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 | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 292 | [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 }, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 293 | [NL80211_ATTR_STA_FLAGS2] = { |
| 294 | .len = sizeof(struct nl80211_sta_flag_update), |
| 295 | }, |
Jouni Malinen | 3f77316c | 2009-05-11 21:57:57 +0300 | [diff] [blame] | 296 | [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG }, |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 297 | [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 }, |
| 298 | [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG }, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 299 | [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG }, |
| 300 | [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 }, |
| 301 | [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 302 | [NL80211_ATTR_PID] = { .type = NLA_U32 }, |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 303 | [NL80211_ATTR_4ADDR] = { .type = NLA_U8 }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 304 | [NL80211_ATTR_PMKID] = { .type = NLA_BINARY, |
| 305 | .len = WLAN_PMKID_LEN }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 306 | [NL80211_ATTR_DURATION] = { .type = NLA_U32 }, |
| 307 | [NL80211_ATTR_COOKIE] = { .type = NLA_U64 }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 308 | [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 309 | [NL80211_ATTR_FRAME] = { .type = NLA_BINARY, |
| 310 | .len = IEEE80211_MAX_DATA_LEN }, |
| 311 | [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 312 | [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 313 | [NL80211_ATTR_CQM] = { .type = NLA_NESTED, }, |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 314 | [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG }, |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 315 | [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 }, |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 316 | [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 }, |
| 317 | [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 }, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 318 | [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 }, |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 319 | [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 }, |
| 320 | [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 }, |
Felix Fietkau | 885a46d | 2010-11-11 15:07:22 +0100 | [diff] [blame] | 321 | [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 }, |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 322 | [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 323 | [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 324 | [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED }, |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 325 | [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 }, |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 326 | [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 }, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 327 | [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED }, |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 328 | [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED }, |
Jouni Malinen | 32e9de8 | 2011-08-10 23:53:31 +0300 | [diff] [blame] | 329 | [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 }, |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 330 | [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY, |
| 331 | .len = IEEE80211_MAX_DATA_LEN }, |
| 332 | [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY, |
| 333 | .len = IEEE80211_MAX_DATA_LEN }, |
Vivek Natarajan | f4b34b5 | 2011-08-29 14:23:03 +0530 | [diff] [blame] | 334 | [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG }, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 335 | [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED }, |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 336 | [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 337 | [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 }, |
| 338 | [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 }, |
| 339 | [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 }, |
| 340 | [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG }, |
| 341 | [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG }, |
Arik Nemtsov | 31fa97c | 2014-06-11 17:18:21 +0300 | [diff] [blame] | 342 | [NL80211_ATTR_TDLS_INITIATOR] = { .type = NLA_FLAG }, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 343 | [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG }, |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 344 | [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY, |
| 345 | .len = IEEE80211_MAX_DATA_LEN }, |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 346 | [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 }, |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 347 | [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG }, |
| 348 | [NL80211_ATTR_HT_CAPABILITY_MASK] = { |
| 349 | .len = NL80211_HT_CAPABILITY_LEN |
| 350 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 351 | [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 }, |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 352 | [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 }, |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 353 | [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 }, |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 354 | [NL80211_ATTR_WDEV] = { .type = NLA_U64 }, |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 355 | [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 }, |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 356 | [NL80211_ATTR_SAE_DATA] = { .type = NLA_BINARY, }, |
Mahesh Palivela | f461be3e | 2012-10-11 08:04:52 +0000 | [diff] [blame] | 357 | [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN }, |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 358 | [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 }, |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 359 | [NL80211_ATTR_P2P_CTWINDOW] = { .type = NLA_U8 }, |
| 360 | [NL80211_ATTR_P2P_OPPPS] = { .type = NLA_U8 }, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 361 | [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 }, |
| 362 | [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED }, |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 363 | [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 }, |
| 364 | [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, }, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 365 | [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, }, |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 366 | [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG }, |
| 367 | [NL80211_ATTR_VHT_CAPABILITY_MASK] = { |
| 368 | .len = NL80211_VHT_CAPABILITY_LEN, |
| 369 | }, |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 370 | [NL80211_ATTR_MDID] = { .type = NLA_U16 }, |
| 371 | [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY, |
| 372 | .len = IEEE80211_MAX_DATA_LEN }, |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 373 | [NL80211_ATTR_PEER_AID] = { .type = NLA_U16 }, |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 374 | [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 }, |
| 375 | [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG }, |
| 376 | [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED }, |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 377 | [NL80211_ATTR_CSA_C_OFF_BEACON] = { .type = NLA_BINARY }, |
| 378 | [NL80211_ATTR_CSA_C_OFF_PRESP] = { .type = NLA_BINARY }, |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 379 | [NL80211_ATTR_STA_SUPPORTED_CHANNELS] = { .type = NLA_BINARY }, |
| 380 | [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES] = { .type = NLA_BINARY }, |
Simon Wunderlich | 5336fa8 | 2013-10-07 18:41:05 +0200 | [diff] [blame] | 381 | [NL80211_ATTR_HANDLE_DFS] = { .type = NLA_FLAG }, |
Marek Kwaczynski | 60f4a7b | 2013-12-03 10:04:59 +0100 | [diff] [blame] | 382 | [NL80211_ATTR_OPMODE_NOTIF] = { .type = NLA_U8 }, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 383 | [NL80211_ATTR_VENDOR_ID] = { .type = NLA_U32 }, |
| 384 | [NL80211_ATTR_VENDOR_SUBCMD] = { .type = NLA_U32 }, |
| 385 | [NL80211_ATTR_VENDOR_DATA] = { .type = NLA_BINARY }, |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 386 | [NL80211_ATTR_QOS_MAP] = { .type = NLA_BINARY, |
| 387 | .len = IEEE80211_QOS_MAP_LEN_MAX }, |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 388 | [NL80211_ATTR_MAC_HINT] = { .len = ETH_ALEN }, |
| 389 | [NL80211_ATTR_WIPHY_FREQ_HINT] = { .type = NLA_U32 }, |
Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 390 | [NL80211_ATTR_TDLS_PEER_CAPABILITY] = { .type = NLA_U32 }, |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 391 | [NL80211_ATTR_IFACE_SOCKET_OWNER] = { .type = NLA_FLAG }, |
Andrei Otcheretianski | 34d22ce | 2014-05-09 14:11:44 +0300 | [diff] [blame] | 392 | [NL80211_ATTR_CSA_C_OFFSETS_TX] = { .type = NLA_BINARY }, |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 393 | [NL80211_ATTR_USE_RRM] = { .type = NLA_FLAG }, |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 394 | [NL80211_ATTR_TSID] = { .type = NLA_U8 }, |
| 395 | [NL80211_ATTR_USER_PRIO] = { .type = NLA_U8 }, |
| 396 | [NL80211_ATTR_ADMITTED_TIME] = { .type = NLA_U16 }, |
Eliad Peller | 18998c3 | 2014-09-10 14:07:34 +0300 | [diff] [blame] | 397 | [NL80211_ATTR_SMPS_MODE] = { .type = NLA_U8 }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 398 | }; |
| 399 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 400 | /* policy for the key attributes */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 401 | static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 402 | [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 403 | [NL80211_KEY_IDX] = { .type = NLA_U8 }, |
| 404 | [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, |
Jouni Malinen | 8196226 | 2011-11-02 23:36:31 +0200 | [diff] [blame] | 405 | [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 406 | [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, |
| 407 | [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 408 | [NL80211_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 409 | [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
| 410 | }; |
| 411 | |
| 412 | /* policy for the key default flags */ |
| 413 | static const struct nla_policy |
| 414 | nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = { |
| 415 | [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG }, |
| 416 | [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 417 | }; |
| 418 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 419 | /* policy for WoWLAN attributes */ |
| 420 | static const struct nla_policy |
| 421 | nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = { |
| 422 | [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG }, |
| 423 | [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG }, |
| 424 | [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG }, |
| 425 | [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED }, |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 426 | [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG }, |
| 427 | [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG }, |
| 428 | [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG }, |
| 429 | [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG }, |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 430 | [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED }, |
| 431 | }; |
| 432 | |
| 433 | static const struct nla_policy |
| 434 | nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = { |
| 435 | [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 }, |
| 436 | [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 }, |
| 437 | [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN }, |
| 438 | [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 }, |
| 439 | [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 }, |
| 440 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 }, |
| 441 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = { |
| 442 | .len = sizeof(struct nl80211_wowlan_tcp_data_seq) |
| 443 | }, |
| 444 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = { |
| 445 | .len = sizeof(struct nl80211_wowlan_tcp_data_token) |
| 446 | }, |
| 447 | [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 }, |
| 448 | [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 }, |
| 449 | [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 450 | }; |
| 451 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 452 | /* policy for coalesce rule attributes */ |
| 453 | static const struct nla_policy |
| 454 | nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = { |
| 455 | [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 }, |
| 456 | [NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 }, |
| 457 | [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED }, |
| 458 | }; |
| 459 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 460 | /* policy for GTK rekey offload attributes */ |
| 461 | static const struct nla_policy |
| 462 | nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = { |
| 463 | [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN }, |
| 464 | [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN }, |
| 465 | [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN }, |
| 466 | }; |
| 467 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 468 | static const struct nla_policy |
| 469 | nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = { |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 470 | [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 471 | .len = IEEE80211_MAX_SSID_LEN }, |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 472 | [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 }, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 473 | }; |
| 474 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 475 | static int nl80211_prepare_wdev_dump(struct sk_buff *skb, |
| 476 | struct netlink_callback *cb, |
| 477 | struct cfg80211_registered_device **rdev, |
| 478 | struct wireless_dev **wdev) |
Holger Schurig | a043897 | 2009-11-11 11:30:02 +0100 | [diff] [blame] | 479 | { |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 480 | int err; |
| 481 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 482 | rtnl_lock(); |
| 483 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 484 | if (!cb->args[0]) { |
| 485 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 486 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 487 | nl80211_policy); |
| 488 | if (err) |
| 489 | goto out_unlock; |
| 490 | |
| 491 | *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk), |
| 492 | nl80211_fam.attrbuf); |
| 493 | if (IS_ERR(*wdev)) { |
| 494 | err = PTR_ERR(*wdev); |
| 495 | goto out_unlock; |
| 496 | } |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 497 | *rdev = wiphy_to_rdev((*wdev)->wiphy); |
Johannes Berg | c319d50 | 2013-07-30 22:34:28 +0200 | [diff] [blame] | 498 | /* 0 is the first index - add 1 to parse only once */ |
| 499 | cb->args[0] = (*rdev)->wiphy_idx + 1; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 500 | cb->args[1] = (*wdev)->identifier; |
| 501 | } else { |
Johannes Berg | c319d50 | 2013-07-30 22:34:28 +0200 | [diff] [blame] | 502 | /* subtract the 1 again here */ |
| 503 | struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1); |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 504 | struct wireless_dev *tmp; |
| 505 | |
| 506 | if (!wiphy) { |
| 507 | err = -ENODEV; |
| 508 | goto out_unlock; |
| 509 | } |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 510 | *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 511 | *wdev = NULL; |
| 512 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 513 | list_for_each_entry(tmp, &(*rdev)->wdev_list, list) { |
| 514 | if (tmp->identifier == cb->args[1]) { |
| 515 | *wdev = tmp; |
| 516 | break; |
| 517 | } |
| 518 | } |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 519 | |
| 520 | if (!*wdev) { |
| 521 | err = -ENODEV; |
| 522 | goto out_unlock; |
| 523 | } |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 524 | } |
| 525 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 526 | return 0; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 527 | out_unlock: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 528 | rtnl_unlock(); |
| 529 | return err; |
| 530 | } |
| 531 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 532 | static void nl80211_finish_wdev_dump(struct cfg80211_registered_device *rdev) |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 533 | { |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 534 | rtnl_unlock(); |
| 535 | } |
| 536 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 537 | /* IE validation */ |
| 538 | static bool is_valid_ie_attr(const struct nlattr *attr) |
| 539 | { |
| 540 | const u8 *pos; |
| 541 | int len; |
| 542 | |
| 543 | if (!attr) |
| 544 | return true; |
| 545 | |
| 546 | pos = nla_data(attr); |
| 547 | len = nla_len(attr); |
| 548 | |
| 549 | while (len) { |
| 550 | u8 elemlen; |
| 551 | |
| 552 | if (len < 2) |
| 553 | return false; |
| 554 | len -= 2; |
| 555 | |
| 556 | elemlen = pos[1]; |
| 557 | if (elemlen > len) |
| 558 | return false; |
| 559 | |
| 560 | len -= elemlen; |
| 561 | pos += 2 + elemlen; |
| 562 | } |
| 563 | |
| 564 | return true; |
| 565 | } |
| 566 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 567 | /* message building helper */ |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 568 | static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 569 | int flags, u8 cmd) |
| 570 | { |
| 571 | /* since there is no private header just add the generic one */ |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 572 | return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 573 | } |
| 574 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 575 | static int nl80211_msg_put_channel(struct sk_buff *msg, |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 576 | struct ieee80211_channel *chan, |
| 577 | bool large) |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 578 | { |
Rostislav Lisovy | ea077c1 | 2014-04-15 14:37:55 +0200 | [diff] [blame] | 579 | /* Some channels must be completely excluded from the |
| 580 | * list to protect old user-space tools from breaking |
| 581 | */ |
| 582 | if (!large && chan->flags & |
| 583 | (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ)) |
| 584 | return 0; |
| 585 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 586 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
| 587 | chan->center_freq)) |
| 588 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 589 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 590 | if ((chan->flags & IEEE80211_CHAN_DISABLED) && |
| 591 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED)) |
| 592 | goto nla_put_failure; |
Luis R. Rodriguez | 8fe02e1 | 2013-10-21 19:22:25 +0200 | [diff] [blame] | 593 | if (chan->flags & IEEE80211_CHAN_NO_IR) { |
| 594 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR)) |
| 595 | goto nla_put_failure; |
| 596 | if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS)) |
| 597 | goto nla_put_failure; |
| 598 | } |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 599 | if (chan->flags & IEEE80211_CHAN_RADAR) { |
| 600 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR)) |
| 601 | goto nla_put_failure; |
| 602 | if (large) { |
| 603 | u32 time; |
| 604 | |
| 605 | time = elapsed_jiffies_msecs(chan->dfs_state_entered); |
| 606 | |
| 607 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE, |
| 608 | chan->dfs_state)) |
| 609 | goto nla_put_failure; |
| 610 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME, |
| 611 | time)) |
| 612 | goto nla_put_failure; |
Janusz Dziedzic | 089027e | 2014-02-21 19:46:12 +0100 | [diff] [blame] | 613 | if (nla_put_u32(msg, |
| 614 | NL80211_FREQUENCY_ATTR_DFS_CAC_TIME, |
| 615 | chan->dfs_cac_ms)) |
| 616 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 617 | } |
| 618 | } |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 619 | |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 620 | if (large) { |
| 621 | if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) && |
| 622 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS)) |
| 623 | goto nla_put_failure; |
| 624 | if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) && |
| 625 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS)) |
| 626 | goto nla_put_failure; |
| 627 | if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) && |
| 628 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ)) |
| 629 | goto nla_put_failure; |
| 630 | if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) && |
| 631 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ)) |
| 632 | goto nla_put_failure; |
David Spinadel | 570dbde | 2014-02-23 09:12:59 +0200 | [diff] [blame] | 633 | if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) && |
| 634 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY)) |
| 635 | goto nla_put_failure; |
| 636 | if ((chan->flags & IEEE80211_CHAN_GO_CONCURRENT) && |
| 637 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_GO_CONCURRENT)) |
| 638 | goto nla_put_failure; |
Rostislav Lisovy | ea077c1 | 2014-04-15 14:37:55 +0200 | [diff] [blame] | 639 | if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) && |
| 640 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ)) |
| 641 | goto nla_put_failure; |
| 642 | if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) && |
| 643 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ)) |
| 644 | goto nla_put_failure; |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 645 | } |
| 646 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 647 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
| 648 | DBM_TO_MBM(chan->max_power))) |
| 649 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 650 | |
| 651 | return 0; |
| 652 | |
| 653 | nla_put_failure: |
| 654 | return -ENOBUFS; |
| 655 | } |
| 656 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 657 | /* netlink command implementations */ |
| 658 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 659 | struct key_parse { |
| 660 | struct key_params p; |
| 661 | int idx; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 662 | int type; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 663 | bool def, defmgmt; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 664 | bool def_uni, def_multi; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 665 | }; |
| 666 | |
| 667 | static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k) |
| 668 | { |
| 669 | struct nlattr *tb[NL80211_KEY_MAX + 1]; |
| 670 | int err = nla_parse_nested(tb, NL80211_KEY_MAX, key, |
| 671 | nl80211_key_policy); |
| 672 | if (err) |
| 673 | return err; |
| 674 | |
| 675 | k->def = !!tb[NL80211_KEY_DEFAULT]; |
| 676 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; |
| 677 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 678 | if (k->def) { |
| 679 | k->def_uni = true; |
| 680 | k->def_multi = true; |
| 681 | } |
| 682 | if (k->defmgmt) |
| 683 | k->def_multi = true; |
| 684 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 685 | if (tb[NL80211_KEY_IDX]) |
| 686 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); |
| 687 | |
| 688 | if (tb[NL80211_KEY_DATA]) { |
| 689 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); |
| 690 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); |
| 691 | } |
| 692 | |
| 693 | if (tb[NL80211_KEY_SEQ]) { |
| 694 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); |
| 695 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); |
| 696 | } |
| 697 | |
| 698 | if (tb[NL80211_KEY_CIPHER]) |
| 699 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); |
| 700 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 701 | if (tb[NL80211_KEY_TYPE]) { |
| 702 | k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); |
| 703 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 704 | return -EINVAL; |
| 705 | } |
| 706 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 707 | if (tb[NL80211_KEY_DEFAULT_TYPES]) { |
| 708 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
Johannes Berg | 2da8f41 | 2012-01-20 13:52:37 +0100 | [diff] [blame] | 709 | err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 710 | tb[NL80211_KEY_DEFAULT_TYPES], |
| 711 | nl80211_key_default_policy); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 712 | if (err) |
| 713 | return err; |
| 714 | |
| 715 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 716 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 717 | } |
| 718 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 719 | return 0; |
| 720 | } |
| 721 | |
| 722 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) |
| 723 | { |
| 724 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { |
| 725 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 726 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 727 | } |
| 728 | |
| 729 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { |
| 730 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 731 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 732 | } |
| 733 | |
| 734 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 735 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 736 | |
| 737 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) |
| 738 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); |
| 739 | |
| 740 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; |
| 741 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; |
| 742 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 743 | if (k->def) { |
| 744 | k->def_uni = true; |
| 745 | k->def_multi = true; |
| 746 | } |
| 747 | if (k->defmgmt) |
| 748 | k->def_multi = true; |
| 749 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 750 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 751 | k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 752 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 753 | return -EINVAL; |
| 754 | } |
| 755 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 756 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { |
| 757 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
| 758 | int err = nla_parse_nested( |
| 759 | kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 760 | info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], |
| 761 | nl80211_key_default_policy); |
| 762 | if (err) |
| 763 | return err; |
| 764 | |
| 765 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 766 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 767 | } |
| 768 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 769 | return 0; |
| 770 | } |
| 771 | |
| 772 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) |
| 773 | { |
| 774 | int err; |
| 775 | |
| 776 | memset(k, 0, sizeof(*k)); |
| 777 | k->idx = -1; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 778 | k->type = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 779 | |
| 780 | if (info->attrs[NL80211_ATTR_KEY]) |
| 781 | err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k); |
| 782 | else |
| 783 | err = nl80211_parse_key_old(info, k); |
| 784 | |
| 785 | if (err) |
| 786 | return err; |
| 787 | |
| 788 | if (k->def && k->defmgmt) |
| 789 | return -EINVAL; |
| 790 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 791 | if (k->defmgmt) { |
| 792 | if (k->def_uni || !k->def_multi) |
| 793 | return -EINVAL; |
| 794 | } |
| 795 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 796 | if (k->idx != -1) { |
| 797 | if (k->defmgmt) { |
| 798 | if (k->idx < 4 || k->idx > 5) |
| 799 | return -EINVAL; |
| 800 | } else if (k->def) { |
| 801 | if (k->idx < 0 || k->idx > 3) |
| 802 | return -EINVAL; |
| 803 | } else { |
| 804 | if (k->idx < 0 || k->idx > 5) |
| 805 | return -EINVAL; |
| 806 | } |
| 807 | } |
| 808 | |
| 809 | return 0; |
| 810 | } |
| 811 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 812 | static struct cfg80211_cached_keys * |
| 813 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 814 | struct nlattr *keys, bool *no_ht) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 815 | { |
| 816 | struct key_parse parse; |
| 817 | struct nlattr *key; |
| 818 | struct cfg80211_cached_keys *result; |
| 819 | int rem, err, def = 0; |
| 820 | |
| 821 | result = kzalloc(sizeof(*result), GFP_KERNEL); |
| 822 | if (!result) |
| 823 | return ERR_PTR(-ENOMEM); |
| 824 | |
| 825 | result->def = -1; |
| 826 | result->defmgmt = -1; |
| 827 | |
| 828 | nla_for_each_nested(key, keys, rem) { |
| 829 | memset(&parse, 0, sizeof(parse)); |
| 830 | parse.idx = -1; |
| 831 | |
| 832 | err = nl80211_parse_key_new(key, &parse); |
| 833 | if (err) |
| 834 | goto error; |
| 835 | err = -EINVAL; |
| 836 | if (!parse.p.key) |
| 837 | goto error; |
| 838 | if (parse.idx < 0 || parse.idx > 4) |
| 839 | goto error; |
| 840 | if (parse.def) { |
| 841 | if (def) |
| 842 | goto error; |
| 843 | def = 1; |
| 844 | result->def = parse.idx; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 845 | if (!parse.def_uni || !parse.def_multi) |
| 846 | goto error; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 847 | } else if (parse.defmgmt) |
| 848 | goto error; |
| 849 | err = cfg80211_validate_key_settings(rdev, &parse.p, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 850 | parse.idx, false, NULL); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 851 | if (err) |
| 852 | goto error; |
| 853 | result->params[parse.idx].cipher = parse.p.cipher; |
| 854 | result->params[parse.idx].key_len = parse.p.key_len; |
| 855 | result->params[parse.idx].key = result->data[parse.idx]; |
| 856 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 857 | |
| 858 | if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 || |
| 859 | parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) { |
| 860 | if (no_ht) |
| 861 | *no_ht = true; |
| 862 | } |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 863 | } |
| 864 | |
| 865 | return result; |
| 866 | error: |
| 867 | kfree(result); |
| 868 | return ERR_PTR(err); |
| 869 | } |
| 870 | |
| 871 | static int nl80211_key_allowed(struct wireless_dev *wdev) |
| 872 | { |
| 873 | ASSERT_WDEV_LOCK(wdev); |
| 874 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 875 | switch (wdev->iftype) { |
| 876 | case NL80211_IFTYPE_AP: |
| 877 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 878 | case NL80211_IFTYPE_P2P_GO: |
Thomas Pedersen | ff973af | 2011-05-03 16:57:12 -0700 | [diff] [blame] | 879 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 880 | break; |
| 881 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 882 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 883 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 884 | if (!wdev->current_bss) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 885 | return -ENOLINK; |
| 886 | break; |
| 887 | default: |
| 888 | return -EINVAL; |
| 889 | } |
| 890 | |
| 891 | return 0; |
| 892 | } |
| 893 | |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 894 | static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy, |
| 895 | struct nlattr *tb) |
| 896 | { |
| 897 | struct ieee80211_channel *chan; |
| 898 | |
| 899 | if (tb == NULL) |
| 900 | return NULL; |
| 901 | chan = ieee80211_get_channel(wiphy, nla_get_u32(tb)); |
| 902 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) |
| 903 | return NULL; |
| 904 | return chan; |
| 905 | } |
| 906 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 907 | static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) |
| 908 | { |
| 909 | struct nlattr *nl_modes = nla_nest_start(msg, attr); |
| 910 | int i; |
| 911 | |
| 912 | if (!nl_modes) |
| 913 | goto nla_put_failure; |
| 914 | |
| 915 | i = 0; |
| 916 | while (ifmodes) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 917 | if ((ifmodes & 1) && nla_put_flag(msg, i)) |
| 918 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 919 | ifmodes >>= 1; |
| 920 | i++; |
| 921 | } |
| 922 | |
| 923 | nla_nest_end(msg, nl_modes); |
| 924 | return 0; |
| 925 | |
| 926 | nla_put_failure: |
| 927 | return -ENOBUFS; |
| 928 | } |
| 929 | |
| 930 | static int nl80211_put_iface_combinations(struct wiphy *wiphy, |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 931 | struct sk_buff *msg, |
| 932 | bool large) |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 933 | { |
| 934 | struct nlattr *nl_combis; |
| 935 | int i, j; |
| 936 | |
| 937 | nl_combis = nla_nest_start(msg, |
| 938 | NL80211_ATTR_INTERFACE_COMBINATIONS); |
| 939 | if (!nl_combis) |
| 940 | goto nla_put_failure; |
| 941 | |
| 942 | for (i = 0; i < wiphy->n_iface_combinations; i++) { |
| 943 | const struct ieee80211_iface_combination *c; |
| 944 | struct nlattr *nl_combi, *nl_limits; |
| 945 | |
| 946 | c = &wiphy->iface_combinations[i]; |
| 947 | |
| 948 | nl_combi = nla_nest_start(msg, i + 1); |
| 949 | if (!nl_combi) |
| 950 | goto nla_put_failure; |
| 951 | |
| 952 | nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS); |
| 953 | if (!nl_limits) |
| 954 | goto nla_put_failure; |
| 955 | |
| 956 | for (j = 0; j < c->n_limits; j++) { |
| 957 | struct nlattr *nl_limit; |
| 958 | |
| 959 | nl_limit = nla_nest_start(msg, j + 1); |
| 960 | if (!nl_limit) |
| 961 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 962 | if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX, |
| 963 | c->limits[j].max)) |
| 964 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 965 | if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, |
| 966 | c->limits[j].types)) |
| 967 | goto nla_put_failure; |
| 968 | nla_nest_end(msg, nl_limit); |
| 969 | } |
| 970 | |
| 971 | nla_nest_end(msg, nl_limits); |
| 972 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 973 | if (c->beacon_int_infra_match && |
| 974 | nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH)) |
| 975 | goto nla_put_failure; |
| 976 | if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, |
| 977 | c->num_different_channels) || |
| 978 | nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM, |
| 979 | c->max_interfaces)) |
| 980 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 981 | if (large && |
Felix Fietkau | 8c48b50 | 2014-05-05 11:48:40 +0200 | [diff] [blame] | 982 | (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS, |
| 983 | c->radar_detect_widths) || |
| 984 | nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS, |
| 985 | c->radar_detect_regions))) |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 986 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 987 | |
| 988 | nla_nest_end(msg, nl_combi); |
| 989 | } |
| 990 | |
| 991 | nla_nest_end(msg, nl_combis); |
| 992 | |
| 993 | return 0; |
| 994 | nla_put_failure: |
| 995 | return -ENOBUFS; |
| 996 | } |
| 997 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 998 | #ifdef CONFIG_PM |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 999 | static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev, |
| 1000 | struct sk_buff *msg) |
| 1001 | { |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 1002 | const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp; |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1003 | struct nlattr *nl_tcp; |
| 1004 | |
| 1005 | if (!tcp) |
| 1006 | return 0; |
| 1007 | |
| 1008 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); |
| 1009 | if (!nl_tcp) |
| 1010 | return -ENOBUFS; |
| 1011 | |
| 1012 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 1013 | tcp->data_payload_max)) |
| 1014 | return -ENOBUFS; |
| 1015 | |
| 1016 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 1017 | tcp->data_payload_max)) |
| 1018 | return -ENOBUFS; |
| 1019 | |
| 1020 | if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ)) |
| 1021 | return -ENOBUFS; |
| 1022 | |
| 1023 | if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, |
| 1024 | sizeof(*tcp->tok), tcp->tok)) |
| 1025 | return -ENOBUFS; |
| 1026 | |
| 1027 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, |
| 1028 | tcp->data_interval_max)) |
| 1029 | return -ENOBUFS; |
| 1030 | |
| 1031 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, |
| 1032 | tcp->wake_payload_max)) |
| 1033 | return -ENOBUFS; |
| 1034 | |
| 1035 | nla_nest_end(msg, nl_tcp); |
| 1036 | return 0; |
| 1037 | } |
| 1038 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1039 | static int nl80211_send_wowlan(struct sk_buff *msg, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1040 | struct cfg80211_registered_device *rdev, |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1041 | bool large) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1042 | { |
| 1043 | struct nlattr *nl_wowlan; |
| 1044 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1045 | if (!rdev->wiphy.wowlan) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1046 | return 0; |
| 1047 | |
| 1048 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); |
| 1049 | if (!nl_wowlan) |
| 1050 | return -ENOBUFS; |
| 1051 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1052 | if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1053 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1054 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1055 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1056 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1057 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1058 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1059 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1060 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1061 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1062 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1063 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1064 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1065 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1066 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1067 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 1068 | return -ENOBUFS; |
| 1069 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1070 | if (rdev->wiphy.wowlan->n_patterns) { |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 1071 | struct nl80211_pattern_support pat = { |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1072 | .max_patterns = rdev->wiphy.wowlan->n_patterns, |
| 1073 | .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len, |
| 1074 | .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len, |
| 1075 | .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1076 | }; |
| 1077 | |
| 1078 | if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 1079 | sizeof(pat), &pat)) |
| 1080 | return -ENOBUFS; |
| 1081 | } |
| 1082 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1083 | if (large && nl80211_send_wowlan_tcp_caps(rdev, msg)) |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1084 | return -ENOBUFS; |
| 1085 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1086 | nla_nest_end(msg, nl_wowlan); |
| 1087 | |
| 1088 | return 0; |
| 1089 | } |
| 1090 | #endif |
| 1091 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1092 | static int nl80211_send_coalesce(struct sk_buff *msg, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1093 | struct cfg80211_registered_device *rdev) |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1094 | { |
| 1095 | struct nl80211_coalesce_rule_support rule; |
| 1096 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1097 | if (!rdev->wiphy.coalesce) |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1098 | return 0; |
| 1099 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1100 | rule.max_rules = rdev->wiphy.coalesce->n_rules; |
| 1101 | rule.max_delay = rdev->wiphy.coalesce->max_delay; |
| 1102 | rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns; |
| 1103 | rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len; |
| 1104 | rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len; |
| 1105 | rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset; |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1106 | |
| 1107 | if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule)) |
| 1108 | return -ENOBUFS; |
| 1109 | |
| 1110 | return 0; |
| 1111 | } |
| 1112 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1113 | static int nl80211_send_band_rateinfo(struct sk_buff *msg, |
| 1114 | struct ieee80211_supported_band *sband) |
| 1115 | { |
| 1116 | struct nlattr *nl_rates, *nl_rate; |
| 1117 | struct ieee80211_rate *rate; |
| 1118 | int i; |
| 1119 | |
| 1120 | /* add HT info */ |
| 1121 | if (sband->ht_cap.ht_supported && |
| 1122 | (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET, |
| 1123 | sizeof(sband->ht_cap.mcs), |
| 1124 | &sband->ht_cap.mcs) || |
| 1125 | nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA, |
| 1126 | sband->ht_cap.cap) || |
| 1127 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, |
| 1128 | sband->ht_cap.ampdu_factor) || |
| 1129 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, |
| 1130 | sband->ht_cap.ampdu_density))) |
| 1131 | return -ENOBUFS; |
| 1132 | |
| 1133 | /* add VHT info */ |
| 1134 | if (sband->vht_cap.vht_supported && |
| 1135 | (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET, |
| 1136 | sizeof(sband->vht_cap.vht_mcs), |
| 1137 | &sband->vht_cap.vht_mcs) || |
| 1138 | nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA, |
| 1139 | sband->vht_cap.cap))) |
| 1140 | return -ENOBUFS; |
| 1141 | |
| 1142 | /* add bitrates */ |
| 1143 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); |
| 1144 | if (!nl_rates) |
| 1145 | return -ENOBUFS; |
| 1146 | |
| 1147 | for (i = 0; i < sband->n_bitrates; i++) { |
| 1148 | nl_rate = nla_nest_start(msg, i); |
| 1149 | if (!nl_rate) |
| 1150 | return -ENOBUFS; |
| 1151 | |
| 1152 | rate = &sband->bitrates[i]; |
| 1153 | if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE, |
| 1154 | rate->bitrate)) |
| 1155 | return -ENOBUFS; |
| 1156 | if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) && |
| 1157 | nla_put_flag(msg, |
| 1158 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE)) |
| 1159 | return -ENOBUFS; |
| 1160 | |
| 1161 | nla_nest_end(msg, nl_rate); |
| 1162 | } |
| 1163 | |
| 1164 | nla_nest_end(msg, nl_rates); |
| 1165 | |
| 1166 | return 0; |
| 1167 | } |
| 1168 | |
| 1169 | static int |
| 1170 | nl80211_send_mgmt_stypes(struct sk_buff *msg, |
| 1171 | const struct ieee80211_txrx_stypes *mgmt_stypes) |
| 1172 | { |
| 1173 | u16 stypes; |
| 1174 | struct nlattr *nl_ftypes, *nl_ifs; |
| 1175 | enum nl80211_iftype ift; |
| 1176 | int i; |
| 1177 | |
| 1178 | if (!mgmt_stypes) |
| 1179 | return 0; |
| 1180 | |
| 1181 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES); |
| 1182 | if (!nl_ifs) |
| 1183 | return -ENOBUFS; |
| 1184 | |
| 1185 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 1186 | nl_ftypes = nla_nest_start(msg, ift); |
| 1187 | if (!nl_ftypes) |
| 1188 | return -ENOBUFS; |
| 1189 | i = 0; |
| 1190 | stypes = mgmt_stypes[ift].tx; |
| 1191 | while (stypes) { |
| 1192 | if ((stypes & 1) && |
| 1193 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1194 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1195 | return -ENOBUFS; |
| 1196 | stypes >>= 1; |
| 1197 | i++; |
| 1198 | } |
| 1199 | nla_nest_end(msg, nl_ftypes); |
| 1200 | } |
| 1201 | |
| 1202 | nla_nest_end(msg, nl_ifs); |
| 1203 | |
| 1204 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES); |
| 1205 | if (!nl_ifs) |
| 1206 | return -ENOBUFS; |
| 1207 | |
| 1208 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 1209 | nl_ftypes = nla_nest_start(msg, ift); |
| 1210 | if (!nl_ftypes) |
| 1211 | return -ENOBUFS; |
| 1212 | i = 0; |
| 1213 | stypes = mgmt_stypes[ift].rx; |
| 1214 | while (stypes) { |
| 1215 | if ((stypes & 1) && |
| 1216 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1217 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1218 | return -ENOBUFS; |
| 1219 | stypes >>= 1; |
| 1220 | i++; |
| 1221 | } |
| 1222 | nla_nest_end(msg, nl_ftypes); |
| 1223 | } |
| 1224 | nla_nest_end(msg, nl_ifs); |
| 1225 | |
| 1226 | return 0; |
| 1227 | } |
| 1228 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1229 | struct nl80211_dump_wiphy_state { |
| 1230 | s64 filter_wiphy; |
| 1231 | long start; |
| 1232 | long split_start, band_start, chan_start; |
| 1233 | bool split; |
| 1234 | }; |
| 1235 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1236 | static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev, |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1237 | enum nl80211_commands cmd, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1238 | struct sk_buff *msg, u32 portid, u32 seq, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1239 | int flags, struct nl80211_dump_wiphy_state *state) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1240 | { |
| 1241 | void *hdr; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1242 | struct nlattr *nl_bands, *nl_band; |
| 1243 | struct nlattr *nl_freqs, *nl_freq; |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1244 | struct nlattr *nl_cmds; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1245 | enum ieee80211_band band; |
| 1246 | struct ieee80211_channel *chan; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1247 | int i; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1248 | const struct ieee80211_txrx_stypes *mgmt_stypes = |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1249 | rdev->wiphy.mgmt_stypes; |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1250 | u32 features; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1251 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1252 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1253 | if (!hdr) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1254 | return -ENOBUFS; |
| 1255 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1256 | if (WARN_ON(!state)) |
| 1257 | return -EINVAL; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1258 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1259 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1260 | nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1261 | wiphy_name(&rdev->wiphy)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1262 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1263 | cfg80211_rdev_list_generation)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1264 | goto nla_put_failure; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1265 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1266 | if (cmd != NL80211_CMD_NEW_WIPHY) |
| 1267 | goto finish; |
| 1268 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1269 | switch (state->split_start) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1270 | case 0: |
| 1271 | if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1272 | rdev->wiphy.retry_short) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1273 | nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1274 | rdev->wiphy.retry_long) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1275 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1276 | rdev->wiphy.frag_threshold) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1277 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1278 | rdev->wiphy.rts_threshold) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1279 | nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1280 | rdev->wiphy.coverage_class) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1281 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1282 | rdev->wiphy.max_scan_ssids) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1283 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1284 | rdev->wiphy.max_sched_scan_ssids) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1285 | nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1286 | rdev->wiphy.max_scan_ie_len) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1287 | nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1288 | rdev->wiphy.max_sched_scan_ie_len) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1289 | nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1290 | rdev->wiphy.max_match_sets)) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1291 | goto nla_put_failure; |
| 1292 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1293 | if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1294 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN)) |
| 1295 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1296 | if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1297 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH)) |
| 1298 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1299 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1300 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD)) |
| 1301 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1302 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1303 | nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT)) |
| 1304 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1305 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1306 | nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT)) |
| 1307 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1308 | if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1309 | nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1310 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1311 | state->split_start++; |
| 1312 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1313 | break; |
| 1314 | case 1: |
| 1315 | if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1316 | sizeof(u32) * rdev->wiphy.n_cipher_suites, |
| 1317 | rdev->wiphy.cipher_suites)) |
Mahesh Palivela | bf0c111e | 2012-06-22 07:27:46 +0000 | [diff] [blame] | 1318 | goto nla_put_failure; |
| 1319 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1320 | if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1321 | rdev->wiphy.max_num_pmkids)) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1322 | goto nla_put_failure; |
| 1323 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1324 | if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1325 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE)) |
| 1326 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1327 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1328 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1329 | rdev->wiphy.available_antennas_tx) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1330 | nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1331 | rdev->wiphy.available_antennas_rx)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1332 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1333 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1334 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1335 | nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1336 | rdev->wiphy.probe_resp_offload)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1337 | goto nla_put_failure; |
Jouni Malinen | e2f367f26 | 2008-11-21 19:01:30 +0200 | [diff] [blame] | 1338 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1339 | if ((rdev->wiphy.available_antennas_tx || |
| 1340 | rdev->wiphy.available_antennas_rx) && |
| 1341 | rdev->ops->get_antenna) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1342 | u32 tx_ant = 0, rx_ant = 0; |
| 1343 | int res; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1344 | res = rdev_get_antenna(rdev, &tx_ant, &rx_ant); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1345 | if (!res) { |
| 1346 | if (nla_put_u32(msg, |
| 1347 | NL80211_ATTR_WIPHY_ANTENNA_TX, |
| 1348 | tx_ant) || |
| 1349 | nla_put_u32(msg, |
| 1350 | NL80211_ATTR_WIPHY_ANTENNA_RX, |
| 1351 | rx_ant)) |
| 1352 | goto nla_put_failure; |
| 1353 | } |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1354 | } |
| 1355 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1356 | state->split_start++; |
| 1357 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1358 | break; |
| 1359 | case 2: |
| 1360 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1361 | rdev->wiphy.interface_modes)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1362 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1363 | state->split_start++; |
| 1364 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1365 | break; |
| 1366 | case 3: |
| 1367 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); |
| 1368 | if (!nl_bands) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1369 | goto nla_put_failure; |
| 1370 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1371 | for (band = state->band_start; |
| 1372 | band < IEEE80211_NUM_BANDS; band++) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1373 | struct ieee80211_supported_band *sband; |
| 1374 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1375 | sband = rdev->wiphy.bands[band]; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1376 | |
| 1377 | if (!sband) |
| 1378 | continue; |
| 1379 | |
| 1380 | nl_band = nla_nest_start(msg, band); |
| 1381 | if (!nl_band) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1382 | goto nla_put_failure; |
| 1383 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1384 | switch (state->chan_start) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1385 | case 0: |
| 1386 | if (nl80211_send_band_rateinfo(msg, sband)) |
| 1387 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1388 | state->chan_start++; |
| 1389 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1390 | break; |
| 1391 | default: |
| 1392 | /* add frequencies */ |
| 1393 | nl_freqs = nla_nest_start( |
| 1394 | msg, NL80211_BAND_ATTR_FREQS); |
| 1395 | if (!nl_freqs) |
| 1396 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1397 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1398 | for (i = state->chan_start - 1; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1399 | i < sband->n_channels; |
| 1400 | i++) { |
| 1401 | nl_freq = nla_nest_start(msg, i); |
| 1402 | if (!nl_freq) |
| 1403 | goto nla_put_failure; |
| 1404 | |
| 1405 | chan = &sband->channels[i]; |
| 1406 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1407 | if (nl80211_msg_put_channel( |
| 1408 | msg, chan, |
| 1409 | state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1410 | goto nla_put_failure; |
| 1411 | |
| 1412 | nla_nest_end(msg, nl_freq); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1413 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1414 | break; |
| 1415 | } |
| 1416 | if (i < sband->n_channels) |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1417 | state->chan_start = i + 2; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1418 | else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1419 | state->chan_start = 0; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1420 | nla_nest_end(msg, nl_freqs); |
| 1421 | } |
| 1422 | |
| 1423 | nla_nest_end(msg, nl_band); |
| 1424 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1425 | if (state->split) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1426 | /* start again here */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1427 | if (state->chan_start) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1428 | band--; |
| 1429 | break; |
| 1430 | } |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1431 | } |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1432 | nla_nest_end(msg, nl_bands); |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1433 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1434 | if (band < IEEE80211_NUM_BANDS) |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1435 | state->band_start = band + 1; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1436 | else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1437 | state->band_start = 0; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1438 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1439 | /* if bands & channels are done, continue outside */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1440 | if (state->band_start == 0 && state->chan_start == 0) |
| 1441 | state->split_start++; |
| 1442 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1443 | break; |
| 1444 | case 4: |
| 1445 | nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); |
| 1446 | if (!nl_cmds) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1447 | goto nla_put_failure; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1448 | |
| 1449 | i = 0; |
| 1450 | #define CMD(op, n) \ |
| 1451 | do { \ |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1452 | if (rdev->ops->op) { \ |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1453 | i++; \ |
| 1454 | if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \ |
| 1455 | goto nla_put_failure; \ |
| 1456 | } \ |
| 1457 | } while (0) |
| 1458 | |
| 1459 | CMD(add_virtual_intf, NEW_INTERFACE); |
| 1460 | CMD(change_virtual_intf, SET_INTERFACE); |
| 1461 | CMD(add_key, NEW_KEY); |
| 1462 | CMD(start_ap, START_AP); |
| 1463 | CMD(add_station, NEW_STATION); |
| 1464 | CMD(add_mpath, NEW_MPATH); |
| 1465 | CMD(update_mesh_config, SET_MESH_CONFIG); |
| 1466 | CMD(change_bss, SET_BSS); |
| 1467 | CMD(auth, AUTHENTICATE); |
| 1468 | CMD(assoc, ASSOCIATE); |
| 1469 | CMD(deauth, DEAUTHENTICATE); |
| 1470 | CMD(disassoc, DISASSOCIATE); |
| 1471 | CMD(join_ibss, JOIN_IBSS); |
| 1472 | CMD(join_mesh, JOIN_MESH); |
| 1473 | CMD(set_pmksa, SET_PMKSA); |
| 1474 | CMD(del_pmksa, DEL_PMKSA); |
| 1475 | CMD(flush_pmksa, FLUSH_PMKSA); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1476 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1477 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); |
| 1478 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); |
| 1479 | CMD(mgmt_tx, FRAME); |
| 1480 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1481 | if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1482 | i++; |
| 1483 | if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS)) |
| 1484 | goto nla_put_failure; |
| 1485 | } |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1486 | if (rdev->ops->set_monitor_channel || rdev->ops->start_ap || |
| 1487 | rdev->ops->join_mesh) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1488 | i++; |
| 1489 | if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL)) |
| 1490 | goto nla_put_failure; |
| 1491 | } |
| 1492 | CMD(set_wds_peer, SET_WDS_PEER); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1493 | if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1494 | CMD(tdls_mgmt, TDLS_MGMT); |
| 1495 | CMD(tdls_oper, TDLS_OPER); |
| 1496 | } |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1497 | if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1498 | CMD(sched_scan_start, START_SCHED_SCAN); |
| 1499 | CMD(probe_client, PROBE_CLIENT); |
| 1500 | CMD(set_noack_map, SET_NOACK_MAP); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1501 | if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1502 | i++; |
| 1503 | if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS)) |
| 1504 | goto nla_put_failure; |
| 1505 | } |
| 1506 | CMD(start_p2p_device, START_P2P_DEVICE); |
| 1507 | CMD(set_mcast_rate, SET_MCAST_RATE); |
Johannes Berg | 02df00e | 2014-06-10 14:06:25 +0200 | [diff] [blame] | 1508 | #ifdef CONFIG_NL80211_TESTMODE |
| 1509 | CMD(testmode_cmd, TESTMODE); |
| 1510 | #endif |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1511 | if (state->split) { |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 1512 | CMD(crit_proto_start, CRIT_PROTOCOL_START); |
| 1513 | CMD(crit_proto_stop, CRIT_PROTOCOL_STOP); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1514 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 1515 | CMD(channel_switch, CHANNEL_SWITCH); |
Johannes Berg | 02df00e | 2014-06-10 14:06:25 +0200 | [diff] [blame] | 1516 | CMD(set_qos_map, SET_QOS_MAP); |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 1517 | if (rdev->wiphy.flags & |
| 1518 | WIPHY_FLAG_SUPPORTS_WMM_ADMISSION) |
| 1519 | CMD(add_tx_ts, ADD_TX_TS); |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 1520 | } |
Johannes Berg | 02df00e | 2014-06-10 14:06:25 +0200 | [diff] [blame] | 1521 | /* add into the if now */ |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1522 | #undef CMD |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1523 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1524 | if (rdev->ops->connect || rdev->ops->auth) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1525 | i++; |
| 1526 | if (nla_put_u32(msg, i, NL80211_CMD_CONNECT)) |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1527 | goto nla_put_failure; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1528 | } |
| 1529 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1530 | if (rdev->ops->disconnect || rdev->ops->deauth) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1531 | i++; |
| 1532 | if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT)) |
| 1533 | goto nla_put_failure; |
| 1534 | } |
Johannes Berg | 74b70a4 | 2010-08-24 12:15:53 +0200 | [diff] [blame] | 1535 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1536 | nla_nest_end(msg, nl_cmds); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1537 | state->split_start++; |
| 1538 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1539 | break; |
| 1540 | case 5: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1541 | if (rdev->ops->remain_on_channel && |
| 1542 | (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1543 | nla_put_u32(msg, |
| 1544 | NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1545 | rdev->wiphy.max_remain_on_channel_duration)) |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1546 | goto nla_put_failure; |
| 1547 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1548 | if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1549 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) |
| 1550 | goto nla_put_failure; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1551 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1552 | if (nl80211_send_mgmt_stypes(msg, mgmt_stypes)) |
| 1553 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1554 | state->split_start++; |
| 1555 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1556 | break; |
| 1557 | case 6: |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 1558 | #ifdef CONFIG_PM |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1559 | if (nl80211_send_wowlan(msg, rdev, state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1560 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1561 | state->split_start++; |
| 1562 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1563 | break; |
| 1564 | #else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1565 | state->split_start++; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1566 | #endif |
| 1567 | case 7: |
| 1568 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1569 | rdev->wiphy.software_iftypes)) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1570 | goto nla_put_failure; |
| 1571 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1572 | if (nl80211_put_iface_combinations(&rdev->wiphy, msg, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1573 | state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1574 | goto nla_put_failure; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1575 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1576 | state->split_start++; |
| 1577 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1578 | break; |
| 1579 | case 8: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1580 | if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1581 | nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1582 | rdev->wiphy.ap_sme_capa)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1583 | goto nla_put_failure; |
| 1584 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1585 | features = rdev->wiphy.features; |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1586 | /* |
| 1587 | * We can only add the per-channel limit information if the |
| 1588 | * dump is split, otherwise it makes it too big. Therefore |
| 1589 | * only advertise it in that case. |
| 1590 | */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1591 | if (state->split) |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1592 | features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS; |
| 1593 | if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1594 | goto nla_put_failure; |
| 1595 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1596 | if (rdev->wiphy.ht_capa_mod_mask && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1597 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1598 | sizeof(*rdev->wiphy.ht_capa_mod_mask), |
| 1599 | rdev->wiphy.ht_capa_mod_mask)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1600 | goto nla_put_failure; |
| 1601 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1602 | if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME && |
| 1603 | rdev->wiphy.max_acl_mac_addrs && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1604 | nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1605 | rdev->wiphy.max_acl_mac_addrs)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1606 | goto nla_put_failure; |
| 1607 | |
| 1608 | /* |
| 1609 | * Any information below this point is only available to |
| 1610 | * applications that can deal with it being split. This |
| 1611 | * helps ensure that newly added capabilities don't break |
| 1612 | * older tools by overrunning their buffers. |
| 1613 | * |
| 1614 | * We still increment split_start so that in the split |
| 1615 | * case we'll continue with more data in the next round, |
| 1616 | * but break unconditionally so unsplit data stops here. |
| 1617 | */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1618 | state->split_start++; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1619 | break; |
| 1620 | case 9: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1621 | if (rdev->wiphy.extended_capabilities && |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1622 | (nla_put(msg, NL80211_ATTR_EXT_CAPA, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1623 | rdev->wiphy.extended_capabilities_len, |
| 1624 | rdev->wiphy.extended_capabilities) || |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1625 | nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1626 | rdev->wiphy.extended_capabilities_len, |
| 1627 | rdev->wiphy.extended_capabilities_mask))) |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1628 | goto nla_put_failure; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1629 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1630 | if (rdev->wiphy.vht_capa_mod_mask && |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 1631 | nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1632 | sizeof(*rdev->wiphy.vht_capa_mod_mask), |
| 1633 | rdev->wiphy.vht_capa_mod_mask)) |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 1634 | goto nla_put_failure; |
| 1635 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1636 | state->split_start++; |
| 1637 | break; |
| 1638 | case 10: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1639 | if (nl80211_send_coalesce(msg, rdev)) |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1640 | goto nla_put_failure; |
| 1641 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1642 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) && |
Felix Fietkau | 01e0daa | 2013-11-09 14:57:54 +0100 | [diff] [blame] | 1643 | (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) || |
| 1644 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ))) |
| 1645 | goto nla_put_failure; |
Jouni Malinen | b43504c | 2014-01-15 00:01:08 +0200 | [diff] [blame] | 1646 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1647 | if (rdev->wiphy.max_ap_assoc_sta && |
Jouni Malinen | b43504c | 2014-01-15 00:01:08 +0200 | [diff] [blame] | 1648 | nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1649 | rdev->wiphy.max_ap_assoc_sta)) |
Jouni Malinen | b43504c | 2014-01-15 00:01:08 +0200 | [diff] [blame] | 1650 | goto nla_put_failure; |
| 1651 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 1652 | state->split_start++; |
| 1653 | break; |
| 1654 | case 11: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1655 | if (rdev->wiphy.n_vendor_commands) { |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1656 | const struct nl80211_vendor_cmd_info *info; |
| 1657 | struct nlattr *nested; |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 1658 | |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1659 | nested = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); |
| 1660 | if (!nested) |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 1661 | goto nla_put_failure; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1662 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1663 | for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { |
| 1664 | info = &rdev->wiphy.vendor_commands[i].info; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1665 | if (nla_put(msg, i + 1, sizeof(*info), info)) |
| 1666 | goto nla_put_failure; |
| 1667 | } |
| 1668 | nla_nest_end(msg, nested); |
| 1669 | } |
| 1670 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1671 | if (rdev->wiphy.n_vendor_events) { |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1672 | const struct nl80211_vendor_cmd_info *info; |
| 1673 | struct nlattr *nested; |
| 1674 | |
| 1675 | nested = nla_nest_start(msg, |
| 1676 | NL80211_ATTR_VENDOR_EVENTS); |
| 1677 | if (!nested) |
| 1678 | goto nla_put_failure; |
| 1679 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1680 | for (i = 0; i < rdev->wiphy.n_vendor_events; i++) { |
| 1681 | info = &rdev->wiphy.vendor_events[i]; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1682 | if (nla_put(msg, i + 1, sizeof(*info), info)) |
| 1683 | goto nla_put_failure; |
| 1684 | } |
| 1685 | nla_nest_end(msg, nested); |
| 1686 | } |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 1687 | state->split_start++; |
| 1688 | break; |
| 1689 | case 12: |
| 1690 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH && |
| 1691 | nla_put_u8(msg, NL80211_ATTR_MAX_CSA_COUNTERS, |
| 1692 | rdev->wiphy.max_num_csa_counters)) |
| 1693 | goto nla_put_failure; |
Felix Fietkau | 01e0daa | 2013-11-09 14:57:54 +0100 | [diff] [blame] | 1694 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1695 | /* done */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1696 | state->split_start = 0; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1697 | break; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1698 | } |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1699 | finish: |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1700 | return genlmsg_end(msg, hdr); |
| 1701 | |
| 1702 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 1703 | genlmsg_cancel(msg, hdr); |
| 1704 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1705 | } |
| 1706 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1707 | static int nl80211_dump_wiphy_parse(struct sk_buff *skb, |
| 1708 | struct netlink_callback *cb, |
| 1709 | struct nl80211_dump_wiphy_state *state) |
| 1710 | { |
| 1711 | struct nlattr **tb = nl80211_fam.attrbuf; |
| 1712 | int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 1713 | tb, nl80211_fam.maxattr, nl80211_policy); |
| 1714 | /* ignore parse errors for backward compatibility */ |
| 1715 | if (ret) |
| 1716 | return 0; |
| 1717 | |
| 1718 | state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP]; |
| 1719 | if (tb[NL80211_ATTR_WIPHY]) |
| 1720 | state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]); |
| 1721 | if (tb[NL80211_ATTR_WDEV]) |
| 1722 | state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32; |
| 1723 | if (tb[NL80211_ATTR_IFINDEX]) { |
| 1724 | struct net_device *netdev; |
| 1725 | struct cfg80211_registered_device *rdev; |
| 1726 | int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); |
| 1727 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 1728 | netdev = __dev_get_by_index(sock_net(skb->sk), ifidx); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1729 | if (!netdev) |
| 1730 | return -ENODEV; |
| 1731 | if (netdev->ieee80211_ptr) { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 1732 | rdev = wiphy_to_rdev( |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1733 | netdev->ieee80211_ptr->wiphy); |
| 1734 | state->filter_wiphy = rdev->wiphy_idx; |
| 1735 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1736 | } |
| 1737 | |
| 1738 | return 0; |
| 1739 | } |
| 1740 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1741 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) |
| 1742 | { |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1743 | int idx = 0, ret; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1744 | struct nl80211_dump_wiphy_state *state = (void *)cb->args[0]; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1745 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 3a5a423 | 2013-06-19 10:09:57 +0200 | [diff] [blame] | 1746 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1747 | rtnl_lock(); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1748 | if (!state) { |
| 1749 | state = kzalloc(sizeof(*state), GFP_KERNEL); |
John W. Linville | 57ed5cd | 2013-06-28 13:18:21 -0400 | [diff] [blame] | 1750 | if (!state) { |
| 1751 | rtnl_unlock(); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1752 | return -ENOMEM; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1753 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1754 | state->filter_wiphy = -1; |
| 1755 | ret = nl80211_dump_wiphy_parse(skb, cb, state); |
| 1756 | if (ret) { |
| 1757 | kfree(state); |
| 1758 | rtnl_unlock(); |
| 1759 | return ret; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1760 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1761 | cb->args[0] = (long)state; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1762 | } |
| 1763 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1764 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 1765 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1766 | continue; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1767 | if (++idx <= state->start) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1768 | continue; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1769 | if (state->filter_wiphy != -1 && |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1770 | state->filter_wiphy != rdev->wiphy_idx) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1771 | continue; |
| 1772 | /* attempt to fit multiple wiphy data chunks into the skb */ |
| 1773 | do { |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1774 | ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, |
| 1775 | skb, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1776 | NETLINK_CB(cb->skb).portid, |
| 1777 | cb->nlh->nlmsg_seq, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1778 | NLM_F_MULTI, state); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1779 | if (ret < 0) { |
| 1780 | /* |
| 1781 | * If sending the wiphy data didn't fit (ENOBUFS |
| 1782 | * or EMSGSIZE returned), this SKB is still |
| 1783 | * empty (so it's not too big because another |
| 1784 | * wiphy dataset is already in the skb) and |
| 1785 | * we've not tried to adjust the dump allocation |
| 1786 | * yet ... then adjust the alloc size to be |
| 1787 | * bigger, and return 1 but with the empty skb. |
| 1788 | * This results in an empty message being RX'ed |
| 1789 | * in userspace, but that is ignored. |
| 1790 | * |
| 1791 | * We can then retry with the larger buffer. |
| 1792 | */ |
| 1793 | if ((ret == -ENOBUFS || ret == -EMSGSIZE) && |
Pontus Fuchs | f12cb28 | 2014-01-16 15:00:40 +0100 | [diff] [blame] | 1794 | !skb->len && !state->split && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1795 | cb->min_dump_alloc < 4096) { |
| 1796 | cb->min_dump_alloc = 4096; |
Pontus Fuchs | f12cb28 | 2014-01-16 15:00:40 +0100 | [diff] [blame] | 1797 | state->split_start = 0; |
David S. Miller | d98cae64e | 2013-06-19 16:49:39 -0700 | [diff] [blame] | 1798 | rtnl_unlock(); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1799 | return 1; |
| 1800 | } |
| 1801 | idx--; |
| 1802 | break; |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1803 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1804 | } while (state->split_start > 0); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1805 | break; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1806 | } |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1807 | rtnl_unlock(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1808 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1809 | state->start = idx; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1810 | |
| 1811 | return skb->len; |
| 1812 | } |
| 1813 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1814 | static int nl80211_dump_wiphy_done(struct netlink_callback *cb) |
| 1815 | { |
| 1816 | kfree((void *)cb->args[0]); |
| 1817 | return 0; |
| 1818 | } |
| 1819 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1820 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1821 | { |
| 1822 | struct sk_buff *msg; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1823 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1824 | struct nl80211_dump_wiphy_state state = {}; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1825 | |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1826 | msg = nlmsg_new(4096, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1827 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1828 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1829 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1830 | if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg, |
| 1831 | info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1832 | &state) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1833 | nlmsg_free(msg); |
| 1834 | return -ENOBUFS; |
| 1835 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1836 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 1837 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1838 | } |
| 1839 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1840 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
| 1841 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, |
| 1842 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, |
| 1843 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, |
| 1844 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, |
| 1845 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, |
| 1846 | }; |
| 1847 | |
| 1848 | static int parse_txq_params(struct nlattr *tb[], |
| 1849 | struct ieee80211_txq_params *txq_params) |
| 1850 | { |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1851 | if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] || |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1852 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
| 1853 | !tb[NL80211_TXQ_ATTR_AIFS]) |
| 1854 | return -EINVAL; |
| 1855 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1856 | txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1857 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
| 1858 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); |
| 1859 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); |
| 1860 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); |
| 1861 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1862 | if (txq_params->ac >= NL80211_NUM_ACS) |
| 1863 | return -EINVAL; |
| 1864 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1865 | return 0; |
| 1866 | } |
| 1867 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1868 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
| 1869 | { |
| 1870 | /* |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1871 | * You can only set the channel explicitly for WDS interfaces, |
| 1872 | * all others have their channel managed via their respective |
| 1873 | * "establish a connection" command (connect, join, ...) |
| 1874 | * |
| 1875 | * For AP/GO and mesh mode, the channel can be set with the |
| 1876 | * channel userspace API, but is only stored and passed to the |
| 1877 | * low-level driver when the AP starts or the mesh is joined. |
| 1878 | * This is for backward compatibility, userspace can also give |
| 1879 | * the channel in the start-ap or join-mesh commands instead. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1880 | * |
| 1881 | * Monitors are special as they are normally slaved to |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1882 | * whatever else is going on, so they have their own special |
| 1883 | * operation to set the monitor channel if possible. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1884 | */ |
| 1885 | return !wdev || |
| 1886 | wdev->iftype == NL80211_IFTYPE_AP || |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1887 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 1888 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
| 1889 | wdev->iftype == NL80211_IFTYPE_P2P_GO; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1890 | } |
| 1891 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1892 | static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev, |
| 1893 | struct genl_info *info, |
| 1894 | struct cfg80211_chan_def *chandef) |
| 1895 | { |
Mahesh Palivela | dbeca2e | 2012-11-29 14:11:07 +0530 | [diff] [blame] | 1896 | u32 control_freq; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1897 | |
| 1898 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 1899 | return -EINVAL; |
| 1900 | |
| 1901 | control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 1902 | |
| 1903 | chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1904 | chandef->width = NL80211_CHAN_WIDTH_20_NOHT; |
| 1905 | chandef->center_freq1 = control_freq; |
| 1906 | chandef->center_freq2 = 0; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1907 | |
| 1908 | /* Primary channel not allowed */ |
| 1909 | if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) |
| 1910 | return -EINVAL; |
| 1911 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1912 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 1913 | enum nl80211_channel_type chantype; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1914 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1915 | chantype = nla_get_u32( |
| 1916 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 1917 | |
| 1918 | switch (chantype) { |
| 1919 | case NL80211_CHAN_NO_HT: |
| 1920 | case NL80211_CHAN_HT20: |
| 1921 | case NL80211_CHAN_HT40PLUS: |
| 1922 | case NL80211_CHAN_HT40MINUS: |
| 1923 | cfg80211_chandef_create(chandef, chandef->chan, |
| 1924 | chantype); |
| 1925 | break; |
| 1926 | default: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1927 | return -EINVAL; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1928 | } |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1929 | } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) { |
| 1930 | chandef->width = |
| 1931 | nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]); |
| 1932 | if (info->attrs[NL80211_ATTR_CENTER_FREQ1]) |
| 1933 | chandef->center_freq1 = |
| 1934 | nla_get_u32( |
| 1935 | info->attrs[NL80211_ATTR_CENTER_FREQ1]); |
| 1936 | if (info->attrs[NL80211_ATTR_CENTER_FREQ2]) |
| 1937 | chandef->center_freq2 = |
| 1938 | nla_get_u32( |
| 1939 | info->attrs[NL80211_ATTR_CENTER_FREQ2]); |
| 1940 | } |
| 1941 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 1942 | if (!cfg80211_chandef_valid(chandef)) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1943 | return -EINVAL; |
| 1944 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 1945 | if (!cfg80211_chandef_usable(&rdev->wiphy, chandef, |
| 1946 | IEEE80211_CHAN_DISABLED)) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1947 | return -EINVAL; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1948 | |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 1949 | if ((chandef->width == NL80211_CHAN_WIDTH_5 || |
| 1950 | chandef->width == NL80211_CHAN_WIDTH_10) && |
| 1951 | !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ)) |
| 1952 | return -EINVAL; |
| 1953 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1954 | return 0; |
| 1955 | } |
| 1956 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1957 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 1958 | struct net_device *dev, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1959 | struct genl_info *info) |
| 1960 | { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1961 | struct cfg80211_chan_def chandef; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1962 | int result; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1963 | enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR; |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 1964 | struct wireless_dev *wdev = NULL; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1965 | |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 1966 | if (dev) |
| 1967 | wdev = dev->ieee80211_ptr; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1968 | if (!nl80211_can_set_dev_channel(wdev)) |
| 1969 | return -EOPNOTSUPP; |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 1970 | if (wdev) |
| 1971 | iftype = wdev->iftype; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1972 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1973 | result = nl80211_parse_chandef(rdev, info, &chandef); |
| 1974 | if (result) |
| 1975 | return result; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1976 | |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1977 | switch (iftype) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1978 | case NL80211_IFTYPE_AP: |
| 1979 | case NL80211_IFTYPE_P2P_GO: |
Ilan Peer | 174e0cd | 2014-02-23 09:13:01 +0200 | [diff] [blame] | 1980 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef, iftype)) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1981 | result = -EINVAL; |
| 1982 | break; |
| 1983 | } |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 1984 | if (wdev->beacon_interval) { |
| 1985 | if (!dev || !rdev->ops->set_ap_chanwidth || |
| 1986 | !(rdev->wiphy.features & |
| 1987 | NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) { |
| 1988 | result = -EBUSY; |
| 1989 | break; |
| 1990 | } |
| 1991 | |
| 1992 | /* Only allow dynamic channel width changes */ |
| 1993 | if (chandef.chan != wdev->preset_chandef.chan) { |
| 1994 | result = -EBUSY; |
| 1995 | break; |
| 1996 | } |
| 1997 | result = rdev_set_ap_chanwidth(rdev, dev, &chandef); |
| 1998 | if (result) |
| 1999 | break; |
| 2000 | } |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2001 | wdev->preset_chandef = chandef; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2002 | result = 0; |
| 2003 | break; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 2004 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2005 | result = cfg80211_set_mesh_channel(rdev, wdev, &chandef); |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 2006 | break; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2007 | case NL80211_IFTYPE_MONITOR: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2008 | result = cfg80211_set_monitor_channel(rdev, &chandef); |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2009 | break; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2010 | default: |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2011 | result = -EINVAL; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2012 | } |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2013 | |
| 2014 | return result; |
| 2015 | } |
| 2016 | |
| 2017 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) |
| 2018 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2019 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2020 | struct net_device *netdev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2021 | |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2022 | return __nl80211_set_channel(rdev, netdev, info); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2023 | } |
| 2024 | |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2025 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
| 2026 | { |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 2027 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2028 | struct net_device *dev = info->user_ptr[1]; |
| 2029 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 388ac77 | 2010-10-07 13:11:09 +0200 | [diff] [blame] | 2030 | const u8 *bssid; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2031 | |
| 2032 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2033 | return -EINVAL; |
| 2034 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 2035 | if (netif_running(dev)) |
| 2036 | return -EBUSY; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2037 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 2038 | if (!rdev->ops->set_wds_peer) |
| 2039 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2040 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 2041 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
| 2042 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2043 | |
| 2044 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2045 | return rdev_set_wds_peer(rdev, dev, bssid); |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2046 | } |
| 2047 | |
| 2048 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2049 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 2050 | { |
| 2051 | struct cfg80211_registered_device *rdev; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2052 | struct net_device *netdev = NULL; |
| 2053 | struct wireless_dev *wdev; |
Bill Jordan | a1e567c | 2010-09-10 11:22:32 -0400 | [diff] [blame] | 2054 | int result = 0, rem_txq_params = 0; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2055 | struct nlattr *nl_txq_params; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2056 | u32 changed; |
| 2057 | u8 retry_short = 0, retry_long = 0; |
| 2058 | u32 frag_threshold = 0, rts_threshold = 0; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2059 | u8 coverage_class = 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2060 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2061 | ASSERT_RTNL(); |
| 2062 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2063 | /* |
| 2064 | * Try to find the wiphy and netdev. Normally this |
| 2065 | * function shouldn't need the netdev, but this is |
| 2066 | * done for backward compatibility -- previously |
| 2067 | * setting the channel was done per wiphy, but now |
| 2068 | * it is per netdev. Previous userland like hostapd |
| 2069 | * also passed a netdev to set_wiphy, so that it is |
| 2070 | * possible to let that go to the right netdev! |
| 2071 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2072 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2073 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
| 2074 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); |
| 2075 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2076 | netdev = __dev_get_by_index(genl_info_net(info), ifindex); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2077 | if (netdev && netdev->ieee80211_ptr) |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 2078 | rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2079 | else |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2080 | netdev = NULL; |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2081 | } |
| 2082 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2083 | if (!netdev) { |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 2084 | rdev = __cfg80211_rdev_from_attrs(genl_info_net(info), |
| 2085 | info->attrs); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2086 | if (IS_ERR(rdev)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2087 | return PTR_ERR(rdev); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2088 | wdev = NULL; |
| 2089 | netdev = NULL; |
| 2090 | result = 0; |
Johannes Berg | 71fe96b | 2012-10-24 10:04:58 +0200 | [diff] [blame] | 2091 | } else |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2092 | wdev = netdev->ieee80211_ptr; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2093 | |
| 2094 | /* |
| 2095 | * end workaround code, by now the rdev is available |
| 2096 | * and locked, and wdev may or may not be NULL. |
| 2097 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2098 | |
| 2099 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2100 | result = cfg80211_dev_rename( |
| 2101 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2102 | |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2103 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2104 | return result; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2105 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2106 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { |
| 2107 | struct ieee80211_txq_params txq_params; |
| 2108 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; |
| 2109 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2110 | if (!rdev->ops->set_txq_params) |
| 2111 | return -EOPNOTSUPP; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2112 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2113 | if (!netdev) |
| 2114 | return -EINVAL; |
Eliad Peller | f70f01c | 2011-09-25 20:06:53 +0300 | [diff] [blame] | 2115 | |
Johannes Berg | 133a3ff | 2011-11-03 14:50:13 +0100 | [diff] [blame] | 2116 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2117 | netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2118 | return -EINVAL; |
Johannes Berg | 133a3ff | 2011-11-03 14:50:13 +0100 | [diff] [blame] | 2119 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2120 | if (!netif_running(netdev)) |
| 2121 | return -ENETDOWN; |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 2122 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2123 | nla_for_each_nested(nl_txq_params, |
| 2124 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], |
| 2125 | rem_txq_params) { |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 2126 | result = nla_parse(tb, NL80211_TXQ_ATTR_MAX, |
| 2127 | nla_data(nl_txq_params), |
| 2128 | nla_len(nl_txq_params), |
| 2129 | txq_params_policy); |
| 2130 | if (result) |
| 2131 | return result; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2132 | result = parse_txq_params(tb, &txq_params); |
| 2133 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2134 | return result; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2135 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2136 | result = rdev_set_txq_params(rdev, netdev, |
| 2137 | &txq_params); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2138 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2139 | return result; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2140 | } |
| 2141 | } |
| 2142 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2143 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2144 | result = __nl80211_set_channel( |
| 2145 | rdev, |
| 2146 | nl80211_can_set_dev_channel(wdev) ? netdev : NULL, |
| 2147 | info); |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2148 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2149 | return result; |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2150 | } |
| 2151 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2152 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2153 | struct wireless_dev *txp_wdev = wdev; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2154 | enum nl80211_tx_power_setting type; |
| 2155 | int idx, mbm = 0; |
| 2156 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2157 | if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER)) |
| 2158 | txp_wdev = NULL; |
| 2159 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2160 | if (!rdev->ops->set_tx_power) |
| 2161 | return -EOPNOTSUPP; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2162 | |
| 2163 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; |
| 2164 | type = nla_get_u32(info->attrs[idx]); |
| 2165 | |
| 2166 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2167 | (type != NL80211_TX_POWER_AUTOMATIC)) |
| 2168 | return -EINVAL; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2169 | |
| 2170 | if (type != NL80211_TX_POWER_AUTOMATIC) { |
| 2171 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; |
| 2172 | mbm = nla_get_u32(info->attrs[idx]); |
| 2173 | } |
| 2174 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2175 | result = rdev_set_tx_power(rdev, txp_wdev, type, mbm); |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2176 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2177 | return result; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2178 | } |
| 2179 | |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2180 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
| 2181 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { |
| 2182 | u32 tx_ant, rx_ant; |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2183 | if ((!rdev->wiphy.available_antennas_tx && |
| 2184 | !rdev->wiphy.available_antennas_rx) || |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2185 | !rdev->ops->set_antenna) |
| 2186 | return -EOPNOTSUPP; |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2187 | |
| 2188 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); |
| 2189 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); |
| 2190 | |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2191 | /* reject antenna configurations which don't match the |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2192 | * available antenna masks, except for the "all" mask */ |
| 2193 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2194 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) |
| 2195 | return -EINVAL; |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2196 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2197 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
| 2198 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2199 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2200 | result = rdev_set_antenna(rdev, tx_ant, rx_ant); |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2201 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2202 | return result; |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2203 | } |
| 2204 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2205 | changed = 0; |
| 2206 | |
| 2207 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { |
| 2208 | retry_short = nla_get_u8( |
| 2209 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2210 | if (retry_short == 0) |
| 2211 | return -EINVAL; |
| 2212 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2213 | changed |= WIPHY_PARAM_RETRY_SHORT; |
| 2214 | } |
| 2215 | |
| 2216 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { |
| 2217 | retry_long = nla_get_u8( |
| 2218 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2219 | if (retry_long == 0) |
| 2220 | return -EINVAL; |
| 2221 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2222 | changed |= WIPHY_PARAM_RETRY_LONG; |
| 2223 | } |
| 2224 | |
| 2225 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { |
| 2226 | frag_threshold = nla_get_u32( |
| 2227 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2228 | if (frag_threshold < 256) |
| 2229 | return -EINVAL; |
| 2230 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2231 | if (frag_threshold != (u32) -1) { |
| 2232 | /* |
| 2233 | * Fragments (apart from the last one) are required to |
| 2234 | * have even length. Make the fragmentation code |
| 2235 | * simpler by stripping LSB should someone try to use |
| 2236 | * odd threshold value. |
| 2237 | */ |
| 2238 | frag_threshold &= ~0x1; |
| 2239 | } |
| 2240 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; |
| 2241 | } |
| 2242 | |
| 2243 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { |
| 2244 | rts_threshold = nla_get_u32( |
| 2245 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); |
| 2246 | changed |= WIPHY_PARAM_RTS_THRESHOLD; |
| 2247 | } |
| 2248 | |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2249 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
Lorenzo Bianconi | 3057dbf | 2014-09-04 23:57:40 +0200 | [diff] [blame] | 2250 | if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) |
| 2251 | return -EINVAL; |
| 2252 | |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2253 | coverage_class = nla_get_u8( |
| 2254 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); |
| 2255 | changed |= WIPHY_PARAM_COVERAGE_CLASS; |
| 2256 | } |
| 2257 | |
Lorenzo Bianconi | 3057dbf | 2014-09-04 23:57:40 +0200 | [diff] [blame] | 2258 | if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) { |
| 2259 | if (!(rdev->wiphy.features & NL80211_FEATURE_ACKTO_ESTIMATION)) |
| 2260 | return -EOPNOTSUPP; |
| 2261 | |
| 2262 | changed |= WIPHY_PARAM_DYN_ACK; |
| 2263 | } |
| 2264 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2265 | if (changed) { |
| 2266 | u8 old_retry_short, old_retry_long; |
| 2267 | u32 old_frag_threshold, old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2268 | u8 old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2269 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2270 | if (!rdev->ops->set_wiphy_params) |
| 2271 | return -EOPNOTSUPP; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2272 | |
| 2273 | old_retry_short = rdev->wiphy.retry_short; |
| 2274 | old_retry_long = rdev->wiphy.retry_long; |
| 2275 | old_frag_threshold = rdev->wiphy.frag_threshold; |
| 2276 | old_rts_threshold = rdev->wiphy.rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2277 | old_coverage_class = rdev->wiphy.coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2278 | |
| 2279 | if (changed & WIPHY_PARAM_RETRY_SHORT) |
| 2280 | rdev->wiphy.retry_short = retry_short; |
| 2281 | if (changed & WIPHY_PARAM_RETRY_LONG) |
| 2282 | rdev->wiphy.retry_long = retry_long; |
| 2283 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) |
| 2284 | rdev->wiphy.frag_threshold = frag_threshold; |
| 2285 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) |
| 2286 | rdev->wiphy.rts_threshold = rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2287 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
| 2288 | rdev->wiphy.coverage_class = coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2289 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2290 | result = rdev_set_wiphy_params(rdev, changed); |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2291 | if (result) { |
| 2292 | rdev->wiphy.retry_short = old_retry_short; |
| 2293 | rdev->wiphy.retry_long = old_retry_long; |
| 2294 | rdev->wiphy.frag_threshold = old_frag_threshold; |
| 2295 | rdev->wiphy.rts_threshold = old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2296 | rdev->wiphy.coverage_class = old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2297 | } |
| 2298 | } |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2299 | return 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2300 | } |
| 2301 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 2302 | static inline u64 wdev_id(struct wireless_dev *wdev) |
| 2303 | { |
| 2304 | return (u64)wdev->identifier | |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 2305 | ((u64)wiphy_to_rdev(wdev->wiphy)->wiphy_idx << 32); |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 2306 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2307 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2308 | static int nl80211_send_chandef(struct sk_buff *msg, |
Janusz Dziedzic | d2859df | 2013-11-06 13:55:51 +0100 | [diff] [blame] | 2309 | const struct cfg80211_chan_def *chandef) |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2310 | { |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 2311 | WARN_ON(!cfg80211_chandef_valid(chandef)); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2312 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2313 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
| 2314 | chandef->chan->center_freq)) |
| 2315 | return -ENOBUFS; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2316 | switch (chandef->width) { |
| 2317 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 2318 | case NL80211_CHAN_WIDTH_20: |
| 2319 | case NL80211_CHAN_WIDTH_40: |
| 2320 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 2321 | cfg80211_get_chandef_type(chandef))) |
| 2322 | return -ENOBUFS; |
| 2323 | break; |
| 2324 | default: |
| 2325 | break; |
| 2326 | } |
| 2327 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width)) |
| 2328 | return -ENOBUFS; |
| 2329 | if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1)) |
| 2330 | return -ENOBUFS; |
| 2331 | if (chandef->center_freq2 && |
| 2332 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2)) |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2333 | return -ENOBUFS; |
| 2334 | return 0; |
| 2335 | } |
| 2336 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2337 | 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] | 2338 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2339 | struct wireless_dev *wdev) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2340 | { |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2341 | struct net_device *dev = wdev->netdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2342 | void *hdr; |
| 2343 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2344 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_INTERFACE); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2345 | if (!hdr) |
| 2346 | return -1; |
| 2347 | |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2348 | if (dev && |
| 2349 | (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2350 | nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name))) |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2351 | goto nla_put_failure; |
| 2352 | |
| 2353 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 2354 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 2355 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2356 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2357 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
| 2358 | rdev->devlist_generation ^ |
| 2359 | (cfg80211_rdev_list_generation << 2))) |
| 2360 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2361 | |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 2362 | if (rdev->ops->get_channel) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2363 | int ret; |
| 2364 | struct cfg80211_chan_def chandef; |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 2365 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2366 | ret = rdev_get_channel(rdev, wdev, &chandef); |
| 2367 | if (ret == 0) { |
| 2368 | if (nl80211_send_chandef(msg, &chandef)) |
| 2369 | goto nla_put_failure; |
| 2370 | } |
Pontus Fuchs | d91df0e | 2012-04-03 16:39:58 +0200 | [diff] [blame] | 2371 | } |
| 2372 | |
Antonio Quartulli | b84e7a0 | 2012-11-07 12:52:20 +0100 | [diff] [blame] | 2373 | if (wdev->ssid_len) { |
| 2374 | if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid)) |
| 2375 | goto nla_put_failure; |
| 2376 | } |
| 2377 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2378 | return genlmsg_end(msg, hdr); |
| 2379 | |
| 2380 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 2381 | genlmsg_cancel(msg, hdr); |
| 2382 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2383 | } |
| 2384 | |
| 2385 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) |
| 2386 | { |
| 2387 | int wp_idx = 0; |
| 2388 | int if_idx = 0; |
| 2389 | int wp_start = cb->args[0]; |
| 2390 | int if_start = cb->args[1]; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2391 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2392 | struct wireless_dev *wdev; |
| 2393 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2394 | rtnl_lock(); |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2395 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 2396 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2397 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2398 | if (wp_idx < wp_start) { |
| 2399 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2400 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2401 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2402 | if_idx = 0; |
| 2403 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 2404 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2405 | if (if_idx < if_start) { |
| 2406 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2407 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2408 | } |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2409 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2410 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2411 | rdev, wdev) < 0) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2412 | goto out; |
| 2413 | } |
| 2414 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2415 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2416 | |
| 2417 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2418 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2419 | out: |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2420 | rtnl_unlock(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2421 | |
| 2422 | cb->args[0] = wp_idx; |
| 2423 | cb->args[1] = if_idx; |
| 2424 | |
| 2425 | return skb->len; |
| 2426 | } |
| 2427 | |
| 2428 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) |
| 2429 | { |
| 2430 | struct sk_buff *msg; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2431 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2432 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2433 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2434 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2435 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2436 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2437 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2438 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2439 | rdev, wdev) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2440 | nlmsg_free(msg); |
| 2441 | return -ENOBUFS; |
| 2442 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2443 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 2444 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2445 | } |
| 2446 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2447 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
| 2448 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, |
| 2449 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, |
| 2450 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, |
| 2451 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, |
| 2452 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2453 | [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG }, |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2454 | }; |
| 2455 | |
| 2456 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) |
| 2457 | { |
| 2458 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; |
| 2459 | int flag; |
| 2460 | |
| 2461 | *mntrflags = 0; |
| 2462 | |
| 2463 | if (!nla) |
| 2464 | return -EINVAL; |
| 2465 | |
| 2466 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, |
| 2467 | nla, mntr_flags_policy)) |
| 2468 | return -EINVAL; |
| 2469 | |
| 2470 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) |
| 2471 | if (flags[flag]) |
| 2472 | *mntrflags |= (1<<flag); |
| 2473 | |
| 2474 | return 0; |
| 2475 | } |
| 2476 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2477 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2478 | struct net_device *netdev, u8 use_4addr, |
| 2479 | enum nl80211_iftype iftype) |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2480 | { |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2481 | if (!use_4addr) { |
Jiri Pirko | f350a0a8 | 2010-06-15 06:50:45 +0000 | [diff] [blame] | 2482 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2483 | return -EBUSY; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2484 | return 0; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2485 | } |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2486 | |
| 2487 | switch (iftype) { |
| 2488 | case NL80211_IFTYPE_AP_VLAN: |
| 2489 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) |
| 2490 | return 0; |
| 2491 | break; |
| 2492 | case NL80211_IFTYPE_STATION: |
| 2493 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) |
| 2494 | return 0; |
| 2495 | break; |
| 2496 | default: |
| 2497 | break; |
| 2498 | } |
| 2499 | |
| 2500 | return -EOPNOTSUPP; |
| 2501 | } |
| 2502 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2503 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
| 2504 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2505 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2506 | struct vif_params params; |
Johannes Berg | e36d56b | 2009-06-09 21:04:43 +0200 | [diff] [blame] | 2507 | int err; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2508 | enum nl80211_iftype otype, ntype; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2509 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2510 | u32 _flags, *flags = NULL; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2511 | bool change = false; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2512 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2513 | memset(¶ms, 0, sizeof(params)); |
| 2514 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2515 | otype = ntype = dev->ieee80211_ptr->iftype; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2516 | |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 2517 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2518 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2519 | if (otype != ntype) |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2520 | change = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2521 | if (ntype > NL80211_IFTYPE_MAX) |
| 2522 | return -EINVAL; |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 2523 | } |
| 2524 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2525 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2526 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2527 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2528 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
| 2529 | return -EINVAL; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2530 | if (netif_running(dev)) |
| 2531 | return -EBUSY; |
| 2532 | |
| 2533 | wdev_lock(wdev); |
| 2534 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 2535 | IEEE80211_MAX_MESH_ID_LEN); |
| 2536 | wdev->mesh_id_up_len = |
| 2537 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 2538 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 2539 | wdev->mesh_id_up_len); |
| 2540 | wdev_unlock(wdev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2541 | } |
| 2542 | |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2543 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
| 2544 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
| 2545 | change = true; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2546 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2547 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2548 | return err; |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2549 | } else { |
| 2550 | params.use_4addr = -1; |
| 2551 | } |
| 2552 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2553 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2554 | if (ntype != NL80211_IFTYPE_MONITOR) |
| 2555 | return -EINVAL; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2556 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
| 2557 | &_flags); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2558 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2559 | return err; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2560 | |
| 2561 | flags = &_flags; |
| 2562 | change = true; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2563 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2564 | |
Luciano Coelho | 1800329 | 2013-08-29 13:26:57 +0300 | [diff] [blame] | 2565 | if (flags && (*flags & MONITOR_FLAG_ACTIVE) && |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2566 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
| 2567 | return -EOPNOTSUPP; |
| 2568 | |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2569 | if (change) |
Johannes Berg | 3d54d25 | 2009-08-21 14:51:05 +0200 | [diff] [blame] | 2570 | err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2571 | else |
| 2572 | err = 0; |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 2573 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2574 | if (!err && params.use_4addr != -1) |
| 2575 | dev->ieee80211_ptr->use_4addr = params.use_4addr; |
| 2576 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2577 | return err; |
| 2578 | } |
| 2579 | |
| 2580 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) |
| 2581 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2582 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2583 | struct vif_params params; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2584 | struct wireless_dev *wdev; |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2585 | struct sk_buff *msg; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2586 | int err; |
| 2587 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2588 | u32 flags; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2589 | |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 2590 | /* to avoid failing a new interface creation due to pending removal */ |
| 2591 | cfg80211_destroy_ifaces(rdev); |
| 2592 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2593 | memset(¶ms, 0, sizeof(params)); |
| 2594 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2595 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
| 2596 | return -EINVAL; |
| 2597 | |
| 2598 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
| 2599 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
| 2600 | if (type > NL80211_IFTYPE_MAX) |
| 2601 | return -EINVAL; |
| 2602 | } |
| 2603 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2604 | if (!rdev->ops->add_virtual_intf || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2605 | !(rdev->wiphy.interface_modes & (1 << type))) |
| 2606 | return -EOPNOTSUPP; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2607 | |
Arend van Spriel | 1c18f14 | 2013-01-08 10:17:27 +0100 | [diff] [blame] | 2608 | if (type == NL80211_IFTYPE_P2P_DEVICE && info->attrs[NL80211_ATTR_MAC]) { |
| 2609 | nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC], |
| 2610 | ETH_ALEN); |
| 2611 | if (!is_valid_ether_addr(params.macaddr)) |
| 2612 | return -EADDRNOTAVAIL; |
| 2613 | } |
| 2614 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2615 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2616 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2617 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2618 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2619 | return err; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2620 | } |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2621 | |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2622 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 2623 | if (!msg) |
| 2624 | return -ENOMEM; |
| 2625 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2626 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
| 2627 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, |
| 2628 | &flags); |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2629 | |
Luciano Coelho | 1800329 | 2013-08-29 13:26:57 +0300 | [diff] [blame] | 2630 | if (!err && (flags & MONITOR_FLAG_ACTIVE) && |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2631 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
| 2632 | return -EOPNOTSUPP; |
| 2633 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2634 | wdev = rdev_add_virtual_intf(rdev, |
| 2635 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), |
| 2636 | type, err ? NULL : &flags, ¶ms); |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2637 | if (IS_ERR(wdev)) { |
| 2638 | nlmsg_free(msg); |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2639 | return PTR_ERR(wdev); |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2640 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2641 | |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 2642 | if (info->attrs[NL80211_ATTR_IFACE_SOCKET_OWNER]) |
| 2643 | wdev->owner_nlportid = info->snd_portid; |
| 2644 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2645 | switch (type) { |
| 2646 | case NL80211_IFTYPE_MESH_POINT: |
| 2647 | if (!info->attrs[NL80211_ATTR_MESH_ID]) |
| 2648 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2649 | wdev_lock(wdev); |
| 2650 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 2651 | IEEE80211_MAX_MESH_ID_LEN); |
| 2652 | wdev->mesh_id_up_len = |
| 2653 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 2654 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 2655 | wdev->mesh_id_up_len); |
| 2656 | wdev_unlock(wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2657 | break; |
| 2658 | case NL80211_IFTYPE_P2P_DEVICE: |
| 2659 | /* |
| 2660 | * P2P Device doesn't have a netdev, so doesn't go |
| 2661 | * through the netdev notifier and must be added here |
| 2662 | */ |
| 2663 | mutex_init(&wdev->mtx); |
| 2664 | INIT_LIST_HEAD(&wdev->event_list); |
| 2665 | spin_lock_init(&wdev->event_lock); |
| 2666 | INIT_LIST_HEAD(&wdev->mgmt_registrations); |
| 2667 | spin_lock_init(&wdev->mgmt_registrations_lock); |
| 2668 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2669 | wdev->identifier = ++rdev->wdev_id; |
| 2670 | list_add_rcu(&wdev->list, &rdev->wdev_list); |
| 2671 | rdev->devlist_generation++; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2672 | break; |
| 2673 | default: |
| 2674 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2675 | } |
| 2676 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2677 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2678 | rdev, wdev) < 0) { |
| 2679 | nlmsg_free(msg); |
| 2680 | return -ENOBUFS; |
| 2681 | } |
| 2682 | |
| 2683 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2684 | } |
| 2685 | |
| 2686 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) |
| 2687 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2688 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2689 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2690 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2691 | if (!rdev->ops->del_virtual_intf) |
| 2692 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2693 | |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2694 | /* |
| 2695 | * If we remove a wireless device without a netdev then clear |
| 2696 | * user_ptr[1] so that nl80211_post_doit won't dereference it |
| 2697 | * to check if it needs to do dev_put(). Otherwise it crashes |
| 2698 | * since the wdev has been freed, unlike with a netdev where |
| 2699 | * we need the dev_put() for the netdev to really be freed. |
| 2700 | */ |
| 2701 | if (!wdev->netdev) |
| 2702 | info->user_ptr[1] = NULL; |
| 2703 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2704 | return rdev_del_virtual_intf(rdev, wdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2705 | } |
| 2706 | |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 2707 | static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info) |
| 2708 | { |
| 2709 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2710 | struct net_device *dev = info->user_ptr[1]; |
| 2711 | u16 noack_map; |
| 2712 | |
| 2713 | if (!info->attrs[NL80211_ATTR_NOACK_MAP]) |
| 2714 | return -EINVAL; |
| 2715 | |
| 2716 | if (!rdev->ops->set_noack_map) |
| 2717 | return -EOPNOTSUPP; |
| 2718 | |
| 2719 | noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]); |
| 2720 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2721 | return rdev_set_noack_map(rdev, dev, noack_map); |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 2722 | } |
| 2723 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2724 | struct get_key_cookie { |
| 2725 | struct sk_buff *msg; |
| 2726 | int error; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2727 | int idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2728 | }; |
| 2729 | |
| 2730 | static void get_key_callback(void *c, struct key_params *params) |
| 2731 | { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2732 | struct nlattr *key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2733 | struct get_key_cookie *cookie = c; |
| 2734 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2735 | if ((params->key && |
| 2736 | nla_put(cookie->msg, NL80211_ATTR_KEY_DATA, |
| 2737 | params->key_len, params->key)) || |
| 2738 | (params->seq && |
| 2739 | nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ, |
| 2740 | params->seq_len, params->seq)) || |
| 2741 | (params->cipher && |
| 2742 | nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER, |
| 2743 | params->cipher))) |
| 2744 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2745 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2746 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
| 2747 | if (!key) |
| 2748 | goto nla_put_failure; |
| 2749 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2750 | if ((params->key && |
| 2751 | nla_put(cookie->msg, NL80211_KEY_DATA, |
| 2752 | params->key_len, params->key)) || |
| 2753 | (params->seq && |
| 2754 | nla_put(cookie->msg, NL80211_KEY_SEQ, |
| 2755 | params->seq_len, params->seq)) || |
| 2756 | (params->cipher && |
| 2757 | nla_put_u32(cookie->msg, NL80211_KEY_CIPHER, |
| 2758 | params->cipher))) |
| 2759 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2760 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2761 | if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx)) |
| 2762 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2763 | |
| 2764 | nla_nest_end(cookie->msg, key); |
| 2765 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2766 | return; |
| 2767 | nla_put_failure: |
| 2768 | cookie->error = 1; |
| 2769 | } |
| 2770 | |
| 2771 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) |
| 2772 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2773 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2774 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2775 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2776 | u8 key_idx = 0; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2777 | const u8 *mac_addr = NULL; |
| 2778 | bool pairwise; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2779 | struct get_key_cookie cookie = { |
| 2780 | .error = 0, |
| 2781 | }; |
| 2782 | void *hdr; |
| 2783 | struct sk_buff *msg; |
| 2784 | |
| 2785 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 2786 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 2787 | |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 2788 | if (key_idx > 5) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2789 | return -EINVAL; |
| 2790 | |
| 2791 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2792 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2793 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2794 | pairwise = !!mac_addr; |
| 2795 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 2796 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 2797 | if (kt >= NUM_NL80211_KEYTYPES) |
| 2798 | return -EINVAL; |
| 2799 | if (kt != NL80211_KEYTYPE_GROUP && |
| 2800 | kt != NL80211_KEYTYPE_PAIRWISE) |
| 2801 | return -EINVAL; |
| 2802 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; |
| 2803 | } |
| 2804 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2805 | if (!rdev->ops->get_key) |
| 2806 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2807 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2808 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2809 | if (!msg) |
| 2810 | return -ENOMEM; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2811 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2812 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2813 | NL80211_CMD_NEW_KEY); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 2814 | if (!hdr) |
Johannes Berg | 9fe271a | 2013-10-25 11:15:12 +0200 | [diff] [blame] | 2815 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2816 | |
| 2817 | cookie.msg = msg; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2818 | cookie.idx = key_idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2819 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2820 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 2821 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) |
| 2822 | goto nla_put_failure; |
| 2823 | if (mac_addr && |
| 2824 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 2825 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2826 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2827 | if (pairwise && mac_addr && |
| 2828 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 2829 | return -ENOENT; |
| 2830 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2831 | err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie, |
| 2832 | get_key_callback); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2833 | |
| 2834 | if (err) |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 2835 | goto free_msg; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2836 | |
| 2837 | if (cookie.error) |
| 2838 | goto nla_put_failure; |
| 2839 | |
| 2840 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2841 | return genlmsg_reply(msg, info); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2842 | |
| 2843 | nla_put_failure: |
| 2844 | err = -ENOBUFS; |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 2845 | free_msg: |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2846 | nlmsg_free(msg); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2847 | return err; |
| 2848 | } |
| 2849 | |
| 2850 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) |
| 2851 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2852 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2853 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2854 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2855 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2856 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2857 | err = nl80211_parse_key(info, &key); |
| 2858 | if (err) |
| 2859 | return err; |
| 2860 | |
| 2861 | if (key.idx < 0) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2862 | return -EINVAL; |
| 2863 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2864 | /* only support setting default key */ |
| 2865 | if (!key.def && !key.defmgmt) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2866 | return -EINVAL; |
| 2867 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2868 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2869 | |
| 2870 | if (key.def) { |
| 2871 | if (!rdev->ops->set_default_key) { |
| 2872 | err = -EOPNOTSUPP; |
| 2873 | goto out; |
| 2874 | } |
| 2875 | |
| 2876 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2877 | if (err) |
| 2878 | goto out; |
| 2879 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2880 | err = rdev_set_default_key(rdev, dev, key.idx, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2881 | key.def_uni, key.def_multi); |
| 2882 | |
| 2883 | if (err) |
| 2884 | goto out; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2885 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 2886 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2887 | dev->ieee80211_ptr->wext.default_key = key.idx; |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2888 | #endif |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2889 | } else { |
| 2890 | if (key.def_uni || !key.def_multi) { |
| 2891 | err = -EINVAL; |
| 2892 | goto out; |
| 2893 | } |
| 2894 | |
| 2895 | if (!rdev->ops->set_default_mgmt_key) { |
| 2896 | err = -EOPNOTSUPP; |
| 2897 | goto out; |
| 2898 | } |
| 2899 | |
| 2900 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2901 | if (err) |
| 2902 | goto out; |
| 2903 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2904 | err = rdev_set_default_mgmt_key(rdev, dev, key.idx); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2905 | if (err) |
| 2906 | goto out; |
| 2907 | |
| 2908 | #ifdef CONFIG_CFG80211_WEXT |
| 2909 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; |
| 2910 | #endif |
| 2911 | } |
| 2912 | |
| 2913 | out: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2914 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2915 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2916 | return err; |
| 2917 | } |
| 2918 | |
| 2919 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) |
| 2920 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2921 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2922 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2923 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2924 | struct key_parse key; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2925 | const u8 *mac_addr = NULL; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2926 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2927 | err = nl80211_parse_key(info, &key); |
| 2928 | if (err) |
| 2929 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2930 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2931 | if (!key.p.key) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2932 | return -EINVAL; |
| 2933 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2934 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2935 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2936 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2937 | if (key.type == -1) { |
| 2938 | if (mac_addr) |
| 2939 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 2940 | else |
| 2941 | key.type = NL80211_KEYTYPE_GROUP; |
| 2942 | } |
| 2943 | |
| 2944 | /* for now */ |
| 2945 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 2946 | key.type != NL80211_KEYTYPE_GROUP) |
| 2947 | return -EINVAL; |
| 2948 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2949 | if (!rdev->ops->add_key) |
| 2950 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2951 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2952 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
| 2953 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2954 | mac_addr)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2955 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2956 | |
| 2957 | wdev_lock(dev->ieee80211_ptr); |
| 2958 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2959 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2960 | err = rdev_add_key(rdev, dev, key.idx, |
| 2961 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2962 | mac_addr, &key.p); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2963 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2964 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2965 | return err; |
| 2966 | } |
| 2967 | |
| 2968 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) |
| 2969 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2970 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2971 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2972 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2973 | u8 *mac_addr = NULL; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2974 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2975 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2976 | err = nl80211_parse_key(info, &key); |
| 2977 | if (err) |
| 2978 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2979 | |
| 2980 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2981 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2982 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2983 | if (key.type == -1) { |
| 2984 | if (mac_addr) |
| 2985 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 2986 | else |
| 2987 | key.type = NL80211_KEYTYPE_GROUP; |
| 2988 | } |
| 2989 | |
| 2990 | /* for now */ |
| 2991 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 2992 | key.type != NL80211_KEYTYPE_GROUP) |
| 2993 | return -EINVAL; |
| 2994 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2995 | if (!rdev->ops->del_key) |
| 2996 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2997 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2998 | wdev_lock(dev->ieee80211_ptr); |
| 2999 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3000 | |
| 3001 | if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr && |
| 3002 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 3003 | err = -ENOENT; |
| 3004 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3005 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3006 | err = rdev_del_key(rdev, dev, key.idx, |
| 3007 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 3008 | mac_addr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3009 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 3010 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 3011 | if (!err) { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3012 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 3013 | dev->ieee80211_ptr->wext.default_key = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3014 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 3015 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
| 3016 | } |
| 3017 | #endif |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3018 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 3019 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3020 | return err; |
| 3021 | } |
| 3022 | |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 3023 | /* This function returns an error or the number of nested attributes */ |
| 3024 | static int validate_acl_mac_addrs(struct nlattr *nl_attr) |
| 3025 | { |
| 3026 | struct nlattr *attr; |
| 3027 | int n_entries = 0, tmp; |
| 3028 | |
| 3029 | nla_for_each_nested(attr, nl_attr, tmp) { |
| 3030 | if (nla_len(attr) != ETH_ALEN) |
| 3031 | return -EINVAL; |
| 3032 | |
| 3033 | n_entries++; |
| 3034 | } |
| 3035 | |
| 3036 | return n_entries; |
| 3037 | } |
| 3038 | |
| 3039 | /* |
| 3040 | * This function parses ACL information and allocates memory for ACL data. |
| 3041 | * On successful return, the calling function is responsible to free the |
| 3042 | * ACL buffer returned by this function. |
| 3043 | */ |
| 3044 | static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy, |
| 3045 | struct genl_info *info) |
| 3046 | { |
| 3047 | enum nl80211_acl_policy acl_policy; |
| 3048 | struct nlattr *attr; |
| 3049 | struct cfg80211_acl_data *acl; |
| 3050 | int i = 0, n_entries, tmp; |
| 3051 | |
| 3052 | if (!wiphy->max_acl_mac_addrs) |
| 3053 | return ERR_PTR(-EOPNOTSUPP); |
| 3054 | |
| 3055 | if (!info->attrs[NL80211_ATTR_ACL_POLICY]) |
| 3056 | return ERR_PTR(-EINVAL); |
| 3057 | |
| 3058 | acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]); |
| 3059 | if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED && |
| 3060 | acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED) |
| 3061 | return ERR_PTR(-EINVAL); |
| 3062 | |
| 3063 | if (!info->attrs[NL80211_ATTR_MAC_ADDRS]) |
| 3064 | return ERR_PTR(-EINVAL); |
| 3065 | |
| 3066 | n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]); |
| 3067 | if (n_entries < 0) |
| 3068 | return ERR_PTR(n_entries); |
| 3069 | |
| 3070 | if (n_entries > wiphy->max_acl_mac_addrs) |
| 3071 | return ERR_PTR(-ENOTSUPP); |
| 3072 | |
| 3073 | acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries), |
| 3074 | GFP_KERNEL); |
| 3075 | if (!acl) |
| 3076 | return ERR_PTR(-ENOMEM); |
| 3077 | |
| 3078 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) { |
| 3079 | memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN); |
| 3080 | i++; |
| 3081 | } |
| 3082 | |
| 3083 | acl->n_acl_entries = n_entries; |
| 3084 | acl->acl_policy = acl_policy; |
| 3085 | |
| 3086 | return acl; |
| 3087 | } |
| 3088 | |
| 3089 | static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info) |
| 3090 | { |
| 3091 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3092 | struct net_device *dev = info->user_ptr[1]; |
| 3093 | struct cfg80211_acl_data *acl; |
| 3094 | int err; |
| 3095 | |
| 3096 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3097 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3098 | return -EOPNOTSUPP; |
| 3099 | |
| 3100 | if (!dev->ieee80211_ptr->beacon_interval) |
| 3101 | return -EINVAL; |
| 3102 | |
| 3103 | acl = parse_acl_data(&rdev->wiphy, info); |
| 3104 | if (IS_ERR(acl)) |
| 3105 | return PTR_ERR(acl); |
| 3106 | |
| 3107 | err = rdev_set_mac_acl(rdev, dev, acl); |
| 3108 | |
| 3109 | kfree(acl); |
| 3110 | |
| 3111 | return err; |
| 3112 | } |
| 3113 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3114 | static int nl80211_parse_beacon(struct nlattr *attrs[], |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3115 | struct cfg80211_beacon_data *bcn) |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3116 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3117 | bool haveinfo = false; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3118 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3119 | if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) || |
| 3120 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) || |
| 3121 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) || |
| 3122 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP])) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 3123 | return -EINVAL; |
| 3124 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3125 | memset(bcn, 0, sizeof(*bcn)); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3126 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3127 | if (attrs[NL80211_ATTR_BEACON_HEAD]) { |
| 3128 | bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]); |
| 3129 | bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3130 | if (!bcn->head_len) |
| 3131 | return -EINVAL; |
| 3132 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3133 | } |
| 3134 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3135 | if (attrs[NL80211_ATTR_BEACON_TAIL]) { |
| 3136 | bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]); |
| 3137 | bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3138 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3139 | } |
| 3140 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3141 | if (!haveinfo) |
| 3142 | return -EINVAL; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3143 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3144 | if (attrs[NL80211_ATTR_IE]) { |
| 3145 | bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]); |
| 3146 | bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 3147 | } |
| 3148 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3149 | if (attrs[NL80211_ATTR_IE_PROBE_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3150 | bcn->proberesp_ies = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3151 | nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3152 | bcn->proberesp_ies_len = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3153 | nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 3154 | } |
| 3155 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3156 | if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3157 | bcn->assocresp_ies = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3158 | nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3159 | bcn->assocresp_ies_len = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3160 | nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 3161 | } |
| 3162 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3163 | if (attrs[NL80211_ATTR_PROBE_RESP]) { |
| 3164 | bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]); |
| 3165 | bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]); |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 3166 | } |
| 3167 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3168 | return 0; |
| 3169 | } |
| 3170 | |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3171 | static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev, |
| 3172 | struct cfg80211_ap_settings *params) |
| 3173 | { |
| 3174 | struct wireless_dev *wdev; |
| 3175 | bool ret = false; |
| 3176 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 3177 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3178 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 3179 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 3180 | continue; |
| 3181 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3182 | if (!wdev->preset_chandef.chan) |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3183 | continue; |
| 3184 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3185 | params->chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3186 | ret = true; |
| 3187 | break; |
| 3188 | } |
| 3189 | |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3190 | return ret; |
| 3191 | } |
| 3192 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 3193 | static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev, |
| 3194 | enum nl80211_auth_type auth_type, |
| 3195 | enum nl80211_commands cmd) |
| 3196 | { |
| 3197 | if (auth_type > NL80211_AUTHTYPE_MAX) |
| 3198 | return false; |
| 3199 | |
| 3200 | switch (cmd) { |
| 3201 | case NL80211_CMD_AUTHENTICATE: |
| 3202 | if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && |
| 3203 | auth_type == NL80211_AUTHTYPE_SAE) |
| 3204 | return false; |
| 3205 | return true; |
| 3206 | case NL80211_CMD_CONNECT: |
| 3207 | case NL80211_CMD_START_AP: |
| 3208 | /* SAE not supported yet */ |
| 3209 | if (auth_type == NL80211_AUTHTYPE_SAE) |
| 3210 | return false; |
| 3211 | return true; |
| 3212 | default: |
| 3213 | return false; |
| 3214 | } |
| 3215 | } |
| 3216 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3217 | static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) |
| 3218 | { |
| 3219 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3220 | struct net_device *dev = info->user_ptr[1]; |
| 3221 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3222 | struct cfg80211_ap_settings params; |
| 3223 | int err; |
| 3224 | |
| 3225 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3226 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3227 | return -EOPNOTSUPP; |
| 3228 | |
| 3229 | if (!rdev->ops->start_ap) |
| 3230 | return -EOPNOTSUPP; |
| 3231 | |
| 3232 | if (wdev->beacon_interval) |
| 3233 | return -EALREADY; |
| 3234 | |
| 3235 | memset(¶ms, 0, sizeof(params)); |
| 3236 | |
| 3237 | /* these are required for START_AP */ |
| 3238 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || |
| 3239 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || |
| 3240 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) |
| 3241 | return -EINVAL; |
| 3242 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3243 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3244 | if (err) |
| 3245 | return err; |
| 3246 | |
| 3247 | params.beacon_interval = |
| 3248 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 3249 | params.dtim_period = |
| 3250 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 3251 | |
| 3252 | err = cfg80211_validate_beacon_int(rdev, params.beacon_interval); |
| 3253 | if (err) |
| 3254 | return err; |
| 3255 | |
| 3256 | /* |
| 3257 | * In theory, some of these attributes should be required here |
| 3258 | * but since they were not used when the command was originally |
| 3259 | * added, keep them optional for old user space programs to let |
| 3260 | * them continue to work with drivers that do not need the |
| 3261 | * additional information -- drivers must check! |
| 3262 | */ |
| 3263 | if (info->attrs[NL80211_ATTR_SSID]) { |
| 3264 | params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 3265 | params.ssid_len = |
| 3266 | nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 3267 | if (params.ssid_len == 0 || |
| 3268 | params.ssid_len > IEEE80211_MAX_SSID_LEN) |
| 3269 | return -EINVAL; |
| 3270 | } |
| 3271 | |
| 3272 | if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) { |
| 3273 | params.hidden_ssid = nla_get_u32( |
| 3274 | info->attrs[NL80211_ATTR_HIDDEN_SSID]); |
| 3275 | if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE && |
| 3276 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN && |
| 3277 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS) |
| 3278 | return -EINVAL; |
| 3279 | } |
| 3280 | |
| 3281 | params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
| 3282 | |
| 3283 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 3284 | params.auth_type = nla_get_u32( |
| 3285 | info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 3286 | if (!nl80211_valid_auth_type(rdev, params.auth_type, |
| 3287 | NL80211_CMD_START_AP)) |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3288 | return -EINVAL; |
| 3289 | } else |
| 3290 | params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 3291 | |
| 3292 | err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, |
| 3293 | NL80211_MAX_NR_CIPHER_SUITES); |
| 3294 | if (err) |
| 3295 | return err; |
| 3296 | |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 3297 | if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) { |
| 3298 | if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER)) |
| 3299 | return -EOPNOTSUPP; |
| 3300 | params.inactivity_timeout = nla_get_u16( |
| 3301 | info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]); |
| 3302 | } |
| 3303 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 3304 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 3305 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3306 | return -EINVAL; |
| 3307 | params.p2p_ctwindow = |
| 3308 | nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
| 3309 | if (params.p2p_ctwindow > 127) |
| 3310 | return -EINVAL; |
| 3311 | if (params.p2p_ctwindow != 0 && |
| 3312 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 3313 | return -EINVAL; |
| 3314 | } |
| 3315 | |
| 3316 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 3317 | u8 tmp; |
| 3318 | |
| 3319 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3320 | return -EINVAL; |
| 3321 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
| 3322 | if (tmp > 1) |
| 3323 | return -EINVAL; |
| 3324 | params.p2p_opp_ps = tmp; |
| 3325 | if (params.p2p_opp_ps != 0 && |
| 3326 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 3327 | return -EINVAL; |
| 3328 | } |
| 3329 | |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3330 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3331 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
| 3332 | if (err) |
| 3333 | return err; |
| 3334 | } else if (wdev->preset_chandef.chan) { |
| 3335 | params.chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3336 | } else if (!nl80211_get_ap_channel(rdev, ¶ms)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3337 | return -EINVAL; |
| 3338 | |
Ilan Peer | 174e0cd | 2014-02-23 09:13:01 +0200 | [diff] [blame] | 3339 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, ¶ms.chandef, |
| 3340 | wdev->iftype)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3341 | return -EINVAL; |
| 3342 | |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 3343 | if (info->attrs[NL80211_ATTR_ACL_POLICY]) { |
| 3344 | params.acl = parse_acl_data(&rdev->wiphy, info); |
| 3345 | if (IS_ERR(params.acl)) |
| 3346 | return PTR_ERR(params.acl); |
| 3347 | } |
| 3348 | |
Eliad Peller | 18998c3 | 2014-09-10 14:07:34 +0300 | [diff] [blame] | 3349 | if (info->attrs[NL80211_ATTR_SMPS_MODE]) { |
| 3350 | params.smps_mode = |
| 3351 | nla_get_u8(info->attrs[NL80211_ATTR_SMPS_MODE]); |
| 3352 | switch (params.smps_mode) { |
| 3353 | case NL80211_SMPS_OFF: |
| 3354 | break; |
| 3355 | case NL80211_SMPS_STATIC: |
| 3356 | if (!(rdev->wiphy.features & |
| 3357 | NL80211_FEATURE_STATIC_SMPS)) |
| 3358 | return -EINVAL; |
| 3359 | break; |
| 3360 | case NL80211_SMPS_DYNAMIC: |
| 3361 | if (!(rdev->wiphy.features & |
| 3362 | NL80211_FEATURE_DYNAMIC_SMPS)) |
| 3363 | return -EINVAL; |
| 3364 | break; |
| 3365 | default: |
| 3366 | return -EINVAL; |
| 3367 | } |
| 3368 | } else { |
| 3369 | params.smps_mode = NL80211_SMPS_OFF; |
| 3370 | } |
| 3371 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 3372 | wdev_lock(wdev); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3373 | err = rdev_start_ap(rdev, dev, ¶ms); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3374 | if (!err) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3375 | wdev->preset_chandef = params.chandef; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3376 | wdev->beacon_interval = params.beacon_interval; |
Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 3377 | wdev->chandef = params.chandef; |
Antonio Quartulli | 06e191e | 2012-11-07 12:52:19 +0100 | [diff] [blame] | 3378 | wdev->ssid_len = params.ssid_len; |
| 3379 | memcpy(wdev->ssid, params.ssid, wdev->ssid_len); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3380 | } |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 3381 | wdev_unlock(wdev); |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 3382 | |
| 3383 | kfree(params.acl); |
| 3384 | |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 3385 | return err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3386 | } |
| 3387 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3388 | static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info) |
| 3389 | { |
| 3390 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3391 | struct net_device *dev = info->user_ptr[1]; |
| 3392 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3393 | struct cfg80211_beacon_data params; |
| 3394 | int err; |
| 3395 | |
| 3396 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3397 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3398 | return -EOPNOTSUPP; |
| 3399 | |
| 3400 | if (!rdev->ops->change_beacon) |
| 3401 | return -EOPNOTSUPP; |
| 3402 | |
| 3403 | if (!wdev->beacon_interval) |
| 3404 | return -EINVAL; |
| 3405 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3406 | err = nl80211_parse_beacon(info->attrs, ¶ms); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3407 | if (err) |
| 3408 | return err; |
| 3409 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 3410 | wdev_lock(wdev); |
| 3411 | err = rdev_change_beacon(rdev, dev, ¶ms); |
| 3412 | wdev_unlock(wdev); |
| 3413 | |
| 3414 | return err; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3415 | } |
| 3416 | |
| 3417 | 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] | 3418 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3419 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3420 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3421 | |
Ilan Peer | 7c8d5e0 | 2014-02-25 15:33:38 +0200 | [diff] [blame] | 3422 | return cfg80211_stop_ap(rdev, dev, false); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3423 | } |
| 3424 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3425 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
| 3426 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, |
| 3427 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, |
| 3428 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, |
Jouni Malinen | 0e46724 | 2009-05-11 21:57:55 +0300 | [diff] [blame] | 3429 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 3430 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
Johannes Berg | d83023d | 2011-12-14 09:29:15 +0100 | [diff] [blame] | 3431 | [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3432 | }; |
| 3433 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3434 | static int parse_station_flags(struct genl_info *info, |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3435 | enum nl80211_iftype iftype, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3436 | struct station_parameters *params) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3437 | { |
| 3438 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3439 | struct nlattr *nla; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3440 | int flag; |
| 3441 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3442 | /* |
| 3443 | * Try parsing the new attribute first so userspace |
| 3444 | * can specify both for older kernels. |
| 3445 | */ |
| 3446 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; |
| 3447 | if (nla) { |
| 3448 | struct nl80211_sta_flag_update *sta_flags; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3449 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3450 | sta_flags = nla_data(nla); |
| 3451 | params->sta_flags_mask = sta_flags->mask; |
| 3452 | params->sta_flags_set = sta_flags->set; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3453 | params->sta_flags_set &= params->sta_flags_mask; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3454 | if ((params->sta_flags_mask | |
| 3455 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) |
| 3456 | return -EINVAL; |
| 3457 | return 0; |
| 3458 | } |
| 3459 | |
| 3460 | /* if present, parse the old attribute */ |
| 3461 | |
| 3462 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3463 | if (!nla) |
| 3464 | return 0; |
| 3465 | |
| 3466 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, |
| 3467 | nla, sta_flags_policy)) |
| 3468 | return -EINVAL; |
| 3469 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3470 | /* |
| 3471 | * Only allow certain flags for interface types so that |
| 3472 | * other attributes are silently ignored. Remember that |
| 3473 | * this is backward compatibility code with old userspace |
| 3474 | * and shouldn't be hit in other cases anyway. |
| 3475 | */ |
| 3476 | switch (iftype) { |
| 3477 | case NL80211_IFTYPE_AP: |
| 3478 | case NL80211_IFTYPE_AP_VLAN: |
| 3479 | case NL80211_IFTYPE_P2P_GO: |
| 3480 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3481 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 3482 | BIT(NL80211_STA_FLAG_WME) | |
| 3483 | BIT(NL80211_STA_FLAG_MFP); |
| 3484 | break; |
| 3485 | case NL80211_IFTYPE_P2P_CLIENT: |
| 3486 | case NL80211_IFTYPE_STATION: |
| 3487 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3488 | BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3489 | break; |
| 3490 | case NL80211_IFTYPE_MESH_POINT: |
| 3491 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3492 | BIT(NL80211_STA_FLAG_MFP) | |
| 3493 | BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 3494 | default: |
| 3495 | return -EINVAL; |
| 3496 | } |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3497 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 3498 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) { |
| 3499 | if (flags[flag]) { |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3500 | params->sta_flags_set |= (1<<flag); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3501 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 3502 | /* no longer support new API additions in old API */ |
| 3503 | if (flag > NL80211_STA_FLAG_MAX_OLD_API) |
| 3504 | return -EINVAL; |
| 3505 | } |
| 3506 | } |
| 3507 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3508 | return 0; |
| 3509 | } |
| 3510 | |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3511 | static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, |
| 3512 | int attr) |
| 3513 | { |
| 3514 | struct nlattr *rate; |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 3515 | u32 bitrate; |
| 3516 | u16 bitrate_compat; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3517 | |
| 3518 | rate = nla_nest_start(msg, attr); |
| 3519 | if (!rate) |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 3520 | return false; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3521 | |
| 3522 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ |
| 3523 | bitrate = cfg80211_calculate_bitrate(info); |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 3524 | /* report 16-bit bitrate only if we can */ |
| 3525 | bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 3526 | if (bitrate > 0 && |
| 3527 | nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate)) |
| 3528 | return false; |
| 3529 | if (bitrate_compat > 0 && |
| 3530 | nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat)) |
| 3531 | return false; |
| 3532 | |
| 3533 | if (info->flags & RATE_INFO_FLAGS_MCS) { |
| 3534 | if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) |
| 3535 | return false; |
| 3536 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && |
| 3537 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) |
| 3538 | return false; |
| 3539 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 3540 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 3541 | return false; |
| 3542 | } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) { |
| 3543 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs)) |
| 3544 | return false; |
| 3545 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss)) |
| 3546 | return false; |
| 3547 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && |
| 3548 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) |
| 3549 | return false; |
| 3550 | if (info->flags & RATE_INFO_FLAGS_80_MHZ_WIDTH && |
| 3551 | nla_put_flag(msg, NL80211_RATE_INFO_80_MHZ_WIDTH)) |
| 3552 | return false; |
| 3553 | if (info->flags & RATE_INFO_FLAGS_80P80_MHZ_WIDTH && |
| 3554 | nla_put_flag(msg, NL80211_RATE_INFO_80P80_MHZ_WIDTH)) |
| 3555 | return false; |
| 3556 | if (info->flags & RATE_INFO_FLAGS_160_MHZ_WIDTH && |
| 3557 | nla_put_flag(msg, NL80211_RATE_INFO_160_MHZ_WIDTH)) |
| 3558 | return false; |
| 3559 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 3560 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 3561 | return false; |
| 3562 | } |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3563 | |
| 3564 | nla_nest_end(msg, rate); |
| 3565 | return true; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3566 | } |
| 3567 | |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 3568 | static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal, |
| 3569 | int id) |
| 3570 | { |
| 3571 | void *attr; |
| 3572 | int i = 0; |
| 3573 | |
| 3574 | if (!mask) |
| 3575 | return true; |
| 3576 | |
| 3577 | attr = nla_nest_start(msg, id); |
| 3578 | if (!attr) |
| 3579 | return false; |
| 3580 | |
| 3581 | for (i = 0; i < IEEE80211_MAX_CHAINS; i++) { |
| 3582 | if (!(mask & BIT(i))) |
| 3583 | continue; |
| 3584 | |
| 3585 | if (nla_put_u8(msg, i, signal[i])) |
| 3586 | return false; |
| 3587 | } |
| 3588 | |
| 3589 | nla_nest_end(msg, attr); |
| 3590 | |
| 3591 | return true; |
| 3592 | } |
| 3593 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3594 | 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] | 3595 | int flags, |
| 3596 | struct cfg80211_registered_device *rdev, |
| 3597 | struct net_device *dev, |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 3598 | const u8 *mac_addr, struct station_info *sinfo) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3599 | { |
| 3600 | void *hdr; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3601 | struct nlattr *sinfoattr, *bss_param; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3602 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3603 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3604 | if (!hdr) |
| 3605 | return -1; |
| 3606 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3607 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 3608 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 3609 | nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation)) |
| 3610 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 3611 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3612 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
| 3613 | if (!sinfoattr) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3614 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3615 | if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) && |
| 3616 | nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME, |
| 3617 | sinfo->connected_time)) |
| 3618 | goto nla_put_failure; |
| 3619 | if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) && |
| 3620 | nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME, |
| 3621 | sinfo->inactive_time)) |
| 3622 | goto nla_put_failure; |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3623 | if ((sinfo->filled & (STATION_INFO_RX_BYTES | |
| 3624 | STATION_INFO_RX_BYTES64)) && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3625 | nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES, |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3626 | (u32)sinfo->rx_bytes)) |
| 3627 | goto nla_put_failure; |
| 3628 | if ((sinfo->filled & (STATION_INFO_TX_BYTES | |
Felix Fietkau | 4325d72 | 2013-05-23 15:05:59 +0200 | [diff] [blame] | 3629 | STATION_INFO_TX_BYTES64)) && |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3630 | nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES, |
| 3631 | (u32)sinfo->tx_bytes)) |
| 3632 | goto nla_put_failure; |
| 3633 | if ((sinfo->filled & STATION_INFO_RX_BYTES64) && |
| 3634 | nla_put_u64(msg, NL80211_STA_INFO_RX_BYTES64, |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3635 | sinfo->rx_bytes)) |
| 3636 | goto nla_put_failure; |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3637 | if ((sinfo->filled & STATION_INFO_TX_BYTES64) && |
| 3638 | nla_put_u64(msg, NL80211_STA_INFO_TX_BYTES64, |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3639 | sinfo->tx_bytes)) |
| 3640 | goto nla_put_failure; |
| 3641 | if ((sinfo->filled & STATION_INFO_LLID) && |
| 3642 | nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid)) |
| 3643 | goto nla_put_failure; |
| 3644 | if ((sinfo->filled & STATION_INFO_PLID) && |
| 3645 | nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid)) |
| 3646 | goto nla_put_failure; |
| 3647 | if ((sinfo->filled & STATION_INFO_PLINK_STATE) && |
| 3648 | nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE, |
| 3649 | sinfo->plink_state)) |
| 3650 | goto nla_put_failure; |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3651 | switch (rdev->wiphy.signal_type) { |
| 3652 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3653 | if ((sinfo->filled & STATION_INFO_SIGNAL) && |
| 3654 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL, |
| 3655 | sinfo->signal)) |
| 3656 | goto nla_put_failure; |
| 3657 | if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) && |
| 3658 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG, |
| 3659 | sinfo->signal_avg)) |
| 3660 | goto nla_put_failure; |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3661 | break; |
| 3662 | default: |
| 3663 | break; |
| 3664 | } |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 3665 | if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL) { |
| 3666 | if (!nl80211_put_signal(msg, sinfo->chains, |
| 3667 | sinfo->chain_signal, |
| 3668 | NL80211_STA_INFO_CHAIN_SIGNAL)) |
| 3669 | goto nla_put_failure; |
| 3670 | } |
| 3671 | if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL_AVG) { |
| 3672 | if (!nl80211_put_signal(msg, sinfo->chains, |
| 3673 | sinfo->chain_signal_avg, |
| 3674 | NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) |
| 3675 | goto nla_put_failure; |
| 3676 | } |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3677 | if (sinfo->filled & STATION_INFO_TX_BITRATE) { |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3678 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
| 3679 | NL80211_STA_INFO_TX_BITRATE)) |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3680 | goto nla_put_failure; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3681 | } |
| 3682 | if (sinfo->filled & STATION_INFO_RX_BITRATE) { |
| 3683 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, |
| 3684 | NL80211_STA_INFO_RX_BITRATE)) |
| 3685 | goto nla_put_failure; |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3686 | } |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3687 | if ((sinfo->filled & STATION_INFO_RX_PACKETS) && |
| 3688 | nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS, |
| 3689 | sinfo->rx_packets)) |
| 3690 | goto nla_put_failure; |
| 3691 | if ((sinfo->filled & STATION_INFO_TX_PACKETS) && |
| 3692 | nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS, |
| 3693 | sinfo->tx_packets)) |
| 3694 | goto nla_put_failure; |
| 3695 | if ((sinfo->filled & STATION_INFO_TX_RETRIES) && |
| 3696 | nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES, |
| 3697 | sinfo->tx_retries)) |
| 3698 | goto nla_put_failure; |
| 3699 | if ((sinfo->filled & STATION_INFO_TX_FAILED) && |
| 3700 | nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED, |
| 3701 | sinfo->tx_failed)) |
| 3702 | goto nla_put_failure; |
Antonio Quartulli | 867d849 | 2014-05-19 21:53:19 +0200 | [diff] [blame] | 3703 | if ((sinfo->filled & STATION_INFO_EXPECTED_THROUGHPUT) && |
| 3704 | nla_put_u32(msg, NL80211_STA_INFO_EXPECTED_THROUGHPUT, |
| 3705 | sinfo->expected_throughput)) |
| 3706 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3707 | if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) && |
| 3708 | nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS, |
| 3709 | sinfo->beacon_loss_count)) |
| 3710 | goto nla_put_failure; |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 3711 | if ((sinfo->filled & STATION_INFO_LOCAL_PM) && |
| 3712 | nla_put_u32(msg, NL80211_STA_INFO_LOCAL_PM, |
| 3713 | sinfo->local_pm)) |
| 3714 | goto nla_put_failure; |
| 3715 | if ((sinfo->filled & STATION_INFO_PEER_PM) && |
| 3716 | nla_put_u32(msg, NL80211_STA_INFO_PEER_PM, |
| 3717 | sinfo->peer_pm)) |
| 3718 | goto nla_put_failure; |
| 3719 | if ((sinfo->filled & STATION_INFO_NONPEER_PM) && |
| 3720 | nla_put_u32(msg, NL80211_STA_INFO_NONPEER_PM, |
| 3721 | sinfo->nonpeer_pm)) |
| 3722 | goto nla_put_failure; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3723 | if (sinfo->filled & STATION_INFO_BSS_PARAM) { |
| 3724 | bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); |
| 3725 | if (!bss_param) |
| 3726 | goto nla_put_failure; |
| 3727 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3728 | if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) && |
| 3729 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) || |
| 3730 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) && |
| 3731 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) || |
| 3732 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) && |
| 3733 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) || |
| 3734 | nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, |
| 3735 | sinfo->bss_param.dtim_period) || |
| 3736 | nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, |
| 3737 | sinfo->bss_param.beacon_interval)) |
| 3738 | goto nla_put_failure; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3739 | |
| 3740 | nla_nest_end(msg, bss_param); |
| 3741 | } |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3742 | if ((sinfo->filled & STATION_INFO_STA_FLAGS) && |
| 3743 | nla_put(msg, NL80211_STA_INFO_STA_FLAGS, |
| 3744 | sizeof(struct nl80211_sta_flag_update), |
| 3745 | &sinfo->sta_flags)) |
| 3746 | goto nla_put_failure; |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 3747 | if ((sinfo->filled & STATION_INFO_T_OFFSET) && |
| 3748 | nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET, |
| 3749 | sinfo->t_offset)) |
| 3750 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3751 | nla_nest_end(msg, sinfoattr); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3752 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3753 | if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) && |
| 3754 | nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, |
| 3755 | sinfo->assoc_req_ies)) |
| 3756 | goto nla_put_failure; |
Jouni Malinen | 50d3dfb | 2011-08-08 12:11:52 +0300 | [diff] [blame] | 3757 | |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3758 | return genlmsg_end(msg, hdr); |
| 3759 | |
| 3760 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 3761 | genlmsg_cancel(msg, hdr); |
| 3762 | return -EMSGSIZE; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3763 | } |
| 3764 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3765 | static int nl80211_dump_station(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3766 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3767 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3768 | struct station_info sinfo; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 3769 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3770 | struct wireless_dev *wdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3771 | u8 mac_addr[ETH_ALEN]; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3772 | int sta_idx = cb->args[2]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3773 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3774 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 3775 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3776 | if (err) |
| 3777 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3778 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3779 | if (!wdev->netdev) { |
| 3780 | err = -EINVAL; |
| 3781 | goto out_err; |
| 3782 | } |
| 3783 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 3784 | if (!rdev->ops->dump_station) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3785 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3786 | goto out_err; |
| 3787 | } |
| 3788 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3789 | while (1) { |
Jouni Malinen | f612ced | 2011-08-11 11:46:22 +0300 | [diff] [blame] | 3790 | memset(&sinfo, 0, sizeof(sinfo)); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 3791 | err = rdev_dump_station(rdev, wdev->netdev, sta_idx, |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3792 | mac_addr, &sinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3793 | if (err == -ENOENT) |
| 3794 | break; |
| 3795 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3796 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3797 | |
| 3798 | if (nl80211_send_station(skb, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3799 | NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3800 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 3801 | rdev, wdev->netdev, mac_addr, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3802 | &sinfo) < 0) |
| 3803 | goto out; |
| 3804 | |
| 3805 | sta_idx++; |
| 3806 | } |
| 3807 | |
| 3808 | |
| 3809 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3810 | cb->args[2] = sta_idx; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3811 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3812 | out_err: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 3813 | nl80211_finish_wdev_dump(rdev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3814 | |
| 3815 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3816 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3817 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3818 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
| 3819 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3820 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3821 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3822 | struct station_info sinfo; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3823 | struct sk_buff *msg; |
| 3824 | u8 *mac_addr = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3825 | int err; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3826 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3827 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3828 | |
| 3829 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3830 | return -EINVAL; |
| 3831 | |
| 3832 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3833 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3834 | if (!rdev->ops->get_station) |
| 3835 | return -EOPNOTSUPP; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3836 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3837 | err = rdev_get_station(rdev, dev, mac_addr, &sinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3838 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3839 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3840 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3841 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3842 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3843 | return -ENOMEM; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3844 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3845 | 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] | 3846 | rdev, dev, mac_addr, &sinfo) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3847 | nlmsg_free(msg); |
| 3848 | return -ENOBUFS; |
| 3849 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3850 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3851 | return genlmsg_reply(msg, info); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3852 | } |
| 3853 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3854 | int cfg80211_check_station_change(struct wiphy *wiphy, |
| 3855 | struct station_parameters *params, |
| 3856 | enum cfg80211_station_type statype) |
| 3857 | { |
| 3858 | if (params->listen_interval != -1) |
| 3859 | return -EINVAL; |
Arik Nemtsov | c72e114 | 2014-07-17 17:14:29 +0300 | [diff] [blame] | 3860 | if (params->aid && |
| 3861 | !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3862 | return -EINVAL; |
| 3863 | |
| 3864 | /* When you run into this, adjust the code below for the new flag */ |
| 3865 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); |
| 3866 | |
| 3867 | switch (statype) { |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 3868 | case CFG80211_STA_MESH_PEER_KERNEL: |
| 3869 | case CFG80211_STA_MESH_PEER_USER: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3870 | /* |
| 3871 | * No ignoring the TDLS flag here -- the userspace mesh |
| 3872 | * code doesn't have the bug of including TDLS in the |
| 3873 | * mask everywhere. |
| 3874 | */ |
| 3875 | if (params->sta_flags_mask & |
| 3876 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3877 | BIT(NL80211_STA_FLAG_MFP) | |
| 3878 | BIT(NL80211_STA_FLAG_AUTHORIZED))) |
| 3879 | return -EINVAL; |
| 3880 | break; |
| 3881 | case CFG80211_STA_TDLS_PEER_SETUP: |
| 3882 | case CFG80211_STA_TDLS_PEER_ACTIVE: |
| 3883 | if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 3884 | return -EINVAL; |
| 3885 | /* ignore since it can't change */ |
| 3886 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3887 | break; |
| 3888 | default: |
| 3889 | /* disallow mesh-specific things */ |
| 3890 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) |
| 3891 | return -EINVAL; |
| 3892 | if (params->local_pm) |
| 3893 | return -EINVAL; |
| 3894 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
| 3895 | return -EINVAL; |
| 3896 | } |
| 3897 | |
| 3898 | if (statype != CFG80211_STA_TDLS_PEER_SETUP && |
| 3899 | statype != CFG80211_STA_TDLS_PEER_ACTIVE) { |
| 3900 | /* TDLS can't be set, ... */ |
| 3901 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
| 3902 | return -EINVAL; |
| 3903 | /* |
| 3904 | * ... but don't bother the driver with it. This works around |
| 3905 | * a hostapd/wpa_supplicant issue -- it always includes the |
| 3906 | * TLDS_PEER flag in the mask even for AP mode. |
| 3907 | */ |
| 3908 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3909 | } |
| 3910 | |
| 3911 | if (statype != CFG80211_STA_TDLS_PEER_SETUP) { |
| 3912 | /* reject other things that can't change */ |
| 3913 | if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) |
| 3914 | return -EINVAL; |
| 3915 | if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY) |
| 3916 | return -EINVAL; |
| 3917 | if (params->supported_rates) |
| 3918 | return -EINVAL; |
| 3919 | if (params->ext_capab || params->ht_capa || params->vht_capa) |
| 3920 | return -EINVAL; |
| 3921 | } |
| 3922 | |
| 3923 | if (statype != CFG80211_STA_AP_CLIENT) { |
| 3924 | if (params->vlan) |
| 3925 | return -EINVAL; |
| 3926 | } |
| 3927 | |
| 3928 | switch (statype) { |
| 3929 | case CFG80211_STA_AP_MLME_CLIENT: |
| 3930 | /* Use this only for authorizing/unauthorizing a station */ |
| 3931 | if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))) |
| 3932 | return -EOPNOTSUPP; |
| 3933 | break; |
| 3934 | case CFG80211_STA_AP_CLIENT: |
| 3935 | /* accept only the listed bits */ |
| 3936 | if (params->sta_flags_mask & |
| 3937 | ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3938 | BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3939 | BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 3940 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 3941 | BIT(NL80211_STA_FLAG_WME) | |
| 3942 | BIT(NL80211_STA_FLAG_MFP))) |
| 3943 | return -EINVAL; |
| 3944 | |
| 3945 | /* but authenticated/associated only if driver handles it */ |
| 3946 | if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
| 3947 | params->sta_flags_mask & |
| 3948 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3949 | BIT(NL80211_STA_FLAG_ASSOCIATED))) |
| 3950 | return -EINVAL; |
| 3951 | break; |
| 3952 | case CFG80211_STA_IBSS: |
| 3953 | case CFG80211_STA_AP_STA: |
| 3954 | /* reject any changes other than AUTHORIZED */ |
| 3955 | if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) |
| 3956 | return -EINVAL; |
| 3957 | break; |
| 3958 | case CFG80211_STA_TDLS_PEER_SETUP: |
| 3959 | /* reject any changes other than AUTHORIZED or WME */ |
| 3960 | if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3961 | BIT(NL80211_STA_FLAG_WME))) |
| 3962 | return -EINVAL; |
| 3963 | /* force (at least) rates when authorizing */ |
| 3964 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) && |
| 3965 | !params->supported_rates) |
| 3966 | return -EINVAL; |
| 3967 | break; |
| 3968 | case CFG80211_STA_TDLS_PEER_ACTIVE: |
| 3969 | /* reject any changes */ |
| 3970 | return -EINVAL; |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 3971 | case CFG80211_STA_MESH_PEER_KERNEL: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3972 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
| 3973 | return -EINVAL; |
| 3974 | break; |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 3975 | case CFG80211_STA_MESH_PEER_USER: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3976 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) |
| 3977 | return -EINVAL; |
| 3978 | break; |
| 3979 | } |
| 3980 | |
| 3981 | return 0; |
| 3982 | } |
| 3983 | EXPORT_SYMBOL(cfg80211_check_station_change); |
| 3984 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3985 | /* |
Felix Fietkau | c258d2d | 2009-11-11 17:23:31 +0100 | [diff] [blame] | 3986 | * 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] | 3987 | */ |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3988 | static struct net_device *get_vlan(struct genl_info *info, |
| 3989 | struct cfg80211_registered_device *rdev) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3990 | { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3991 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3992 | struct net_device *v; |
| 3993 | int ret; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3994 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3995 | if (!vlanattr) |
| 3996 | return NULL; |
| 3997 | |
| 3998 | v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); |
| 3999 | if (!v) |
| 4000 | return ERR_PTR(-ENODEV); |
| 4001 | |
| 4002 | if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { |
| 4003 | ret = -EINVAL; |
| 4004 | goto error; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4005 | } |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 4006 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4007 | if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
| 4008 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 4009 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { |
| 4010 | ret = -EINVAL; |
| 4011 | goto error; |
| 4012 | } |
| 4013 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 4014 | if (!netif_running(v)) { |
| 4015 | ret = -ENETDOWN; |
| 4016 | goto error; |
| 4017 | } |
| 4018 | |
| 4019 | return v; |
| 4020 | error: |
| 4021 | dev_put(v); |
| 4022 | return ERR_PTR(ret); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4023 | } |
| 4024 | |
Johannes Berg | 94e860f | 2014-01-20 23:58:15 +0100 | [diff] [blame] | 4025 | static const struct nla_policy |
| 4026 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = { |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 4027 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, |
| 4028 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, |
| 4029 | }; |
| 4030 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4031 | static int nl80211_parse_sta_wme(struct genl_info *info, |
| 4032 | struct station_parameters *params) |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 4033 | { |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 4034 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; |
| 4035 | struct nlattr *nla; |
| 4036 | int err; |
| 4037 | |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 4038 | /* parse WME attributes if present */ |
| 4039 | if (!info->attrs[NL80211_ATTR_STA_WME]) |
| 4040 | return 0; |
| 4041 | |
| 4042 | nla = info->attrs[NL80211_ATTR_STA_WME]; |
| 4043 | err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla, |
| 4044 | nl80211_sta_wme_policy); |
| 4045 | if (err) |
| 4046 | return err; |
| 4047 | |
| 4048 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) |
| 4049 | params->uapsd_queues = nla_get_u8( |
| 4050 | tb[NL80211_STA_WME_UAPSD_QUEUES]); |
| 4051 | if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) |
| 4052 | return -EINVAL; |
| 4053 | |
| 4054 | if (tb[NL80211_STA_WME_MAX_SP]) |
| 4055 | params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); |
| 4056 | |
| 4057 | if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) |
| 4058 | return -EINVAL; |
| 4059 | |
| 4060 | params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; |
| 4061 | |
| 4062 | return 0; |
| 4063 | } |
| 4064 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 4065 | static int nl80211_parse_sta_channel_info(struct genl_info *info, |
| 4066 | struct station_parameters *params) |
| 4067 | { |
| 4068 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) { |
| 4069 | params->supported_channels = |
| 4070 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); |
| 4071 | params->supported_channels_len = |
| 4072 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); |
| 4073 | /* |
| 4074 | * Need to include at least one (first channel, number of |
| 4075 | * channels) tuple for each subband, and must have proper |
| 4076 | * tuples for the rest of the data as well. |
| 4077 | */ |
| 4078 | if (params->supported_channels_len < 2) |
| 4079 | return -EINVAL; |
| 4080 | if (params->supported_channels_len % 2) |
| 4081 | return -EINVAL; |
| 4082 | } |
| 4083 | |
| 4084 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) { |
| 4085 | params->supported_oper_classes = |
| 4086 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); |
| 4087 | params->supported_oper_classes_len = |
| 4088 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); |
| 4089 | /* |
| 4090 | * The value of the Length field of the Supported Operating |
| 4091 | * Classes element is between 2 and 253. |
| 4092 | */ |
| 4093 | if (params->supported_oper_classes_len < 2 || |
| 4094 | params->supported_oper_classes_len > 253) |
| 4095 | return -EINVAL; |
| 4096 | } |
| 4097 | return 0; |
| 4098 | } |
| 4099 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4100 | static int nl80211_set_station_tdls(struct genl_info *info, |
| 4101 | struct station_parameters *params) |
| 4102 | { |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 4103 | int err; |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4104 | /* Dummy STA entry gets updated once the peer capabilities are known */ |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 4105 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
| 4106 | params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4107 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 4108 | params->ht_capa = |
| 4109 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
| 4110 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 4111 | params->vht_capa = |
| 4112 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 4113 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 4114 | err = nl80211_parse_sta_channel_info(info, params); |
| 4115 | if (err) |
| 4116 | return err; |
| 4117 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4118 | return nl80211_parse_sta_wme(info, params); |
| 4119 | } |
| 4120 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4121 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
| 4122 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4123 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4124 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4125 | struct station_parameters params; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4126 | u8 *mac_addr; |
| 4127 | int err; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4128 | |
| 4129 | memset(¶ms, 0, sizeof(params)); |
| 4130 | |
| 4131 | params.listen_interval = -1; |
| 4132 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4133 | if (!rdev->ops->change_station) |
| 4134 | return -EOPNOTSUPP; |
| 4135 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4136 | if (info->attrs[NL80211_ATTR_STA_AID]) |
| 4137 | return -EINVAL; |
| 4138 | |
| 4139 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4140 | return -EINVAL; |
| 4141 | |
| 4142 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4143 | |
| 4144 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { |
| 4145 | params.supported_rates = |
| 4146 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4147 | params.supported_rates_len = |
| 4148 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4149 | } |
| 4150 | |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 4151 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
| 4152 | params.capability = |
| 4153 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); |
| 4154 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; |
| 4155 | } |
| 4156 | |
| 4157 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { |
| 4158 | params.ext_capab = |
| 4159 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4160 | params.ext_capab_len = |
| 4161 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4162 | } |
| 4163 | |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 4164 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
Johannes Berg | ba23d20 | 2012-12-27 17:32:09 +0100 | [diff] [blame] | 4165 | return -EINVAL; |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 4166 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 4167 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4168 | return -EINVAL; |
| 4169 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4170 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4171 | params.plink_action = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4172 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 4173 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) |
| 4174 | return -EINVAL; |
| 4175 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4176 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4177 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) { |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 4178 | params.plink_state = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4179 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
| 4180 | if (params.plink_state >= NUM_NL80211_PLINK_STATES) |
| 4181 | return -EINVAL; |
| 4182 | params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE; |
| 4183 | } |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 4184 | |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4185 | if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) { |
| 4186 | enum nl80211_mesh_power_mode pm = nla_get_u32( |
| 4187 | info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]); |
| 4188 | |
| 4189 | if (pm <= NL80211_MESH_POWER_UNKNOWN || |
| 4190 | pm > NL80211_MESH_POWER_MAX) |
| 4191 | return -EINVAL; |
| 4192 | |
| 4193 | params.local_pm = pm; |
| 4194 | } |
| 4195 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4196 | /* Include parameters for TDLS peer (will check later) */ |
| 4197 | err = nl80211_set_station_tdls(info, ¶ms); |
| 4198 | if (err) |
| 4199 | return err; |
| 4200 | |
| 4201 | params.vlan = get_vlan(info, rdev); |
| 4202 | if (IS_ERR(params.vlan)) |
| 4203 | return PTR_ERR(params.vlan); |
| 4204 | |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4205 | switch (dev->ieee80211_ptr->iftype) { |
| 4206 | case NL80211_IFTYPE_AP: |
| 4207 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4208 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4209 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4210 | case NL80211_IFTYPE_STATION: |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 4211 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4212 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4213 | break; |
| 4214 | default: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4215 | err = -EOPNOTSUPP; |
| 4216 | goto out_put_vlan; |
Johannes Berg | 034d655 | 2009-05-27 10:35:29 +0200 | [diff] [blame] | 4217 | } |
| 4218 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4219 | /* driver will call cfg80211_check_station_change() */ |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4220 | err = rdev_change_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4221 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4222 | out_put_vlan: |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4223 | if (params.vlan) |
| 4224 | dev_put(params.vlan); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4225 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4226 | return err; |
| 4227 | } |
| 4228 | |
| 4229 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) |
| 4230 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4231 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4232 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4233 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4234 | struct station_parameters params; |
| 4235 | u8 *mac_addr = NULL; |
| 4236 | |
| 4237 | memset(¶ms, 0, sizeof(params)); |
| 4238 | |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4239 | if (!rdev->ops->add_station) |
| 4240 | return -EOPNOTSUPP; |
| 4241 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4242 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4243 | return -EINVAL; |
| 4244 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4245 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 4246 | return -EINVAL; |
| 4247 | |
| 4248 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) |
| 4249 | return -EINVAL; |
| 4250 | |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 4251 | if (!info->attrs[NL80211_ATTR_STA_AID] && |
| 4252 | !info->attrs[NL80211_ATTR_PEER_AID]) |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 4253 | return -EINVAL; |
| 4254 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4255 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4256 | params.supported_rates = |
| 4257 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4258 | params.supported_rates_len = |
| 4259 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4260 | params.listen_interval = |
| 4261 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 4262 | |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4263 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 4264 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4265 | else |
| 4266 | 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] | 4267 | if (!params.aid || params.aid > IEEE80211_MAX_AID) |
| 4268 | return -EINVAL; |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 4269 | |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 4270 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
| 4271 | params.capability = |
| 4272 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); |
| 4273 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; |
| 4274 | } |
| 4275 | |
| 4276 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { |
| 4277 | params.ext_capab = |
| 4278 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4279 | params.ext_capab_len = |
| 4280 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4281 | } |
| 4282 | |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 4283 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 4284 | params.ht_capa = |
| 4285 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4286 | |
Mahesh Palivela | f461be3e | 2012-10-11 08:04:52 +0000 | [diff] [blame] | 4287 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 4288 | params.vht_capa = |
| 4289 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 4290 | |
Marek Kwaczynski | 60f4a7b | 2013-12-03 10:04:59 +0100 | [diff] [blame] | 4291 | if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) { |
| 4292 | params.opmode_notif_used = true; |
| 4293 | params.opmode_notif = |
| 4294 | nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]); |
| 4295 | } |
| 4296 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4297 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 4298 | params.plink_action = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4299 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 4300 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) |
| 4301 | return -EINVAL; |
| 4302 | } |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 4303 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 4304 | err = nl80211_parse_sta_channel_info(info, ¶ms); |
| 4305 | if (err) |
| 4306 | return err; |
| 4307 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4308 | err = nl80211_parse_sta_wme(info, ¶ms); |
| 4309 | if (err) |
| 4310 | return err; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4311 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 4312 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4313 | return -EINVAL; |
| 4314 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4315 | /* When you run into this, adjust the code below for the new flag */ |
| 4316 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); |
| 4317 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4318 | switch (dev->ieee80211_ptr->iftype) { |
| 4319 | case NL80211_IFTYPE_AP: |
| 4320 | case NL80211_IFTYPE_AP_VLAN: |
| 4321 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4322 | /* ignore WME attributes if iface/sta is not capable */ |
| 4323 | if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) || |
| 4324 | !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) |
| 4325 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4326 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4327 | /* TDLS peers cannot be added */ |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4328 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
| 4329 | info->attrs[NL80211_ATTR_PEER_AID]) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 4330 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4331 | /* but don't bother the driver with it */ |
| 4332 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4333 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4334 | /* allow authenticated/associated only if driver handles it */ |
| 4335 | if (!(rdev->wiphy.features & |
| 4336 | NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
| 4337 | params.sta_flags_mask & |
| 4338 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 4339 | BIT(NL80211_STA_FLAG_ASSOCIATED))) |
| 4340 | return -EINVAL; |
| 4341 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4342 | /* must be last in here for error handling */ |
| 4343 | params.vlan = get_vlan(info, rdev); |
| 4344 | if (IS_ERR(params.vlan)) |
| 4345 | return PTR_ERR(params.vlan); |
| 4346 | break; |
| 4347 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4348 | /* ignore uAPSD data */ |
| 4349 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
| 4350 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4351 | /* associated is disallowed */ |
| 4352 | if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) |
| 4353 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4354 | /* TDLS peers cannot be added */ |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4355 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
| 4356 | info->attrs[NL80211_ATTR_PEER_AID]) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 4357 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4358 | break; |
| 4359 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 93d08f0 | 2013-03-04 09:29:46 +0100 | [diff] [blame] | 4360 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4361 | /* ignore uAPSD data */ |
| 4362 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
| 4363 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4364 | /* these are disallowed */ |
| 4365 | if (params.sta_flags_mask & |
| 4366 | (BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 4367 | BIT(NL80211_STA_FLAG_AUTHENTICATED))) |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4368 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4369 | /* Only TDLS peers can be added */ |
| 4370 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 4371 | return -EINVAL; |
| 4372 | /* Can only add if TDLS ... */ |
| 4373 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) |
| 4374 | return -EOPNOTSUPP; |
| 4375 | /* ... with external setup is supported */ |
| 4376 | if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) |
| 4377 | return -EOPNOTSUPP; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4378 | /* |
| 4379 | * Older wpa_supplicant versions always mark the TDLS peer |
| 4380 | * as authorized, but it shouldn't yet be. |
| 4381 | */ |
| 4382 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED); |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4383 | break; |
| 4384 | default: |
| 4385 | return -EOPNOTSUPP; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4386 | } |
| 4387 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4388 | /* be aware of params.vlan when changing code here */ |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4389 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4390 | err = rdev_add_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4391 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4392 | if (params.vlan) |
| 4393 | dev_put(params.vlan); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4394 | return err; |
| 4395 | } |
| 4396 | |
| 4397 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) |
| 4398 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4399 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4400 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 89c771e | 2014-10-10 20:52:40 +0300 | [diff] [blame^] | 4401 | struct station_del_parameters params; |
| 4402 | |
| 4403 | memset(¶ms, 0, sizeof(params)); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4404 | |
| 4405 | if (info->attrs[NL80211_ATTR_MAC]) |
Jouni Malinen | 89c771e | 2014-10-10 20:52:40 +0300 | [diff] [blame^] | 4406 | params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4407 | |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 4408 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Marco Porsch | d5d9de0 | 2010-03-30 10:00:16 +0200 | [diff] [blame] | 4409 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4410 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4411 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4412 | return -EINVAL; |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 4413 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4414 | if (!rdev->ops->del_station) |
| 4415 | return -EOPNOTSUPP; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4416 | |
Jouni Malinen | 89c771e | 2014-10-10 20:52:40 +0300 | [diff] [blame^] | 4417 | return rdev_del_station(rdev, dev, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4418 | } |
| 4419 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4420 | 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] | 4421 | int flags, struct net_device *dev, |
| 4422 | u8 *dst, u8 *next_hop, |
| 4423 | struct mpath_info *pinfo) |
| 4424 | { |
| 4425 | void *hdr; |
| 4426 | struct nlattr *pinfoattr; |
| 4427 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4428 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4429 | if (!hdr) |
| 4430 | return -1; |
| 4431 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4432 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 4433 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || |
| 4434 | nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) || |
| 4435 | nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation)) |
| 4436 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 4437 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4438 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
| 4439 | if (!pinfoattr) |
| 4440 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4441 | if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) && |
| 4442 | nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN, |
| 4443 | pinfo->frame_qlen)) |
| 4444 | goto nla_put_failure; |
| 4445 | if (((pinfo->filled & MPATH_INFO_SN) && |
| 4446 | nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) || |
| 4447 | ((pinfo->filled & MPATH_INFO_METRIC) && |
| 4448 | nla_put_u32(msg, NL80211_MPATH_INFO_METRIC, |
| 4449 | pinfo->metric)) || |
| 4450 | ((pinfo->filled & MPATH_INFO_EXPTIME) && |
| 4451 | nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME, |
| 4452 | pinfo->exptime)) || |
| 4453 | ((pinfo->filled & MPATH_INFO_FLAGS) && |
| 4454 | nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS, |
| 4455 | pinfo->flags)) || |
| 4456 | ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) && |
| 4457 | nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, |
| 4458 | pinfo->discovery_timeout)) || |
| 4459 | ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) && |
| 4460 | nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, |
| 4461 | pinfo->discovery_retries))) |
| 4462 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4463 | |
| 4464 | nla_nest_end(msg, pinfoattr); |
| 4465 | |
| 4466 | return genlmsg_end(msg, hdr); |
| 4467 | |
| 4468 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 4469 | genlmsg_cancel(msg, hdr); |
| 4470 | return -EMSGSIZE; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4471 | } |
| 4472 | |
| 4473 | static int nl80211_dump_mpath(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4474 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4475 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4476 | struct mpath_info pinfo; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4477 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4478 | struct wireless_dev *wdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4479 | u8 dst[ETH_ALEN]; |
| 4480 | u8 next_hop[ETH_ALEN]; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4481 | int path_idx = cb->args[2]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4482 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4483 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4484 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4485 | if (err) |
| 4486 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4487 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4488 | if (!rdev->ops->dump_mpath) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4489 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4490 | goto out_err; |
| 4491 | } |
| 4492 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4493 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4494 | err = -EOPNOTSUPP; |
Roel Kluin | 0448b5f | 2009-08-22 21:15:49 +0200 | [diff] [blame] | 4495 | goto out_err; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4496 | } |
| 4497 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4498 | while (1) { |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4499 | err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4500 | next_hop, &pinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4501 | if (err == -ENOENT) |
| 4502 | break; |
| 4503 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4504 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4505 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4506 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4507 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4508 | wdev->netdev, dst, next_hop, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4509 | &pinfo) < 0) |
| 4510 | goto out; |
| 4511 | |
| 4512 | path_idx++; |
| 4513 | } |
| 4514 | |
| 4515 | |
| 4516 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4517 | cb->args[2] = path_idx; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4518 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4519 | out_err: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4520 | nl80211_finish_wdev_dump(rdev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4521 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4522 | } |
| 4523 | |
| 4524 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4525 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4526 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4527 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4528 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4529 | struct mpath_info pinfo; |
| 4530 | struct sk_buff *msg; |
| 4531 | u8 *dst = NULL; |
| 4532 | u8 next_hop[ETH_ALEN]; |
| 4533 | |
| 4534 | memset(&pinfo, 0, sizeof(pinfo)); |
| 4535 | |
| 4536 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4537 | return -EINVAL; |
| 4538 | |
| 4539 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4540 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4541 | if (!rdev->ops->get_mpath) |
| 4542 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4543 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4544 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4545 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4546 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4547 | err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4548 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4549 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4550 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4551 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4552 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4553 | return -ENOMEM; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4554 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4555 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4556 | dev, dst, next_hop, &pinfo) < 0) { |
| 4557 | nlmsg_free(msg); |
| 4558 | return -ENOBUFS; |
| 4559 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4560 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4561 | return genlmsg_reply(msg, info); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4562 | } |
| 4563 | |
| 4564 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4565 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4566 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4567 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4568 | u8 *dst = NULL; |
| 4569 | u8 *next_hop = NULL; |
| 4570 | |
| 4571 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4572 | return -EINVAL; |
| 4573 | |
| 4574 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 4575 | return -EINVAL; |
| 4576 | |
| 4577 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4578 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 4579 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4580 | if (!rdev->ops->change_mpath) |
| 4581 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4582 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4583 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4584 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4585 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4586 | return rdev_change_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4587 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4588 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4589 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4590 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4591 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4592 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4593 | u8 *dst = NULL; |
| 4594 | u8 *next_hop = NULL; |
| 4595 | |
| 4596 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4597 | return -EINVAL; |
| 4598 | |
| 4599 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 4600 | return -EINVAL; |
| 4601 | |
| 4602 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4603 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 4604 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4605 | if (!rdev->ops->add_mpath) |
| 4606 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4607 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4608 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4609 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4610 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4611 | return rdev_add_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4612 | } |
| 4613 | |
| 4614 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4615 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4616 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4617 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4618 | u8 *dst = NULL; |
| 4619 | |
| 4620 | if (info->attrs[NL80211_ATTR_MAC]) |
| 4621 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4622 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4623 | if (!rdev->ops->del_mpath) |
| 4624 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4625 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4626 | return rdev_del_mpath(rdev, dev, dst); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4627 | } |
| 4628 | |
Henning Rogge | 66be7d2 | 2014-09-12 08:58:49 +0200 | [diff] [blame] | 4629 | static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info) |
| 4630 | { |
| 4631 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4632 | int err; |
| 4633 | struct net_device *dev = info->user_ptr[1]; |
| 4634 | struct mpath_info pinfo; |
| 4635 | struct sk_buff *msg; |
| 4636 | u8 *dst = NULL; |
| 4637 | u8 mpp[ETH_ALEN]; |
| 4638 | |
| 4639 | memset(&pinfo, 0, sizeof(pinfo)); |
| 4640 | |
| 4641 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4642 | return -EINVAL; |
| 4643 | |
| 4644 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4645 | |
| 4646 | if (!rdev->ops->get_mpp) |
| 4647 | return -EOPNOTSUPP; |
| 4648 | |
| 4649 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4650 | return -EOPNOTSUPP; |
| 4651 | |
| 4652 | err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo); |
| 4653 | if (err) |
| 4654 | return err; |
| 4655 | |
| 4656 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 4657 | if (!msg) |
| 4658 | return -ENOMEM; |
| 4659 | |
| 4660 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
| 4661 | dev, dst, mpp, &pinfo) < 0) { |
| 4662 | nlmsg_free(msg); |
| 4663 | return -ENOBUFS; |
| 4664 | } |
| 4665 | |
| 4666 | return genlmsg_reply(msg, info); |
| 4667 | } |
| 4668 | |
| 4669 | static int nl80211_dump_mpp(struct sk_buff *skb, |
| 4670 | struct netlink_callback *cb) |
| 4671 | { |
| 4672 | struct mpath_info pinfo; |
| 4673 | struct cfg80211_registered_device *rdev; |
| 4674 | struct wireless_dev *wdev; |
| 4675 | u8 dst[ETH_ALEN]; |
| 4676 | u8 mpp[ETH_ALEN]; |
| 4677 | int path_idx = cb->args[2]; |
| 4678 | int err; |
| 4679 | |
| 4680 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
| 4681 | if (err) |
| 4682 | return err; |
| 4683 | |
| 4684 | if (!rdev->ops->dump_mpp) { |
| 4685 | err = -EOPNOTSUPP; |
| 4686 | goto out_err; |
| 4687 | } |
| 4688 | |
| 4689 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { |
| 4690 | err = -EOPNOTSUPP; |
| 4691 | goto out_err; |
| 4692 | } |
| 4693 | |
| 4694 | while (1) { |
| 4695 | err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst, |
| 4696 | mpp, &pinfo); |
| 4697 | if (err == -ENOENT) |
| 4698 | break; |
| 4699 | if (err) |
| 4700 | goto out_err; |
| 4701 | |
| 4702 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
| 4703 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 4704 | wdev->netdev, dst, mpp, |
| 4705 | &pinfo) < 0) |
| 4706 | goto out; |
| 4707 | |
| 4708 | path_idx++; |
| 4709 | } |
| 4710 | |
| 4711 | out: |
| 4712 | cb->args[2] = path_idx; |
| 4713 | err = skb->len; |
| 4714 | out_err: |
| 4715 | nl80211_finish_wdev_dump(rdev); |
| 4716 | return err; |
| 4717 | } |
| 4718 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4719 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
| 4720 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4721 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4722 | struct net_device *dev = info->user_ptr[1]; |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 4723 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4724 | struct bss_parameters params; |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 4725 | int err; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4726 | |
| 4727 | memset(¶ms, 0, sizeof(params)); |
| 4728 | /* default to not changing parameters */ |
| 4729 | params.use_cts_prot = -1; |
| 4730 | params.use_short_preamble = -1; |
| 4731 | params.use_short_slot_time = -1; |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 4732 | params.ap_isolate = -1; |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 4733 | params.ht_opmode = -1; |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 4734 | params.p2p_ctwindow = -1; |
| 4735 | params.p2p_opp_ps = -1; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4736 | |
| 4737 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) |
| 4738 | params.use_cts_prot = |
| 4739 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); |
| 4740 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) |
| 4741 | params.use_short_preamble = |
| 4742 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); |
| 4743 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) |
| 4744 | params.use_short_slot_time = |
| 4745 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 4746 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 4747 | params.basic_rates = |
| 4748 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 4749 | params.basic_rates_len = |
| 4750 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 4751 | } |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 4752 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
| 4753 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 4754 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
| 4755 | params.ht_opmode = |
| 4756 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4757 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 4758 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 4759 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4760 | return -EINVAL; |
| 4761 | params.p2p_ctwindow = |
| 4762 | nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
| 4763 | if (params.p2p_ctwindow < 0) |
| 4764 | return -EINVAL; |
| 4765 | if (params.p2p_ctwindow != 0 && |
| 4766 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 4767 | return -EINVAL; |
| 4768 | } |
| 4769 | |
| 4770 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 4771 | u8 tmp; |
| 4772 | |
| 4773 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4774 | return -EINVAL; |
| 4775 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
| 4776 | if (tmp > 1) |
| 4777 | return -EINVAL; |
| 4778 | params.p2p_opp_ps = tmp; |
| 4779 | if (params.p2p_opp_ps && |
| 4780 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 4781 | return -EINVAL; |
| 4782 | } |
| 4783 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4784 | if (!rdev->ops->change_bss) |
| 4785 | return -EOPNOTSUPP; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4786 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4787 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4788 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4789 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4790 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 4791 | wdev_lock(wdev); |
| 4792 | err = rdev_change_bss(rdev, dev, ¶ms); |
| 4793 | wdev_unlock(wdev); |
| 4794 | |
| 4795 | return err; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4796 | } |
| 4797 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 4798 | 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] | 4799 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
| 4800 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, |
| 4801 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, |
| 4802 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, |
| 4803 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, |
| 4804 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, |
Janusz Dziedzic | 089027e | 2014-02-21 19:46:12 +0100 | [diff] [blame] | 4805 | [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 }, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4806 | }; |
| 4807 | |
| 4808 | static int parse_reg_rule(struct nlattr *tb[], |
| 4809 | struct ieee80211_reg_rule *reg_rule) |
| 4810 | { |
| 4811 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; |
| 4812 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; |
| 4813 | |
| 4814 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) |
| 4815 | return -EINVAL; |
| 4816 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) |
| 4817 | return -EINVAL; |
| 4818 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) |
| 4819 | return -EINVAL; |
Janusz Dziedzic | b0dfd2e | 2014-02-20 13:52:16 +0100 | [diff] [blame] | 4820 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) |
| 4821 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4822 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) |
| 4823 | return -EINVAL; |
| 4824 | |
| 4825 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); |
| 4826 | |
| 4827 | freq_range->start_freq_khz = |
| 4828 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); |
| 4829 | freq_range->end_freq_khz = |
| 4830 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); |
Janusz Dziedzic | b0dfd2e | 2014-02-20 13:52:16 +0100 | [diff] [blame] | 4831 | freq_range->max_bandwidth_khz = |
| 4832 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4833 | |
| 4834 | power_rule->max_eirp = |
| 4835 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); |
| 4836 | |
| 4837 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) |
| 4838 | power_rule->max_antenna_gain = |
| 4839 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); |
| 4840 | |
Janusz Dziedzic | 089027e | 2014-02-21 19:46:12 +0100 | [diff] [blame] | 4841 | if (tb[NL80211_ATTR_DFS_CAC_TIME]) |
| 4842 | reg_rule->dfs_cac_ms = |
| 4843 | nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]); |
| 4844 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4845 | return 0; |
| 4846 | } |
| 4847 | |
| 4848 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 4849 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4850 | char *data = NULL; |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4851 | enum nl80211_user_reg_hint_type user_reg_hint_type; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4852 | |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 4853 | /* |
| 4854 | * You should only get this when cfg80211 hasn't yet initialized |
| 4855 | * completely when built-in to the kernel right between the time |
| 4856 | * window between nl80211_init() and regulatory_init(), if that is |
| 4857 | * even possible. |
| 4858 | */ |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4859 | if (unlikely(!rcu_access_pointer(cfg80211_regdomain))) |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 4860 | return -EINPROGRESS; |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 4861 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4862 | if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]) |
| 4863 | user_reg_hint_type = |
| 4864 | nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]); |
| 4865 | else |
| 4866 | user_reg_hint_type = NL80211_USER_REG_HINT_USER; |
| 4867 | |
| 4868 | switch (user_reg_hint_type) { |
| 4869 | case NL80211_USER_REG_HINT_USER: |
| 4870 | case NL80211_USER_REG_HINT_CELL_BASE: |
Ilan Peer | 52616f2 | 2014-02-25 16:26:00 +0200 | [diff] [blame] | 4871 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 4872 | return -EINVAL; |
| 4873 | |
| 4874 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 4875 | return regulatory_hint_user(data, user_reg_hint_type); |
| 4876 | case NL80211_USER_REG_HINT_INDOOR: |
| 4877 | return regulatory_hint_indoor_user(); |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4878 | default: |
| 4879 | return -EINVAL; |
| 4880 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4881 | } |
| 4882 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4883 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4884 | struct genl_info *info) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4885 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4886 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4887 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4888 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 4889 | struct mesh_config cur_params; |
| 4890 | int err = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4891 | void *hdr; |
| 4892 | struct nlattr *pinfoattr; |
| 4893 | struct sk_buff *msg; |
| 4894 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4895 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4896 | return -EOPNOTSUPP; |
| 4897 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4898 | if (!rdev->ops->get_mesh_config) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4899 | return -EOPNOTSUPP; |
Jouni Malinen | f3f9258 | 2009-03-20 17:57:36 +0200 | [diff] [blame] | 4900 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4901 | wdev_lock(wdev); |
| 4902 | /* If not connected, get default parameters */ |
| 4903 | if (!wdev->mesh_id_len) |
| 4904 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); |
| 4905 | else |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4906 | err = rdev_get_mesh_config(rdev, dev, &cur_params); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4907 | wdev_unlock(wdev); |
| 4908 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4909 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4910 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4911 | |
| 4912 | /* Draw up a netlink message to send back */ |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4913 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4914 | if (!msg) |
| 4915 | return -ENOMEM; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4916 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4917 | NL80211_CMD_GET_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4918 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4919 | goto out; |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4920 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4921 | if (!pinfoattr) |
| 4922 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4923 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 4924 | nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 4925 | cur_params.dot11MeshRetryTimeout) || |
| 4926 | nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 4927 | cur_params.dot11MeshConfirmTimeout) || |
| 4928 | nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 4929 | cur_params.dot11MeshHoldingTimeout) || |
| 4930 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 4931 | cur_params.dot11MeshMaxPeerLinks) || |
| 4932 | nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES, |
| 4933 | cur_params.dot11MeshMaxRetries) || |
| 4934 | nla_put_u8(msg, NL80211_MESHCONF_TTL, |
| 4935 | cur_params.dot11MeshTTL) || |
| 4936 | nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL, |
| 4937 | cur_params.element_ttl) || |
| 4938 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 4939 | cur_params.auto_open_plinks) || |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 4940 | nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 4941 | cur_params.dot11MeshNbrOffsetMaxNeighbor) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4942 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 4943 | cur_params.dot11MeshHWMPmaxPREQretries) || |
| 4944 | nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 4945 | cur_params.path_refresh_time) || |
| 4946 | nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 4947 | cur_params.min_discovery_timeout) || |
| 4948 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 4949 | cur_params.dot11MeshHWMPactivePathTimeout) || |
| 4950 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 4951 | cur_params.dot11MeshHWMPpreqMinInterval) || |
| 4952 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
| 4953 | cur_params.dot11MeshHWMPperrMinInterval) || |
| 4954 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 4955 | cur_params.dot11MeshHWMPnetDiameterTraversalTime) || |
| 4956 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 4957 | cur_params.dot11MeshHWMPRootMode) || |
| 4958 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
| 4959 | cur_params.dot11MeshHWMPRannInterval) || |
| 4960 | nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
| 4961 | cur_params.dot11MeshGateAnnouncementProtocol) || |
| 4962 | nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, |
| 4963 | cur_params.dot11MeshForwarding) || |
| 4964 | nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, |
Ashok Nagarajan | 70c33ea | 2012-04-30 14:20:32 -0700 | [diff] [blame] | 4965 | cur_params.rssi_threshold) || |
| 4966 | nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4967 | cur_params.ht_opmode) || |
| 4968 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 4969 | cur_params.dot11MeshHWMPactivePathToRootTimeout) || |
| 4970 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4971 | cur_params.dot11MeshHWMProotInterval) || |
| 4972 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4973 | cur_params.dot11MeshHWMPconfirmationInterval) || |
| 4974 | nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE, |
| 4975 | cur_params.power_mode) || |
| 4976 | nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW, |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 4977 | cur_params.dot11MeshAwakeWindowDuration) || |
| 4978 | nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT, |
| 4979 | cur_params.plink_timeout)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4980 | goto nla_put_failure; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4981 | nla_nest_end(msg, pinfoattr); |
| 4982 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4983 | return genlmsg_reply(msg, info); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4984 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4985 | nla_put_failure: |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4986 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4987 | out: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 4988 | nlmsg_free(msg); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4989 | return -ENOBUFS; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4990 | } |
| 4991 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 4992 | 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] | 4993 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
| 4994 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, |
| 4995 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, |
| 4996 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, |
| 4997 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, |
| 4998 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 4999 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5000 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 5001 | [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5002 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
| 5003 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, |
| 5004 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, |
| 5005 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, |
| 5006 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 5007 | [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5008 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
Javier Cardona | 699403d | 2011-08-09 16:45:09 -0700 | [diff] [blame] | 5009 | [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 }, |
Javier Cardona | 0507e15 | 2011-08-09 16:45:10 -0700 | [diff] [blame] | 5010 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 }, |
Javier Cardona | 16dd726 | 2011-08-09 16:45:11 -0700 | [diff] [blame] | 5011 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | 94f9065 | 2012-01-21 01:02:16 +0800 | [diff] [blame] | 5012 | [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5013 | [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 }, |
| 5014 | [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 5015 | [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 }, |
| 5016 | [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 5017 | [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 }, |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 5018 | [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 }, |
| 5019 | [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 }, |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 5020 | [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5021 | }; |
| 5022 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5023 | static const struct nla_policy |
| 5024 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 5025 | [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5026 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
| 5027 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 5028 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
Colleen Twitty | 6e16d90 | 2013-05-08 11:45:59 -0700 | [diff] [blame] | 5029 | [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 }, |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 5030 | [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG }, |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 5031 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5032 | .len = IEEE80211_MAX_DATA_LEN }, |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 5033 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5034 | }; |
| 5035 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5036 | static int nl80211_parse_mesh_config(struct genl_info *info, |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5037 | struct mesh_config *cfg, |
| 5038 | u32 *mask_out) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5039 | { |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5040 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5041 | u32 mask = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5042 | |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5043 | #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \ |
| 5044 | do { \ |
| 5045 | if (tb[attr]) { \ |
| 5046 | if (fn(tb[attr]) < min || fn(tb[attr]) > max) \ |
| 5047 | return -EINVAL; \ |
| 5048 | cfg->param = fn(tb[attr]); \ |
| 5049 | mask |= (1 << (attr - 1)); \ |
| 5050 | } \ |
| 5051 | } while (0) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5052 | |
| 5053 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5054 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5055 | return -EINVAL; |
| 5056 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5057 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5058 | nl80211_meshconf_params_policy)) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5059 | return -EINVAL; |
| 5060 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5061 | /* This makes sure that there aren't more than 32 mesh config |
| 5062 | * parameters (otherwise our bitfield scheme would not work.) */ |
| 5063 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); |
| 5064 | |
| 5065 | /* Fill in the params struct */ |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5066 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5067 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 5068 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5069 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5070 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 5071 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5072 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5073 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 5074 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5075 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5076 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 5077 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5078 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5079 | mask, NL80211_MESHCONF_MAX_RETRIES, |
| 5080 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5081 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5082 | mask, NL80211_MESHCONF_TTL, nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5083 | 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] | 5084 | mask, NL80211_MESHCONF_ELEMENT_TTL, |
| 5085 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5086 | 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] | 5087 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 5088 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5089 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, |
| 5090 | 1, 255, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5091 | NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 5092 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5093 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5094 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 5095 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5096 | 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] | 5097 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 5098 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5099 | 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] | 5100 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 5101 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5102 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
| 5103 | 1, 65535, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5104 | NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 5105 | nla_get_u32); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5106 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5107 | 1, 65535, mask, |
| 5108 | NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5109 | nla_get_u16); |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 5110 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5111 | 1, 65535, mask, |
| 5112 | NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5113 | nla_get_u16); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5114 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5115 | dot11MeshHWMPnetDiameterTraversalTime, |
| 5116 | 1, 65535, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5117 | NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 5118 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5119 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4, |
| 5120 | mask, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 5121 | nla_get_u8); |
| 5122 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535, |
| 5123 | mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5124 | nla_get_u16); |
Rui Paulo | 63c5723 | 2009-11-09 23:46:57 +0000 | [diff] [blame] | 5125 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5126 | dot11MeshGateAnnouncementProtocol, 0, 1, |
| 5127 | mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5128 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5129 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5130 | mask, NL80211_MESHCONF_FORWARDING, |
| 5131 | nla_get_u8); |
Chun-Yeow Yeoh | 83374fe | 2013-07-11 18:24:03 +0800 | [diff] [blame] | 5132 | 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] | 5133 | mask, NL80211_MESHCONF_RSSI_THRESHOLD, |
Chun-Yeow Yeoh | 83374fe | 2013-07-11 18:24:03 +0800 | [diff] [blame] | 5134 | nla_get_s32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5135 | 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] | 5136 | mask, NL80211_MESHCONF_HT_OPMODE, |
| 5137 | nla_get_u16); |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 5138 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5139 | 1, 65535, mask, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 5140 | NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 5141 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5142 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 5143 | mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
| 5144 | nla_get_u16); |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 5145 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5146 | dot11MeshHWMPconfirmationInterval, |
| 5147 | 1, 65535, mask, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 5148 | NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
| 5149 | nla_get_u16); |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 5150 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode, |
| 5151 | NL80211_MESH_POWER_ACTIVE, |
| 5152 | NL80211_MESH_POWER_MAX, |
| 5153 | mask, NL80211_MESHCONF_POWER_MODE, |
| 5154 | nla_get_u32); |
| 5155 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration, |
| 5156 | 0, 65535, mask, |
| 5157 | NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16); |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 5158 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 1, 0xffffffff, |
| 5159 | mask, NL80211_MESHCONF_PLINK_TIMEOUT, |
| 5160 | nla_get_u32); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5161 | if (mask_out) |
| 5162 | *mask_out = mask; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5163 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5164 | return 0; |
| 5165 | |
| 5166 | #undef FILL_IN_MESH_PARAM_IF_SET |
| 5167 | } |
| 5168 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5169 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
| 5170 | struct mesh_setup *setup) |
| 5171 | { |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 5172 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5173 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
| 5174 | |
| 5175 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) |
| 5176 | return -EINVAL; |
| 5177 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, |
| 5178 | info->attrs[NL80211_ATTR_MESH_SETUP], |
| 5179 | nl80211_mesh_setup_params_policy)) |
| 5180 | return -EINVAL; |
| 5181 | |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 5182 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC]) |
| 5183 | setup->sync_method = |
| 5184 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ? |
| 5185 | IEEE80211_SYNC_METHOD_VENDOR : |
| 5186 | IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET; |
| 5187 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5188 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
| 5189 | setup->path_sel_proto = |
| 5190 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? |
| 5191 | IEEE80211_PATH_PROTOCOL_VENDOR : |
| 5192 | IEEE80211_PATH_PROTOCOL_HWMP; |
| 5193 | |
| 5194 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) |
| 5195 | setup->path_metric = |
| 5196 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? |
| 5197 | IEEE80211_PATH_METRIC_VENDOR : |
| 5198 | IEEE80211_PATH_METRIC_AIRTIME; |
| 5199 | |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 5200 | |
| 5201 | if (tb[NL80211_MESH_SETUP_IE]) { |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5202 | struct nlattr *ieattr = |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 5203 | tb[NL80211_MESH_SETUP_IE]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5204 | if (!is_valid_ie_attr(ieattr)) |
| 5205 | return -EINVAL; |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 5206 | setup->ie = nla_data(ieattr); |
| 5207 | setup->ie_len = nla_len(ieattr); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5208 | } |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 5209 | if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] && |
| 5210 | !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM)) |
| 5211 | return -EINVAL; |
| 5212 | setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]); |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 5213 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
| 5214 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 5215 | if (setup->is_secure) |
| 5216 | setup->user_mpm = true; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5217 | |
Colleen Twitty | 6e16d90 | 2013-05-08 11:45:59 -0700 | [diff] [blame] | 5218 | if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) { |
| 5219 | if (!setup->user_mpm) |
| 5220 | return -EINVAL; |
| 5221 | setup->auth_id = |
| 5222 | nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]); |
| 5223 | } |
| 5224 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5225 | return 0; |
| 5226 | } |
| 5227 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5228 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5229 | struct genl_info *info) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5230 | { |
| 5231 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5232 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5233 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5234 | struct mesh_config cfg; |
| 5235 | u32 mask; |
| 5236 | int err; |
| 5237 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5238 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 5239 | return -EOPNOTSUPP; |
| 5240 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5241 | if (!rdev->ops->update_mesh_config) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5242 | return -EOPNOTSUPP; |
| 5243 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5244 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5245 | if (err) |
| 5246 | return err; |
| 5247 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5248 | wdev_lock(wdev); |
| 5249 | if (!wdev->mesh_id_len) |
| 5250 | err = -ENOLINK; |
| 5251 | |
| 5252 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5253 | err = rdev_update_mesh_config(rdev, dev, mask, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5254 | |
| 5255 | wdev_unlock(wdev); |
| 5256 | |
| 5257 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5258 | } |
| 5259 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5260 | static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info) |
| 5261 | { |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5262 | const struct ieee80211_regdomain *regdom; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5263 | struct sk_buff *msg; |
| 5264 | void *hdr = NULL; |
| 5265 | struct nlattr *nl_reg_rules; |
| 5266 | unsigned int i; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5267 | |
| 5268 | if (!cfg80211_regdomain) |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5269 | return -EINVAL; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5270 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 5271 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5272 | if (!msg) |
| 5273 | return -ENOBUFS; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5274 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5275 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5276 | NL80211_CMD_GET_REG); |
| 5277 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 5278 | goto put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5279 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 5280 | if (reg_last_request_cell_base() && |
| 5281 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, |
| 5282 | NL80211_USER_REG_HINT_CELL_BASE)) |
| 5283 | goto nla_put_failure; |
| 5284 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5285 | rcu_read_lock(); |
| 5286 | regdom = rcu_dereference(cfg80211_regdomain); |
| 5287 | |
| 5288 | if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) || |
| 5289 | (regdom->dfs_region && |
| 5290 | nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region))) |
| 5291 | goto nla_put_failure_rcu; |
| 5292 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5293 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
| 5294 | if (!nl_reg_rules) |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5295 | goto nla_put_failure_rcu; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5296 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5297 | for (i = 0; i < regdom->n_reg_rules; i++) { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5298 | struct nlattr *nl_reg_rule; |
| 5299 | const struct ieee80211_reg_rule *reg_rule; |
| 5300 | const struct ieee80211_freq_range *freq_range; |
| 5301 | const struct ieee80211_power_rule *power_rule; |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 5302 | unsigned int max_bandwidth_khz; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5303 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5304 | reg_rule = ®dom->reg_rules[i]; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5305 | freq_range = ®_rule->freq_range; |
| 5306 | power_rule = ®_rule->power_rule; |
| 5307 | |
| 5308 | nl_reg_rule = nla_nest_start(msg, i); |
| 5309 | if (!nl_reg_rule) |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5310 | goto nla_put_failure_rcu; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5311 | |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 5312 | max_bandwidth_khz = freq_range->max_bandwidth_khz; |
| 5313 | if (!max_bandwidth_khz) |
| 5314 | max_bandwidth_khz = reg_get_max_bandwidth(regdom, |
| 5315 | reg_rule); |
| 5316 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5317 | if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
| 5318 | reg_rule->flags) || |
| 5319 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START, |
| 5320 | freq_range->start_freq_khz) || |
| 5321 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END, |
| 5322 | freq_range->end_freq_khz) || |
| 5323 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 5324 | max_bandwidth_khz) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5325 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
| 5326 | power_rule->max_antenna_gain) || |
| 5327 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, |
Janusz Dziedzic | 089027e | 2014-02-21 19:46:12 +0100 | [diff] [blame] | 5328 | power_rule->max_eirp) || |
| 5329 | nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME, |
| 5330 | reg_rule->dfs_cac_ms)) |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5331 | goto nla_put_failure_rcu; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5332 | |
| 5333 | nla_nest_end(msg, nl_reg_rule); |
| 5334 | } |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5335 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5336 | |
| 5337 | nla_nest_end(msg, nl_reg_rules); |
| 5338 | |
| 5339 | genlmsg_end(msg, hdr); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5340 | return genlmsg_reply(msg, info); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5341 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5342 | nla_put_failure_rcu: |
| 5343 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5344 | nla_put_failure: |
| 5345 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 5346 | put_failure: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 5347 | nlmsg_free(msg); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5348 | return -EMSGSIZE; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5349 | } |
| 5350 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5351 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 5352 | { |
| 5353 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; |
| 5354 | struct nlattr *nl_reg_rule; |
| 5355 | char *alpha2 = NULL; |
| 5356 | int rem_reg_rules = 0, r = 0; |
| 5357 | u32 num_rules = 0, rule_idx = 0, size_of_regd; |
Luis R. Rodriguez | 4c7d398 | 2013-11-13 18:54:02 +0100 | [diff] [blame] | 5358 | enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5359 | struct ieee80211_regdomain *rd = NULL; |
| 5360 | |
| 5361 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 5362 | return -EINVAL; |
| 5363 | |
| 5364 | if (!info->attrs[NL80211_ATTR_REG_RULES]) |
| 5365 | return -EINVAL; |
| 5366 | |
| 5367 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 5368 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 5369 | if (info->attrs[NL80211_ATTR_DFS_REGION]) |
| 5370 | dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); |
| 5371 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5372 | 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] | 5373 | rem_reg_rules) { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5374 | num_rules++; |
| 5375 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) |
Luis R. Rodriguez | 4776c6e | 2009-05-13 17:04:39 -0400 | [diff] [blame] | 5376 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5377 | } |
| 5378 | |
Luis R. Rodriguez | e438768 | 2013-11-05 09:18:01 -0800 | [diff] [blame] | 5379 | if (!reg_is_valid_request(alpha2)) |
| 5380 | return -EINVAL; |
| 5381 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5382 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 5383 | num_rules * sizeof(struct ieee80211_reg_rule); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5384 | |
| 5385 | rd = kzalloc(size_of_regd, GFP_KERNEL); |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 5386 | if (!rd) |
| 5387 | return -ENOMEM; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5388 | |
| 5389 | rd->n_reg_rules = num_rules; |
| 5390 | rd->alpha2[0] = alpha2[0]; |
| 5391 | rd->alpha2[1] = alpha2[1]; |
| 5392 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 5393 | /* |
| 5394 | * Disable DFS master mode if the DFS region was |
| 5395 | * not supported or known on this kernel. |
| 5396 | */ |
| 5397 | if (reg_supported_dfs_region(dfs_region)) |
| 5398 | rd->dfs_region = dfs_region; |
| 5399 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5400 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 5401 | rem_reg_rules) { |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 5402 | r = nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, |
| 5403 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), |
| 5404 | reg_rule_policy); |
| 5405 | if (r) |
| 5406 | goto bad_reg; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5407 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
| 5408 | if (r) |
| 5409 | goto bad_reg; |
| 5410 | |
| 5411 | rule_idx++; |
| 5412 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 5413 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
| 5414 | r = -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5415 | goto bad_reg; |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 5416 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5417 | } |
| 5418 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5419 | r = set_regdom(rd); |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 5420 | /* set_regdom took ownership */ |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 5421 | rd = NULL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5422 | |
Johannes Berg | d2372b3 | 2008-10-24 20:32:20 +0200 | [diff] [blame] | 5423 | bad_reg: |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5424 | kfree(rd); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 5425 | return r; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5426 | } |
| 5427 | |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5428 | static int validate_scan_freqs(struct nlattr *freqs) |
| 5429 | { |
| 5430 | struct nlattr *attr1, *attr2; |
| 5431 | int n_channels = 0, tmp1, tmp2; |
| 5432 | |
| 5433 | nla_for_each_nested(attr1, freqs, tmp1) { |
| 5434 | n_channels++; |
| 5435 | /* |
| 5436 | * Some hardware has a limited channel list for |
| 5437 | * scanning, and it is pretty much nonsensical |
| 5438 | * to scan for a channel twice, so disallow that |
| 5439 | * and don't require drivers to check that the |
| 5440 | * channel list they get isn't longer than what |
| 5441 | * they can scan, as long as they can scan all |
| 5442 | * the channels they registered at once. |
| 5443 | */ |
| 5444 | nla_for_each_nested(attr2, freqs, tmp2) |
| 5445 | if (attr1 != attr2 && |
| 5446 | nla_get_u32(attr1) == nla_get_u32(attr2)) |
| 5447 | return 0; |
| 5448 | } |
| 5449 | |
| 5450 | return n_channels; |
| 5451 | } |
| 5452 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5453 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
| 5454 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5455 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 5456 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5457 | struct cfg80211_scan_request *request; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5458 | struct nlattr *attr; |
| 5459 | struct wiphy *wiphy; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5460 | int err, tmp, n_ssids = 0, n_channels, i; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5461 | size_t ie_len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5462 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5463 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5464 | return -EINVAL; |
| 5465 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5466 | wiphy = &rdev->wiphy; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5467 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5468 | if (!rdev->ops->scan) |
| 5469 | return -EOPNOTSUPP; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5470 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 5471 | if (rdev->scan_req || rdev->scan_msg) { |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5472 | err = -EBUSY; |
| 5473 | goto unlock; |
| 5474 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5475 | |
| 5476 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5477 | n_channels = validate_scan_freqs( |
| 5478 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5479 | if (!n_channels) { |
| 5480 | err = -EINVAL; |
| 5481 | goto unlock; |
| 5482 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5483 | } else { |
Ilan Peer | bdfbec2 | 2014-01-09 11:37:23 +0200 | [diff] [blame] | 5484 | n_channels = ieee80211_get_num_supported_channels(wiphy); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5485 | } |
| 5486 | |
| 5487 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 5488 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) |
| 5489 | n_ssids++; |
| 5490 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5491 | if (n_ssids > wiphy->max_scan_ssids) { |
| 5492 | err = -EINVAL; |
| 5493 | goto unlock; |
| 5494 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5495 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5496 | if (info->attrs[NL80211_ATTR_IE]) |
| 5497 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5498 | else |
| 5499 | ie_len = 0; |
| 5500 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5501 | if (ie_len > wiphy->max_scan_ie_len) { |
| 5502 | err = -EINVAL; |
| 5503 | goto unlock; |
| 5504 | } |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 5505 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5506 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 5507 | + sizeof(*request->ssids) * n_ssids |
| 5508 | + sizeof(*request->channels) * n_channels |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5509 | + ie_len, GFP_KERNEL); |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5510 | if (!request) { |
| 5511 | err = -ENOMEM; |
| 5512 | goto unlock; |
| 5513 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5514 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5515 | if (n_ssids) |
Johannes Berg | 5ba6353 | 2009-08-07 17:54:07 +0200 | [diff] [blame] | 5516 | request->ssids = (void *)&request->channels[n_channels]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5517 | request->n_ssids = n_ssids; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5518 | if (ie_len) { |
| 5519 | if (request->ssids) |
| 5520 | request->ie = (void *)(request->ssids + n_ssids); |
| 5521 | else |
| 5522 | request->ie = (void *)(request->channels + n_channels); |
| 5523 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5524 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5525 | i = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5526 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 5527 | /* user specified, bail out if channel not found */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5528 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5529 | struct ieee80211_channel *chan; |
| 5530 | |
| 5531 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 5532 | |
| 5533 | if (!chan) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5534 | err = -EINVAL; |
| 5535 | goto out_free; |
| 5536 | } |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5537 | |
| 5538 | /* ignore disabled channels */ |
| 5539 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5540 | continue; |
| 5541 | |
| 5542 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5543 | i++; |
| 5544 | } |
| 5545 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5546 | enum ieee80211_band band; |
| 5547 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5548 | /* all channels */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5549 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 5550 | int j; |
| 5551 | if (!wiphy->bands[band]) |
| 5552 | continue; |
| 5553 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5554 | struct ieee80211_channel *chan; |
| 5555 | |
| 5556 | chan = &wiphy->bands[band]->channels[j]; |
| 5557 | |
| 5558 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5559 | continue; |
| 5560 | |
| 5561 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5562 | i++; |
| 5563 | } |
| 5564 | } |
| 5565 | } |
| 5566 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5567 | if (!i) { |
| 5568 | err = -EINVAL; |
| 5569 | goto out_free; |
| 5570 | } |
| 5571 | |
| 5572 | request->n_channels = i; |
| 5573 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5574 | i = 0; |
| 5575 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 5576 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5577 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5578 | err = -EINVAL; |
| 5579 | goto out_free; |
| 5580 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5581 | request->ssids[i].ssid_len = nla_len(attr); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5582 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5583 | i++; |
| 5584 | } |
| 5585 | } |
| 5586 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5587 | if (info->attrs[NL80211_ATTR_IE]) { |
| 5588 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Johannes Berg | de95a54 | 2009-04-01 11:58:36 +0200 | [diff] [blame] | 5589 | memcpy((void *)request->ie, |
| 5590 | nla_data(info->attrs[NL80211_ATTR_IE]), |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5591 | request->ie_len); |
| 5592 | } |
| 5593 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5594 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) |
Johannes Berg | a401d2b | 2011-07-20 00:52:16 +0200 | [diff] [blame] | 5595 | if (wiphy->bands[i]) |
| 5596 | request->rates[i] = |
| 5597 | (1 << wiphy->bands[i]->n_bitrates) - 1; |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5598 | |
| 5599 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { |
| 5600 | nla_for_each_nested(attr, |
| 5601 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], |
| 5602 | tmp) { |
| 5603 | enum ieee80211_band band = nla_type(attr); |
| 5604 | |
Dan Carpenter | 8440462 | 2011-07-29 11:52:18 +0300 | [diff] [blame] | 5605 | if (band < 0 || band >= IEEE80211_NUM_BANDS) { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5606 | err = -EINVAL; |
| 5607 | goto out_free; |
| 5608 | } |
Felix Fietkau | 1b09cd8 | 2013-11-20 19:40:41 +0100 | [diff] [blame] | 5609 | |
| 5610 | if (!wiphy->bands[band]) |
| 5611 | continue; |
| 5612 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5613 | err = ieee80211_get_ratemask(wiphy->bands[band], |
| 5614 | nla_data(attr), |
| 5615 | nla_len(attr), |
| 5616 | &request->rates[band]); |
| 5617 | if (err) |
| 5618 | goto out_free; |
| 5619 | } |
| 5620 | } |
| 5621 | |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5622 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5623 | request->flags = nla_get_u32( |
| 5624 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); |
Johannes Berg | 00c3a6e | 2013-10-26 17:14:38 +0200 | [diff] [blame] | 5625 | if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 5626 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) { |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5627 | err = -EOPNOTSUPP; |
| 5628 | goto out_free; |
| 5629 | } |
| 5630 | } |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5631 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 5632 | request->no_cck = |
| 5633 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 5634 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 5635 | request->wdev = wdev; |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5636 | request->wiphy = &rdev->wiphy; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 5637 | request->scan_start = jiffies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5638 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5639 | rdev->scan_req = request; |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5640 | err = rdev_scan(rdev, request); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5641 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5642 | if (!err) { |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 5643 | nl80211_send_scan_start(rdev, wdev); |
| 5644 | if (wdev->netdev) |
| 5645 | dev_hold(wdev->netdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5646 | } else { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5647 | out_free: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5648 | rdev->scan_req = NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5649 | kfree(request); |
| 5650 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 5651 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5652 | unlock: |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5653 | return err; |
| 5654 | } |
| 5655 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5656 | static int nl80211_start_sched_scan(struct sk_buff *skb, |
| 5657 | struct genl_info *info) |
| 5658 | { |
| 5659 | struct cfg80211_sched_scan_request *request; |
| 5660 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5661 | struct net_device *dev = info->user_ptr[1]; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5662 | struct nlattr *attr; |
| 5663 | struct wiphy *wiphy; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5664 | 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] | 5665 | u32 interval; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5666 | enum ieee80211_band band; |
| 5667 | size_t ie_len; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5668 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 5669 | s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5670 | |
| 5671 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 5672 | !rdev->ops->sched_scan_start) |
| 5673 | return -EOPNOTSUPP; |
| 5674 | |
| 5675 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5676 | return -EINVAL; |
| 5677 | |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 5678 | if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
| 5679 | return -EINVAL; |
| 5680 | |
| 5681 | interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); |
| 5682 | if (interval == 0) |
| 5683 | return -EINVAL; |
| 5684 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5685 | wiphy = &rdev->wiphy; |
| 5686 | |
| 5687 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 5688 | n_channels = validate_scan_freqs( |
| 5689 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
| 5690 | if (!n_channels) |
| 5691 | return -EINVAL; |
| 5692 | } else { |
Ilan Peer | bdfbec2 | 2014-01-09 11:37:23 +0200 | [diff] [blame] | 5693 | n_channels = ieee80211_get_num_supported_channels(wiphy); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5694 | } |
| 5695 | |
| 5696 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 5697 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 5698 | tmp) |
| 5699 | n_ssids++; |
| 5700 | |
Luciano Coelho | 93b6aa6 | 2011-07-13 14:57:28 +0300 | [diff] [blame] | 5701 | if (n_ssids > wiphy->max_sched_scan_ssids) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5702 | return -EINVAL; |
| 5703 | |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 5704 | /* |
| 5705 | * First, count the number of 'real' matchsets. Due to an issue with |
| 5706 | * the old implementation, matchsets containing only the RSSI attribute |
| 5707 | * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default' |
| 5708 | * RSSI for all matchsets, rather than their own matchset for reporting |
| 5709 | * all APs with a strong RSSI. This is needed to be compatible with |
| 5710 | * older userspace that treated a matchset with only the RSSI as the |
| 5711 | * global RSSI for all other matchsets - if there are other matchsets. |
| 5712 | */ |
| 5713 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5714 | nla_for_each_nested(attr, |
| 5715 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 5716 | tmp) { |
| 5717 | struct nlattr *rssi; |
| 5718 | |
| 5719 | err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
| 5720 | nla_data(attr), nla_len(attr), |
| 5721 | nl80211_match_policy); |
| 5722 | if (err) |
| 5723 | return err; |
| 5724 | /* add other standalone attributes here */ |
| 5725 | if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]) { |
| 5726 | n_match_sets++; |
| 5727 | continue; |
| 5728 | } |
| 5729 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; |
| 5730 | if (rssi) |
| 5731 | default_match_rssi = nla_get_s32(rssi); |
| 5732 | } |
| 5733 | } |
| 5734 | |
| 5735 | /* However, if there's no other matchset, add the RSSI one */ |
| 5736 | if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF) |
| 5737 | n_match_sets = 1; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5738 | |
| 5739 | if (n_match_sets > wiphy->max_match_sets) |
| 5740 | return -EINVAL; |
| 5741 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5742 | if (info->attrs[NL80211_ATTR_IE]) |
| 5743 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5744 | else |
| 5745 | ie_len = 0; |
| 5746 | |
Luciano Coelho | 5a865ba | 2011-07-13 14:57:29 +0300 | [diff] [blame] | 5747 | if (ie_len > wiphy->max_sched_scan_ie_len) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5748 | return -EINVAL; |
| 5749 | |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 5750 | if (rdev->sched_scan_req) { |
| 5751 | err = -EINPROGRESS; |
| 5752 | goto out; |
| 5753 | } |
| 5754 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5755 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 5756 | + sizeof(*request->ssids) * n_ssids |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5757 | + sizeof(*request->match_sets) * n_match_sets |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 5758 | + sizeof(*request->channels) * n_channels |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5759 | + ie_len, GFP_KERNEL); |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 5760 | if (!request) { |
| 5761 | err = -ENOMEM; |
| 5762 | goto out; |
| 5763 | } |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5764 | |
| 5765 | if (n_ssids) |
| 5766 | request->ssids = (void *)&request->channels[n_channels]; |
| 5767 | request->n_ssids = n_ssids; |
| 5768 | if (ie_len) { |
| 5769 | if (request->ssids) |
| 5770 | request->ie = (void *)(request->ssids + n_ssids); |
| 5771 | else |
| 5772 | request->ie = (void *)(request->channels + n_channels); |
| 5773 | } |
| 5774 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5775 | if (n_match_sets) { |
| 5776 | if (request->ie) |
| 5777 | request->match_sets = (void *)(request->ie + ie_len); |
| 5778 | else if (request->ssids) |
| 5779 | request->match_sets = |
| 5780 | (void *)(request->ssids + n_ssids); |
| 5781 | else |
| 5782 | request->match_sets = |
| 5783 | (void *)(request->channels + n_channels); |
| 5784 | } |
| 5785 | request->n_match_sets = n_match_sets; |
| 5786 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5787 | i = 0; |
| 5788 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 5789 | /* user specified, bail out if channel not found */ |
| 5790 | nla_for_each_nested(attr, |
| 5791 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], |
| 5792 | tmp) { |
| 5793 | struct ieee80211_channel *chan; |
| 5794 | |
| 5795 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 5796 | |
| 5797 | if (!chan) { |
| 5798 | err = -EINVAL; |
| 5799 | goto out_free; |
| 5800 | } |
| 5801 | |
| 5802 | /* ignore disabled channels */ |
| 5803 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5804 | continue; |
| 5805 | |
| 5806 | request->channels[i] = chan; |
| 5807 | i++; |
| 5808 | } |
| 5809 | } else { |
| 5810 | /* all channels */ |
| 5811 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 5812 | int j; |
| 5813 | if (!wiphy->bands[band]) |
| 5814 | continue; |
| 5815 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
| 5816 | struct ieee80211_channel *chan; |
| 5817 | |
| 5818 | chan = &wiphy->bands[band]->channels[j]; |
| 5819 | |
| 5820 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5821 | continue; |
| 5822 | |
| 5823 | request->channels[i] = chan; |
| 5824 | i++; |
| 5825 | } |
| 5826 | } |
| 5827 | } |
| 5828 | |
| 5829 | if (!i) { |
| 5830 | err = -EINVAL; |
| 5831 | goto out_free; |
| 5832 | } |
| 5833 | |
| 5834 | request->n_channels = i; |
| 5835 | |
| 5836 | i = 0; |
| 5837 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 5838 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 5839 | tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5840 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5841 | err = -EINVAL; |
| 5842 | goto out_free; |
| 5843 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5844 | request->ssids[i].ssid_len = nla_len(attr); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5845 | memcpy(request->ssids[i].ssid, nla_data(attr), |
| 5846 | nla_len(attr)); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5847 | i++; |
| 5848 | } |
| 5849 | } |
| 5850 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5851 | i = 0; |
| 5852 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
| 5853 | nla_for_each_nested(attr, |
| 5854 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
| 5855 | tmp) { |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 5856 | struct nlattr *ssid, *rssi; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5857 | |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 5858 | err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
| 5859 | nla_data(attr), nla_len(attr), |
| 5860 | nl80211_match_policy); |
| 5861 | if (err) |
| 5862 | goto out_free; |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 5863 | ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5864 | if (ssid) { |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 5865 | if (WARN_ON(i >= n_match_sets)) { |
| 5866 | /* this indicates a programming error, |
| 5867 | * the loop above should have verified |
| 5868 | * things properly |
| 5869 | */ |
| 5870 | err = -EINVAL; |
| 5871 | goto out_free; |
| 5872 | } |
| 5873 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5874 | if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) { |
| 5875 | err = -EINVAL; |
| 5876 | goto out_free; |
| 5877 | } |
| 5878 | memcpy(request->match_sets[i].ssid.ssid, |
| 5879 | nla_data(ssid), nla_len(ssid)); |
| 5880 | request->match_sets[i].ssid.ssid_len = |
| 5881 | nla_len(ssid); |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 5882 | /* special attribute - old implemenation w/a */ |
| 5883 | request->match_sets[i].rssi_thold = |
| 5884 | default_match_rssi; |
| 5885 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; |
| 5886 | if (rssi) |
| 5887 | request->match_sets[i].rssi_thold = |
| 5888 | nla_get_s32(rssi); |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5889 | } |
| 5890 | i++; |
| 5891 | } |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 5892 | |
| 5893 | /* there was no other matchset, so the RSSI one is alone */ |
| 5894 | if (i == 0) |
| 5895 | request->match_sets[0].rssi_thold = default_match_rssi; |
| 5896 | |
| 5897 | request->min_rssi_thold = INT_MAX; |
| 5898 | for (i = 0; i < n_match_sets; i++) |
| 5899 | request->min_rssi_thold = |
| 5900 | min(request->match_sets[i].rssi_thold, |
| 5901 | request->min_rssi_thold); |
| 5902 | } else { |
| 5903 | request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5904 | } |
| 5905 | |
Johannes Berg | 9900e48 | 2014-02-04 21:01:25 +0100 | [diff] [blame] | 5906 | if (ie_len) { |
| 5907 | request->ie_len = ie_len; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5908 | memcpy((void *)request->ie, |
| 5909 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 5910 | request->ie_len); |
| 5911 | } |
| 5912 | |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5913 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5914 | request->flags = nla_get_u32( |
| 5915 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); |
Johannes Berg | 00c3a6e | 2013-10-26 17:14:38 +0200 | [diff] [blame] | 5916 | if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 5917 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) { |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5918 | err = -EOPNOTSUPP; |
| 5919 | goto out_free; |
| 5920 | } |
| 5921 | } |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5922 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5923 | request->dev = dev; |
| 5924 | request->wiphy = &rdev->wiphy; |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 5925 | request->interval = interval; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 5926 | request->scan_start = jiffies; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5927 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5928 | err = rdev_sched_scan_start(rdev, dev, request); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5929 | if (!err) { |
| 5930 | rdev->sched_scan_req = request; |
| 5931 | nl80211_send_sched_scan(rdev, dev, |
| 5932 | NL80211_CMD_START_SCHED_SCAN); |
| 5933 | goto out; |
| 5934 | } |
| 5935 | |
| 5936 | out_free: |
| 5937 | kfree(request); |
| 5938 | out: |
| 5939 | return err; |
| 5940 | } |
| 5941 | |
| 5942 | static int nl80211_stop_sched_scan(struct sk_buff *skb, |
| 5943 | struct genl_info *info) |
| 5944 | { |
| 5945 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5946 | |
| 5947 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 5948 | !rdev->ops->sched_scan_stop) |
| 5949 | return -EOPNOTSUPP; |
| 5950 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5951 | return __cfg80211_stop_sched_scan(rdev, false); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5952 | } |
| 5953 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5954 | static int nl80211_start_radar_detection(struct sk_buff *skb, |
| 5955 | struct genl_info *info) |
| 5956 | { |
| 5957 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5958 | struct net_device *dev = info->user_ptr[1]; |
| 5959 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 5960 | struct cfg80211_chan_def chandef; |
Luis R. Rodriguez | 55f7435 | 2013-11-25 20:56:10 +0100 | [diff] [blame] | 5961 | enum nl80211_dfs_regions dfs_region; |
Janusz Dziedzic | 31559f3 | 2014-02-21 19:46:13 +0100 | [diff] [blame] | 5962 | unsigned int cac_time_ms; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5963 | int err; |
| 5964 | |
Luis R. Rodriguez | 55f7435 | 2013-11-25 20:56:10 +0100 | [diff] [blame] | 5965 | dfs_region = reg_get_dfs_region(wdev->wiphy); |
| 5966 | if (dfs_region == NL80211_DFS_UNSET) |
| 5967 | return -EINVAL; |
| 5968 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5969 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 5970 | if (err) |
| 5971 | return err; |
| 5972 | |
Simon Wunderlich | ff311bc | 2013-09-03 19:43:18 +0200 | [diff] [blame] | 5973 | if (netif_carrier_ok(dev)) |
| 5974 | return -EBUSY; |
| 5975 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5976 | if (wdev->cac_started) |
| 5977 | return -EBUSY; |
| 5978 | |
Luciano Coelho | 2beb6dab | 2014-02-18 11:40:36 +0200 | [diff] [blame] | 5979 | err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, |
Luciano Coelho | 00ec75f | 2014-05-15 13:05:39 +0300 | [diff] [blame] | 5980 | wdev->iftype); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5981 | if (err < 0) |
| 5982 | return err; |
| 5983 | |
| 5984 | if (err == 0) |
| 5985 | return -EINVAL; |
| 5986 | |
Janusz Dziedzic | fe7c3a1 | 2013-11-05 14:48:48 +0100 | [diff] [blame] | 5987 | if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef)) |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5988 | return -EINVAL; |
| 5989 | |
| 5990 | if (!rdev->ops->start_radar_detection) |
| 5991 | return -EOPNOTSUPP; |
| 5992 | |
Janusz Dziedzic | 31559f3 | 2014-02-21 19:46:13 +0100 | [diff] [blame] | 5993 | cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef); |
| 5994 | if (WARN_ON(!cac_time_ms)) |
| 5995 | cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS; |
| 5996 | |
| 5997 | err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef, |
| 5998 | cac_time_ms); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5999 | if (!err) { |
Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 6000 | wdev->chandef = chandef; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6001 | wdev->cac_started = true; |
| 6002 | wdev->cac_start_time = jiffies; |
Janusz Dziedzic | 31559f3 | 2014-02-21 19:46:13 +0100 | [diff] [blame] | 6003 | wdev->cac_time_ms = cac_time_ms; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6004 | } |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6005 | return err; |
| 6006 | } |
| 6007 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6008 | static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info) |
| 6009 | { |
| 6010 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6011 | struct net_device *dev = info->user_ptr[1]; |
| 6012 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 6013 | struct cfg80211_csa_settings params; |
| 6014 | /* csa_attrs is defined static to avoid waste of stack size - this |
| 6015 | * function is called under RTNL lock, so this should not be a problem. |
| 6016 | */ |
| 6017 | static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1]; |
| 6018 | u8 radar_detect_width = 0; |
| 6019 | int err; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 6020 | bool need_new_beacon = false; |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 6021 | int len, i; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6022 | |
| 6023 | if (!rdev->ops->channel_switch || |
| 6024 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)) |
| 6025 | return -EOPNOTSUPP; |
| 6026 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 6027 | switch (dev->ieee80211_ptr->iftype) { |
| 6028 | case NL80211_IFTYPE_AP: |
| 6029 | case NL80211_IFTYPE_P2P_GO: |
| 6030 | need_new_beacon = true; |
| 6031 | |
| 6032 | /* useless if AP is not running */ |
| 6033 | if (!wdev->beacon_interval) |
Johannes Berg | 1ff79df | 2014-01-22 10:05:27 +0100 | [diff] [blame] | 6034 | return -ENOTCONN; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 6035 | break; |
| 6036 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | 1ff79df | 2014-01-22 10:05:27 +0100 | [diff] [blame] | 6037 | if (!wdev->ssid_len) |
| 6038 | return -ENOTCONN; |
| 6039 | break; |
Chun-Yeow Yeoh | c6da674 | 2013-10-14 19:08:28 -0700 | [diff] [blame] | 6040 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 1ff79df | 2014-01-22 10:05:27 +0100 | [diff] [blame] | 6041 | if (!wdev->mesh_id_len) |
| 6042 | return -ENOTCONN; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 6043 | break; |
| 6044 | default: |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6045 | return -EOPNOTSUPP; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 6046 | } |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6047 | |
| 6048 | memset(¶ms, 0, sizeof(params)); |
| 6049 | |
| 6050 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 6051 | !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]) |
| 6052 | return -EINVAL; |
| 6053 | |
| 6054 | /* only important for AP, IBSS and mesh create IEs internally */ |
Andrei Otcheretianski | d0a361a | 2013-10-17 10:52:17 +0200 | [diff] [blame] | 6055 | if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES]) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6056 | return -EINVAL; |
| 6057 | |
| 6058 | params.count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]); |
| 6059 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 6060 | if (!need_new_beacon) |
| 6061 | goto skip_beacons; |
| 6062 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6063 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon_after); |
| 6064 | if (err) |
| 6065 | return err; |
| 6066 | |
| 6067 | err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX, |
| 6068 | info->attrs[NL80211_ATTR_CSA_IES], |
| 6069 | nl80211_policy); |
| 6070 | if (err) |
| 6071 | return err; |
| 6072 | |
| 6073 | err = nl80211_parse_beacon(csa_attrs, ¶ms.beacon_csa); |
| 6074 | if (err) |
| 6075 | return err; |
| 6076 | |
| 6077 | if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]) |
| 6078 | return -EINVAL; |
| 6079 | |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 6080 | len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); |
| 6081 | if (!len || (len % sizeof(u16))) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6082 | return -EINVAL; |
| 6083 | |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 6084 | params.n_counter_offsets_beacon = len / sizeof(u16); |
| 6085 | if (rdev->wiphy.max_num_csa_counters && |
| 6086 | (params.n_counter_offsets_beacon > |
| 6087 | rdev->wiphy.max_num_csa_counters)) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6088 | return -EINVAL; |
| 6089 | |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 6090 | params.counter_offsets_beacon = |
| 6091 | nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); |
| 6092 | |
| 6093 | /* sanity checks - counters should fit and be the same */ |
| 6094 | for (i = 0; i < params.n_counter_offsets_beacon; i++) { |
| 6095 | u16 offset = params.counter_offsets_beacon[i]; |
| 6096 | |
| 6097 | if (offset >= params.beacon_csa.tail_len) |
| 6098 | return -EINVAL; |
| 6099 | |
| 6100 | if (params.beacon_csa.tail[offset] != params.count) |
| 6101 | return -EINVAL; |
| 6102 | } |
| 6103 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6104 | if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) { |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 6105 | len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); |
| 6106 | if (!len || (len % sizeof(u16))) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6107 | return -EINVAL; |
| 6108 | |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 6109 | params.n_counter_offsets_presp = len / sizeof(u16); |
| 6110 | if (rdev->wiphy.max_num_csa_counters && |
| 6111 | (params.n_counter_offsets_beacon > |
| 6112 | rdev->wiphy.max_num_csa_counters)) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6113 | return -EINVAL; |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 6114 | |
| 6115 | params.counter_offsets_presp = |
| 6116 | nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); |
| 6117 | |
| 6118 | /* sanity checks - counters should fit and be the same */ |
| 6119 | for (i = 0; i < params.n_counter_offsets_presp; i++) { |
| 6120 | u16 offset = params.counter_offsets_presp[i]; |
| 6121 | |
| 6122 | if (offset >= params.beacon_csa.probe_resp_len) |
| 6123 | return -EINVAL; |
| 6124 | |
| 6125 | if (params.beacon_csa.probe_resp[offset] != |
| 6126 | params.count) |
| 6127 | return -EINVAL; |
| 6128 | } |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6129 | } |
| 6130 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 6131 | skip_beacons: |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6132 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
| 6133 | if (err) |
| 6134 | return err; |
| 6135 | |
Ilan Peer | 174e0cd | 2014-02-23 09:13:01 +0200 | [diff] [blame] | 6136 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, ¶ms.chandef, |
| 6137 | wdev->iftype)) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6138 | return -EINVAL; |
| 6139 | |
Luciano Coelho | 2beb6dab | 2014-02-18 11:40:36 +0200 | [diff] [blame] | 6140 | err = cfg80211_chandef_dfs_required(wdev->wiphy, |
| 6141 | ¶ms.chandef, |
| 6142 | wdev->iftype); |
| 6143 | if (err < 0) |
| 6144 | return err; |
| 6145 | |
| 6146 | if (err > 0) { |
| 6147 | radar_detect_width = BIT(params.chandef.width); |
| 6148 | params.radar_required = true; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6149 | } |
| 6150 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6151 | if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX]) |
| 6152 | params.block_tx = true; |
| 6153 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 6154 | wdev_lock(wdev); |
| 6155 | err = rdev_channel_switch(rdev, dev, ¶ms); |
| 6156 | wdev_unlock(wdev); |
| 6157 | |
| 6158 | return err; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6159 | } |
| 6160 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 6161 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
| 6162 | u32 seq, int flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6163 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6164 | struct wireless_dev *wdev, |
| 6165 | struct cfg80211_internal_bss *intbss) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6166 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6167 | struct cfg80211_bss *res = &intbss->pub; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 6168 | const struct cfg80211_bss_ies *ies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6169 | void *hdr; |
| 6170 | struct nlattr *bss; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6171 | |
| 6172 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6173 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6174 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6175 | NL80211_CMD_NEW_SCAN_RESULTS); |
| 6176 | if (!hdr) |
| 6177 | return -1; |
| 6178 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 6179 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
| 6180 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6181 | if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation)) |
| 6182 | goto nla_put_failure; |
| 6183 | if (wdev->netdev && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6184 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex)) |
| 6185 | goto nla_put_failure; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6186 | if (nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 6187 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6188 | |
| 6189 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); |
| 6190 | if (!bss) |
| 6191 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6192 | if ((!is_zero_ether_addr(res->bssid) && |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 6193 | nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6194 | goto nla_put_failure; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 6195 | |
| 6196 | rcu_read_lock(); |
Johannes Berg | 0e22708 | 2014-08-12 20:34:30 +0200 | [diff] [blame] | 6197 | /* indicate whether we have probe response data or not */ |
| 6198 | if (rcu_access_pointer(res->proberesp_ies) && |
| 6199 | nla_put_flag(msg, NL80211_BSS_PRESP_DATA)) |
| 6200 | goto fail_unlock_rcu; |
| 6201 | |
| 6202 | /* this pointer prefers to be pointed to probe response data |
| 6203 | * but is always valid |
| 6204 | */ |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 6205 | ies = rcu_dereference(res->ies); |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 6206 | if (ies) { |
| 6207 | if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf)) |
| 6208 | goto fail_unlock_rcu; |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 6209 | if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS, |
| 6210 | ies->len, ies->data)) |
| 6211 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 6212 | } |
Johannes Berg | 0e22708 | 2014-08-12 20:34:30 +0200 | [diff] [blame] | 6213 | |
| 6214 | /* and this pointer is always (unless driver didn't know) beacon data */ |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 6215 | ies = rcu_dereference(res->beacon_ies); |
Johannes Berg | 0e22708 | 2014-08-12 20:34:30 +0200 | [diff] [blame] | 6216 | if (ies && ies->from_beacon) { |
| 6217 | if (nla_put_u64(msg, NL80211_BSS_BEACON_TSF, ies->tsf)) |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 6218 | goto fail_unlock_rcu; |
| 6219 | if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES, |
| 6220 | ies->len, ies->data)) |
| 6221 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 6222 | } |
| 6223 | rcu_read_unlock(); |
| 6224 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6225 | if (res->beacon_interval && |
| 6226 | nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval)) |
| 6227 | goto nla_put_failure; |
| 6228 | if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) || |
| 6229 | nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) || |
Simon Wunderlich | dcd6eac | 2013-07-08 16:55:49 +0200 | [diff] [blame] | 6230 | nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6231 | nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO, |
| 6232 | jiffies_to_msecs(jiffies - intbss->ts))) |
| 6233 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6234 | |
Johannes Berg | 77965c9 | 2009-02-18 18:45:06 +0100 | [diff] [blame] | 6235 | switch (rdev->wiphy.signal_type) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6236 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6237 | if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal)) |
| 6238 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6239 | break; |
| 6240 | case CFG80211_SIGNAL_TYPE_UNSPEC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6241 | if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal)) |
| 6242 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6243 | break; |
| 6244 | default: |
| 6245 | break; |
| 6246 | } |
| 6247 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6248 | switch (wdev->iftype) { |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6249 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6250 | case NL80211_IFTYPE_STATION: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6251 | if (intbss == wdev->current_bss && |
| 6252 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 6253 | NL80211_BSS_STATUS_ASSOCIATED)) |
| 6254 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6255 | break; |
| 6256 | case NL80211_IFTYPE_ADHOC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6257 | if (intbss == wdev->current_bss && |
| 6258 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 6259 | NL80211_BSS_STATUS_IBSS_JOINED)) |
| 6260 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6261 | break; |
| 6262 | default: |
| 6263 | break; |
| 6264 | } |
| 6265 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6266 | nla_nest_end(msg, bss); |
| 6267 | |
| 6268 | return genlmsg_end(msg, hdr); |
| 6269 | |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 6270 | fail_unlock_rcu: |
| 6271 | rcu_read_unlock(); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6272 | nla_put_failure: |
| 6273 | genlmsg_cancel(msg, hdr); |
| 6274 | return -EMSGSIZE; |
| 6275 | } |
| 6276 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6277 | 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] | 6278 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6279 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6280 | struct cfg80211_internal_bss *scan; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6281 | struct wireless_dev *wdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6282 | int start = cb->args[2], idx = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6283 | int err; |
| 6284 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6285 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 6286 | if (err) |
| 6287 | return err; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6288 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6289 | wdev_lock(wdev); |
| 6290 | spin_lock_bh(&rdev->bss_lock); |
| 6291 | cfg80211_bss_expire(rdev); |
| 6292 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 6293 | cb->seq = rdev->bss_generation; |
| 6294 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6295 | list_for_each_entry(scan, &rdev->bss_list, list) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6296 | if (++idx <= start) |
| 6297 | continue; |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 6298 | if (nl80211_send_bss(skb, cb, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6299 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6300 | rdev, wdev, scan) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6301 | idx--; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 6302 | break; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6303 | } |
| 6304 | } |
| 6305 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6306 | spin_unlock_bh(&rdev->bss_lock); |
| 6307 | wdev_unlock(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6308 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6309 | cb->args[2] = idx; |
| 6310 | nl80211_finish_wdev_dump(rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6311 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 6312 | return skb->len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6313 | } |
| 6314 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6315 | 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] | 6316 | int flags, struct net_device *dev, |
| 6317 | struct survey_info *survey) |
| 6318 | { |
| 6319 | void *hdr; |
| 6320 | struct nlattr *infoattr; |
| 6321 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6322 | hdr = nl80211hdr_put(msg, portid, seq, flags, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6323 | NL80211_CMD_NEW_SURVEY_RESULTS); |
| 6324 | if (!hdr) |
| 6325 | return -ENOMEM; |
| 6326 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6327 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
| 6328 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6329 | |
| 6330 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); |
| 6331 | if (!infoattr) |
| 6332 | goto nla_put_failure; |
| 6333 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6334 | if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY, |
| 6335 | survey->channel->center_freq)) |
| 6336 | goto nla_put_failure; |
| 6337 | |
| 6338 | if ((survey->filled & SURVEY_INFO_NOISE_DBM) && |
| 6339 | nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise)) |
| 6340 | goto nla_put_failure; |
| 6341 | if ((survey->filled & SURVEY_INFO_IN_USE) && |
| 6342 | nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE)) |
| 6343 | goto nla_put_failure; |
| 6344 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) && |
| 6345 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME, |
| 6346 | survey->channel_time)) |
| 6347 | goto nla_put_failure; |
| 6348 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) && |
| 6349 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY, |
| 6350 | survey->channel_time_busy)) |
| 6351 | goto nla_put_failure; |
| 6352 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) && |
| 6353 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY, |
| 6354 | survey->channel_time_ext_busy)) |
| 6355 | goto nla_put_failure; |
| 6356 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) && |
| 6357 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX, |
| 6358 | survey->channel_time_rx)) |
| 6359 | goto nla_put_failure; |
| 6360 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) && |
| 6361 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX, |
| 6362 | survey->channel_time_tx)) |
| 6363 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6364 | |
| 6365 | nla_nest_end(msg, infoattr); |
| 6366 | |
| 6367 | return genlmsg_end(msg, hdr); |
| 6368 | |
| 6369 | nla_put_failure: |
| 6370 | genlmsg_cancel(msg, hdr); |
| 6371 | return -EMSGSIZE; |
| 6372 | } |
| 6373 | |
| 6374 | static int nl80211_dump_survey(struct sk_buff *skb, |
| 6375 | struct netlink_callback *cb) |
| 6376 | { |
| 6377 | struct survey_info survey; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 6378 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6379 | struct wireless_dev *wdev; |
| 6380 | int survey_idx = cb->args[2]; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6381 | int res; |
| 6382 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 6383 | res = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 6384 | if (res) |
| 6385 | return res; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6386 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6387 | if (!wdev->netdev) { |
| 6388 | res = -EINVAL; |
| 6389 | goto out_err; |
| 6390 | } |
| 6391 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 6392 | if (!rdev->ops->dump_survey) { |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6393 | res = -EOPNOTSUPP; |
| 6394 | goto out_err; |
| 6395 | } |
| 6396 | |
| 6397 | while (1) { |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 6398 | struct ieee80211_channel *chan; |
| 6399 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 6400 | res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6401 | if (res == -ENOENT) |
| 6402 | break; |
| 6403 | if (res) |
| 6404 | goto out_err; |
| 6405 | |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 6406 | /* Survey without a channel doesn't make sense */ |
| 6407 | if (!survey.channel) { |
| 6408 | res = -EINVAL; |
| 6409 | goto out; |
| 6410 | } |
| 6411 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 6412 | chan = ieee80211_get_channel(&rdev->wiphy, |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 6413 | survey.channel->center_freq); |
| 6414 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) { |
| 6415 | survey_idx++; |
| 6416 | continue; |
| 6417 | } |
| 6418 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6419 | if (nl80211_send_survey(skb, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6420 | NETLINK_CB(cb->skb).portid, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6421 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6422 | wdev->netdev, &survey) < 0) |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6423 | goto out; |
| 6424 | survey_idx++; |
| 6425 | } |
| 6426 | |
| 6427 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6428 | cb->args[2] = survey_idx; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6429 | res = skb->len; |
| 6430 | out_err: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 6431 | nl80211_finish_wdev_dump(rdev); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6432 | return res; |
| 6433 | } |
| 6434 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6435 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
| 6436 | { |
| 6437 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | |
| 6438 | NL80211_WPA_VERSION_2)); |
| 6439 | } |
| 6440 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6441 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
| 6442 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6443 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6444 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6445 | struct ieee80211_channel *chan; |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 6446 | const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL; |
| 6447 | int err, ssid_len, ie_len = 0, sae_data_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6448 | enum nl80211_auth_type auth_type; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6449 | struct key_parse key; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6450 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6451 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6452 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6453 | return -EINVAL; |
| 6454 | |
| 6455 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6456 | return -EINVAL; |
| 6457 | |
Jouni Malinen | 1778092 | 2009-03-27 20:52:47 +0200 | [diff] [blame] | 6458 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
| 6459 | return -EINVAL; |
| 6460 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6461 | if (!info->attrs[NL80211_ATTR_SSID]) |
| 6462 | return -EINVAL; |
| 6463 | |
| 6464 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 6465 | return -EINVAL; |
| 6466 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6467 | err = nl80211_parse_key(info, &key); |
| 6468 | if (err) |
| 6469 | return err; |
| 6470 | |
| 6471 | if (key.idx >= 0) { |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 6472 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
| 6473 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6474 | if (!key.p.key || !key.p.key_len) |
| 6475 | return -EINVAL; |
| 6476 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || |
| 6477 | key.p.key_len != WLAN_KEY_LEN_WEP40) && |
| 6478 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || |
| 6479 | key.p.key_len != WLAN_KEY_LEN_WEP104)) |
| 6480 | return -EINVAL; |
| 6481 | if (key.idx > 4) |
| 6482 | return -EINVAL; |
| 6483 | } else { |
| 6484 | key.p.key_len = 0; |
| 6485 | key.p.key = NULL; |
| 6486 | } |
| 6487 | |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 6488 | if (key.idx >= 0) { |
| 6489 | int i; |
| 6490 | bool ok = false; |
| 6491 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { |
| 6492 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { |
| 6493 | ok = true; |
| 6494 | break; |
| 6495 | } |
| 6496 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6497 | if (!ok) |
| 6498 | return -EINVAL; |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 6499 | } |
| 6500 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6501 | if (!rdev->ops->auth) |
| 6502 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6503 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6504 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6505 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6506 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6507 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6508 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 6509 | chan = nl80211_get_valid_chan(&rdev->wiphy, |
| 6510 | info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 6511 | if (!chan) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6512 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6513 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6514 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 6515 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 6516 | |
| 6517 | if (info->attrs[NL80211_ATTR_IE]) { |
| 6518 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6519 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 6520 | } |
| 6521 | |
| 6522 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 6523 | if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6524 | return -EINVAL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6525 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 6526 | if (auth_type == NL80211_AUTHTYPE_SAE && |
| 6527 | !info->attrs[NL80211_ATTR_SAE_DATA]) |
| 6528 | return -EINVAL; |
| 6529 | |
| 6530 | if (info->attrs[NL80211_ATTR_SAE_DATA]) { |
| 6531 | if (auth_type != NL80211_AUTHTYPE_SAE) |
| 6532 | return -EINVAL; |
| 6533 | sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]); |
| 6534 | sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]); |
| 6535 | /* need to include at least Auth Transaction and Status Code */ |
| 6536 | if (sae_data_len < 4) |
| 6537 | return -EINVAL; |
| 6538 | } |
| 6539 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6540 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 6541 | |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 6542 | /* |
| 6543 | * Since we no longer track auth state, ignore |
| 6544 | * requests to only change local state. |
| 6545 | */ |
| 6546 | if (local_state_change) |
| 6547 | return 0; |
| 6548 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6549 | wdev_lock(dev->ieee80211_ptr); |
| 6550 | err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, |
| 6551 | ssid, ssid_len, ie, ie_len, |
| 6552 | key.p.key, key.p.key_len, key.idx, |
| 6553 | sae_data, sae_data_len); |
| 6554 | wdev_unlock(dev->ieee80211_ptr); |
| 6555 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6556 | } |
| 6557 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 6558 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 6559 | struct genl_info *info, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 6560 | struct cfg80211_crypto_settings *settings, |
| 6561 | int cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6562 | { |
Johannes Berg | c0b2bbd | 2009-07-25 16:54:36 +0200 | [diff] [blame] | 6563 | memset(settings, 0, sizeof(*settings)); |
| 6564 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6565 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
| 6566 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 6567 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
| 6568 | u16 proto; |
| 6569 | proto = nla_get_u16( |
| 6570 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); |
| 6571 | settings->control_port_ethertype = cpu_to_be16(proto); |
| 6572 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 6573 | proto != ETH_P_PAE) |
| 6574 | return -EINVAL; |
| 6575 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) |
| 6576 | settings->control_port_no_encrypt = true; |
| 6577 | } else |
| 6578 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); |
| 6579 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6580 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
| 6581 | void *data; |
| 6582 | int len, i; |
| 6583 | |
| 6584 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 6585 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 6586 | settings->n_ciphers_pairwise = len / sizeof(u32); |
| 6587 | |
| 6588 | if (len % sizeof(u32)) |
| 6589 | return -EINVAL; |
| 6590 | |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 6591 | if (settings->n_ciphers_pairwise > cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6592 | return -EINVAL; |
| 6593 | |
| 6594 | memcpy(settings->ciphers_pairwise, data, len); |
| 6595 | |
| 6596 | for (i = 0; i < settings->n_ciphers_pairwise; i++) |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 6597 | if (!cfg80211_supported_cipher_suite( |
| 6598 | &rdev->wiphy, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6599 | settings->ciphers_pairwise[i])) |
| 6600 | return -EINVAL; |
| 6601 | } |
| 6602 | |
| 6603 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { |
| 6604 | settings->cipher_group = |
| 6605 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 6606 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
| 6607 | settings->cipher_group)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6608 | return -EINVAL; |
| 6609 | } |
| 6610 | |
| 6611 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { |
| 6612 | settings->wpa_versions = |
| 6613 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); |
| 6614 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) |
| 6615 | return -EINVAL; |
| 6616 | } |
| 6617 | |
| 6618 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { |
| 6619 | void *data; |
Jouni Malinen | 6d30240 | 2011-09-21 18:11:33 +0300 | [diff] [blame] | 6620 | int len; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6621 | |
| 6622 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 6623 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 6624 | settings->n_akm_suites = len / sizeof(u32); |
| 6625 | |
| 6626 | if (len % sizeof(u32)) |
| 6627 | return -EINVAL; |
| 6628 | |
Jouni Malinen | 1b9ca02 | 2011-09-21 16:13:07 +0300 | [diff] [blame] | 6629 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) |
| 6630 | return -EINVAL; |
| 6631 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6632 | memcpy(settings->akm_suites, data, len); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6633 | } |
| 6634 | |
| 6635 | return 0; |
| 6636 | } |
| 6637 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6638 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
| 6639 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6640 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6641 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 6642 | struct ieee80211_channel *chan; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6643 | struct cfg80211_assoc_request req = {}; |
| 6644 | const u8 *bssid, *ssid; |
| 6645 | int err, ssid_len = 0; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6646 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6647 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6648 | return -EINVAL; |
| 6649 | |
| 6650 | if (!info->attrs[NL80211_ATTR_MAC] || |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6651 | !info->attrs[NL80211_ATTR_SSID] || |
| 6652 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6653 | return -EINVAL; |
| 6654 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6655 | if (!rdev->ops->assoc) |
| 6656 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6657 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6658 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6659 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6660 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6661 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6662 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6663 | |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 6664 | chan = nl80211_get_valid_chan(&rdev->wiphy, |
| 6665 | info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 6666 | if (!chan) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6667 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6668 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6669 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 6670 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6671 | |
| 6672 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6673 | req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6674 | req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6675 | } |
| 6676 | |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 6677 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 6678 | enum nl80211_mfp mfp = |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 6679 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 6680 | if (mfp == NL80211_MFP_REQUIRED) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6681 | req.use_mfp = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6682 | else if (mfp != NL80211_MFP_NO) |
| 6683 | return -EINVAL; |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 6684 | } |
| 6685 | |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 6686 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6687 | req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 6688 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6689 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6690 | req.flags |= ASSOC_REQ_DISABLE_HT; |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6691 | |
| 6692 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6693 | memcpy(&req.ht_capa_mask, |
| 6694 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 6695 | sizeof(req.ht_capa_mask)); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6696 | |
| 6697 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6698 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6699 | return -EINVAL; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6700 | memcpy(&req.ht_capa, |
| 6701 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 6702 | sizeof(req.ht_capa)); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6703 | } |
| 6704 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6705 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6706 | req.flags |= ASSOC_REQ_DISABLE_VHT; |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6707 | |
| 6708 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6709 | memcpy(&req.vht_capa_mask, |
| 6710 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), |
| 6711 | sizeof(req.vht_capa_mask)); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6712 | |
| 6713 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6714 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6715 | return -EINVAL; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6716 | memcpy(&req.vht_capa, |
| 6717 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), |
| 6718 | sizeof(req.vht_capa)); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6719 | } |
| 6720 | |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 6721 | if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) { |
| 6722 | if (!(rdev->wiphy.features & |
| 6723 | NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) || |
| 6724 | !(rdev->wiphy.features & NL80211_FEATURE_QUIET)) |
| 6725 | return -EINVAL; |
| 6726 | req.flags |= ASSOC_REQ_USE_RRM; |
| 6727 | } |
| 6728 | |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6729 | err = nl80211_crypto_settings(rdev, info, &req.crypto, 1); |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6730 | if (!err) { |
| 6731 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6732 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, |
| 6733 | ssid, ssid_len, &req); |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6734 | wdev_unlock(dev->ieee80211_ptr); |
| 6735 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6736 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6737 | return err; |
| 6738 | } |
| 6739 | |
| 6740 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) |
| 6741 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6742 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6743 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6744 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6745 | int ie_len = 0, err; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6746 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6747 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6748 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6749 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6750 | return -EINVAL; |
| 6751 | |
| 6752 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6753 | return -EINVAL; |
| 6754 | |
| 6755 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 6756 | return -EINVAL; |
| 6757 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6758 | if (!rdev->ops->deauth) |
| 6759 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6760 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6761 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6762 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6763 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6764 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6765 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6766 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6767 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 6768 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6769 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6770 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 6771 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6772 | |
| 6773 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6774 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6775 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6776 | } |
| 6777 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6778 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 6779 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6780 | wdev_lock(dev->ieee80211_ptr); |
| 6781 | err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, |
| 6782 | local_state_change); |
| 6783 | wdev_unlock(dev->ieee80211_ptr); |
| 6784 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6785 | } |
| 6786 | |
| 6787 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) |
| 6788 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6789 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6790 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6791 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6792 | int ie_len = 0, err; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6793 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6794 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6795 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6796 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6797 | return -EINVAL; |
| 6798 | |
| 6799 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6800 | return -EINVAL; |
| 6801 | |
| 6802 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 6803 | return -EINVAL; |
| 6804 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6805 | if (!rdev->ops->disassoc) |
| 6806 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6807 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6808 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6809 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6810 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6811 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6812 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6813 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6814 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 6815 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6816 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6817 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 6818 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6819 | |
| 6820 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6821 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6822 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6823 | } |
| 6824 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6825 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 6826 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6827 | wdev_lock(dev->ieee80211_ptr); |
| 6828 | err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, |
| 6829 | local_state_change); |
| 6830 | wdev_unlock(dev->ieee80211_ptr); |
| 6831 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6832 | } |
| 6833 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 6834 | static bool |
| 6835 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, |
| 6836 | int mcast_rate[IEEE80211_NUM_BANDS], |
| 6837 | int rateval) |
| 6838 | { |
| 6839 | struct wiphy *wiphy = &rdev->wiphy; |
| 6840 | bool found = false; |
| 6841 | int band, i; |
| 6842 | |
| 6843 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 6844 | struct ieee80211_supported_band *sband; |
| 6845 | |
| 6846 | sband = wiphy->bands[band]; |
| 6847 | if (!sband) |
| 6848 | continue; |
| 6849 | |
| 6850 | for (i = 0; i < sband->n_bitrates; i++) { |
| 6851 | if (sband->bitrates[i].bitrate == rateval) { |
| 6852 | mcast_rate[band] = i + 1; |
| 6853 | found = true; |
| 6854 | break; |
| 6855 | } |
| 6856 | } |
| 6857 | } |
| 6858 | |
| 6859 | return found; |
| 6860 | } |
| 6861 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6862 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
| 6863 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6864 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6865 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6866 | struct cfg80211_ibss_params ibss; |
| 6867 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6868 | struct cfg80211_cached_keys *connkeys = NULL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6869 | int err; |
| 6870 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 6871 | memset(&ibss, 0, sizeof(ibss)); |
| 6872 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6873 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6874 | return -EINVAL; |
| 6875 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6876 | if (!info->attrs[NL80211_ATTR_SSID] || |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6877 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 6878 | return -EINVAL; |
| 6879 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 6880 | ibss.beacon_interval = 100; |
| 6881 | |
| 6882 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 6883 | ibss.beacon_interval = |
| 6884 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 6885 | if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000) |
| 6886 | return -EINVAL; |
| 6887 | } |
| 6888 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6889 | if (!rdev->ops->join_ibss) |
| 6890 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6891 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6892 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 6893 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6894 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 6895 | wiphy = &rdev->wiphy; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6896 | |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 6897 | if (info->attrs[NL80211_ATTR_MAC]) { |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6898 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 6899 | |
| 6900 | if (!is_valid_ether_addr(ibss.bssid)) |
| 6901 | return -EINVAL; |
| 6902 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6903 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 6904 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 6905 | |
| 6906 | if (info->attrs[NL80211_ATTR_IE]) { |
| 6907 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6908 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 6909 | } |
| 6910 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6911 | err = nl80211_parse_chandef(rdev, info, &ibss.chandef); |
| 6912 | if (err) |
| 6913 | return err; |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 6914 | |
Ilan Peer | 174e0cd | 2014-02-23 09:13:01 +0200 | [diff] [blame] | 6915 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef, |
| 6916 | NL80211_IFTYPE_ADHOC)) |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 6917 | return -EINVAL; |
| 6918 | |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 6919 | switch (ibss.chandef.width) { |
Simon Wunderlich | bf37264 | 2013-07-08 16:55:58 +0200 | [diff] [blame] | 6920 | case NL80211_CHAN_WIDTH_5: |
| 6921 | case NL80211_CHAN_WIDTH_10: |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 6922 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 6923 | break; |
| 6924 | case NL80211_CHAN_WIDTH_20: |
| 6925 | case NL80211_CHAN_WIDTH_40: |
| 6926 | if (rdev->wiphy.features & NL80211_FEATURE_HT_IBSS) |
| 6927 | break; |
| 6928 | default: |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 6929 | return -EINVAL; |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 6930 | } |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 6931 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6932 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6933 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6934 | |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 6935 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 6936 | u8 *rates = |
| 6937 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 6938 | int n_rates = |
| 6939 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 6940 | struct ieee80211_supported_band *sband = |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6941 | wiphy->bands[ibss.chandef.chan->band]; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 6942 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 6943 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 6944 | &ibss.basic_rates); |
| 6945 | if (err) |
| 6946 | return err; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 6947 | } |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 6948 | |
Simon Wunderlich | 803768f | 2013-06-28 10:39:58 +0200 | [diff] [blame] | 6949 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 6950 | memcpy(&ibss.ht_capa_mask, |
| 6951 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 6952 | sizeof(ibss.ht_capa_mask)); |
| 6953 | |
| 6954 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
| 6955 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 6956 | return -EINVAL; |
| 6957 | memcpy(&ibss.ht_capa, |
| 6958 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 6959 | sizeof(ibss.ht_capa)); |
| 6960 | } |
| 6961 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 6962 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 6963 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, |
| 6964 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 6965 | return -EINVAL; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 6966 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6967 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6968 | bool no_ht = false; |
| 6969 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6970 | connkeys = nl80211_parse_connkeys(rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6971 | info->attrs[NL80211_ATTR_KEYS], |
| 6972 | &no_ht); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6973 | if (IS_ERR(connkeys)) |
| 6974 | return PTR_ERR(connkeys); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6975 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 6976 | if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) && |
| 6977 | no_ht) { |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6978 | kfree(connkeys); |
| 6979 | return -EINVAL; |
| 6980 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6981 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6982 | |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 6983 | ibss.control_port = |
| 6984 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]); |
| 6985 | |
Simon Wunderlich | 5336fa8 | 2013-10-07 18:41:05 +0200 | [diff] [blame] | 6986 | ibss.userspace_handles_dfs = |
| 6987 | nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]); |
| 6988 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6989 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6990 | if (err) |
Johannes Berg | b47f610 | 2014-09-10 13:39:54 +0300 | [diff] [blame] | 6991 | kzfree(connkeys); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6992 | return err; |
| 6993 | } |
| 6994 | |
| 6995 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) |
| 6996 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6997 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6998 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6999 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7000 | if (!rdev->ops->leave_ibss) |
| 7001 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7002 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7003 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 7004 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7005 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7006 | return cfg80211_leave_ibss(rdev, dev, false); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7007 | } |
| 7008 | |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 7009 | static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info) |
| 7010 | { |
| 7011 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7012 | struct net_device *dev = info->user_ptr[1]; |
| 7013 | int mcast_rate[IEEE80211_NUM_BANDS]; |
| 7014 | u32 nla_rate; |
| 7015 | int err; |
| 7016 | |
| 7017 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
| 7018 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 7019 | return -EOPNOTSUPP; |
| 7020 | |
| 7021 | if (!rdev->ops->set_mcast_rate) |
| 7022 | return -EOPNOTSUPP; |
| 7023 | |
| 7024 | memset(mcast_rate, 0, sizeof(mcast_rate)); |
| 7025 | |
| 7026 | if (!info->attrs[NL80211_ATTR_MCAST_RATE]) |
| 7027 | return -EINVAL; |
| 7028 | |
| 7029 | nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]); |
| 7030 | if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate)) |
| 7031 | return -EINVAL; |
| 7032 | |
| 7033 | err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate); |
| 7034 | |
| 7035 | return err; |
| 7036 | } |
| 7037 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 7038 | static struct sk_buff * |
| 7039 | __cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev, |
| 7040 | int approxlen, u32 portid, u32 seq, |
| 7041 | enum nl80211_commands cmd, |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 7042 | enum nl80211_attrs attr, |
| 7043 | const struct nl80211_vendor_cmd_info *info, |
| 7044 | gfp_t gfp) |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 7045 | { |
| 7046 | struct sk_buff *skb; |
| 7047 | void *hdr; |
| 7048 | struct nlattr *data; |
| 7049 | |
| 7050 | skb = nlmsg_new(approxlen + 100, gfp); |
| 7051 | if (!skb) |
| 7052 | return NULL; |
| 7053 | |
| 7054 | hdr = nl80211hdr_put(skb, portid, seq, 0, cmd); |
| 7055 | if (!hdr) { |
| 7056 | kfree_skb(skb); |
| 7057 | return NULL; |
| 7058 | } |
| 7059 | |
| 7060 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 7061 | goto nla_put_failure; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 7062 | |
| 7063 | if (info) { |
| 7064 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID, |
| 7065 | info->vendor_id)) |
| 7066 | goto nla_put_failure; |
| 7067 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD, |
| 7068 | info->subcmd)) |
| 7069 | goto nla_put_failure; |
| 7070 | } |
| 7071 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 7072 | data = nla_nest_start(skb, attr); |
| 7073 | |
| 7074 | ((void **)skb->cb)[0] = rdev; |
| 7075 | ((void **)skb->cb)[1] = hdr; |
| 7076 | ((void **)skb->cb)[2] = data; |
| 7077 | |
| 7078 | return skb; |
| 7079 | |
| 7080 | nla_put_failure: |
| 7081 | kfree_skb(skb); |
| 7082 | return NULL; |
| 7083 | } |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 7084 | |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 7085 | struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy, |
| 7086 | enum nl80211_commands cmd, |
| 7087 | enum nl80211_attrs attr, |
| 7088 | int vendor_event_idx, |
| 7089 | int approxlen, gfp_t gfp) |
| 7090 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 7091 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 7092 | const struct nl80211_vendor_cmd_info *info; |
| 7093 | |
| 7094 | switch (cmd) { |
| 7095 | case NL80211_CMD_TESTMODE: |
| 7096 | if (WARN_ON(vendor_event_idx != -1)) |
| 7097 | return NULL; |
| 7098 | info = NULL; |
| 7099 | break; |
| 7100 | case NL80211_CMD_VENDOR: |
| 7101 | if (WARN_ON(vendor_event_idx < 0 || |
| 7102 | vendor_event_idx >= wiphy->n_vendor_events)) |
| 7103 | return NULL; |
| 7104 | info = &wiphy->vendor_events[vendor_event_idx]; |
| 7105 | break; |
| 7106 | default: |
| 7107 | WARN_ON(1); |
| 7108 | return NULL; |
| 7109 | } |
| 7110 | |
| 7111 | return __cfg80211_alloc_vendor_skb(rdev, approxlen, 0, 0, |
| 7112 | cmd, attr, info, gfp); |
| 7113 | } |
| 7114 | EXPORT_SYMBOL(__cfg80211_alloc_event_skb); |
| 7115 | |
| 7116 | void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp) |
| 7117 | { |
| 7118 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 7119 | void *hdr = ((void **)skb->cb)[1]; |
| 7120 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 7121 | enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE; |
| 7122 | |
Johannes Berg | bd8c78e | 2014-07-30 14:55:26 +0200 | [diff] [blame] | 7123 | /* clear CB data for netlink core to own from now on */ |
| 7124 | memset(skb->cb, 0, sizeof(skb->cb)); |
| 7125 | |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 7126 | nla_nest_end(skb, data); |
| 7127 | genlmsg_end(skb, hdr); |
| 7128 | |
| 7129 | if (data->nla_type == NL80211_ATTR_VENDOR_DATA) |
| 7130 | mcgrp = NL80211_MCGRP_VENDOR; |
| 7131 | |
| 7132 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0, |
| 7133 | mcgrp, gfp); |
| 7134 | } |
| 7135 | EXPORT_SYMBOL(__cfg80211_send_event_skb); |
| 7136 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7137 | #ifdef CONFIG_NL80211_TESTMODE |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7138 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
| 7139 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7140 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 7141 | struct wireless_dev *wdev = |
| 7142 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7143 | int err; |
| 7144 | |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 7145 | if (!rdev->ops->testmode_cmd) |
| 7146 | return -EOPNOTSUPP; |
| 7147 | |
| 7148 | if (IS_ERR(wdev)) { |
| 7149 | err = PTR_ERR(wdev); |
| 7150 | if (err != -EINVAL) |
| 7151 | return err; |
| 7152 | wdev = NULL; |
| 7153 | } else if (wdev->wiphy != &rdev->wiphy) { |
| 7154 | return -EINVAL; |
| 7155 | } |
| 7156 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7157 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
| 7158 | return -EINVAL; |
| 7159 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 7160 | rdev->cur_cmd_info = info; |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 7161 | err = rdev_testmode_cmd(rdev, wdev, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7162 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
| 7163 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 7164 | rdev->cur_cmd_info = NULL; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7165 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7166 | return err; |
| 7167 | } |
| 7168 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7169 | static int nl80211_testmode_dump(struct sk_buff *skb, |
| 7170 | struct netlink_callback *cb) |
| 7171 | { |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 7172 | struct cfg80211_registered_device *rdev; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7173 | int err; |
| 7174 | long phy_idx; |
| 7175 | void *data = NULL; |
| 7176 | int data_len = 0; |
| 7177 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 7178 | rtnl_lock(); |
| 7179 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7180 | if (cb->args[0]) { |
| 7181 | /* |
| 7182 | * 0 is a valid index, but not valid for args[0], |
| 7183 | * so we need to offset by 1. |
| 7184 | */ |
| 7185 | phy_idx = cb->args[0] - 1; |
| 7186 | } else { |
| 7187 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 7188 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 7189 | nl80211_policy); |
| 7190 | if (err) |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 7191 | goto out_err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 7192 | |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 7193 | rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), |
| 7194 | nl80211_fam.attrbuf); |
| 7195 | if (IS_ERR(rdev)) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 7196 | err = PTR_ERR(rdev); |
| 7197 | goto out_err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 7198 | } |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 7199 | phy_idx = rdev->wiphy_idx; |
| 7200 | rdev = NULL; |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 7201 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7202 | if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]) |
| 7203 | cb->args[1] = |
| 7204 | (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]; |
| 7205 | } |
| 7206 | |
| 7207 | if (cb->args[1]) { |
| 7208 | data = nla_data((void *)cb->args[1]); |
| 7209 | data_len = nla_len((void *)cb->args[1]); |
| 7210 | } |
| 7211 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 7212 | rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
| 7213 | if (!rdev) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 7214 | err = -ENOENT; |
| 7215 | goto out_err; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7216 | } |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7217 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 7218 | if (!rdev->ops->testmode_dump) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7219 | err = -EOPNOTSUPP; |
| 7220 | goto out_err; |
| 7221 | } |
| 7222 | |
| 7223 | while (1) { |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7224 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7225 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 7226 | NL80211_CMD_TESTMODE); |
| 7227 | struct nlattr *tmdata; |
| 7228 | |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 7229 | if (!hdr) |
| 7230 | break; |
| 7231 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7232 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7233 | genlmsg_cancel(skb, hdr); |
| 7234 | break; |
| 7235 | } |
| 7236 | |
| 7237 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 7238 | if (!tmdata) { |
| 7239 | genlmsg_cancel(skb, hdr); |
| 7240 | break; |
| 7241 | } |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7242 | err = rdev_testmode_dump(rdev, skb, cb, data, data_len); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7243 | nla_nest_end(skb, tmdata); |
| 7244 | |
| 7245 | if (err == -ENOBUFS || err == -ENOENT) { |
| 7246 | genlmsg_cancel(skb, hdr); |
| 7247 | break; |
| 7248 | } else if (err) { |
| 7249 | genlmsg_cancel(skb, hdr); |
| 7250 | goto out_err; |
| 7251 | } |
| 7252 | |
| 7253 | genlmsg_end(skb, hdr); |
| 7254 | } |
| 7255 | |
| 7256 | err = skb->len; |
| 7257 | /* see above */ |
| 7258 | cb->args[0] = phy_idx + 1; |
| 7259 | out_err: |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 7260 | rtnl_unlock(); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7261 | return err; |
| 7262 | } |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7263 | #endif |
| 7264 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7265 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
| 7266 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7267 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7268 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7269 | struct cfg80211_connect_params connect; |
| 7270 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7271 | struct cfg80211_cached_keys *connkeys = NULL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7272 | int err; |
| 7273 | |
| 7274 | memset(&connect, 0, sizeof(connect)); |
| 7275 | |
| 7276 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 7277 | return -EINVAL; |
| 7278 | |
| 7279 | if (!info->attrs[NL80211_ATTR_SSID] || |
| 7280 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 7281 | return -EINVAL; |
| 7282 | |
| 7283 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 7284 | connect.auth_type = |
| 7285 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 7286 | if (!nl80211_valid_auth_type(rdev, connect.auth_type, |
| 7287 | NL80211_CMD_CONNECT)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7288 | return -EINVAL; |
| 7289 | } else |
| 7290 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 7291 | |
| 7292 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; |
| 7293 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 7294 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 7295 | NL80211_MAX_NR_CIPHER_SUITES); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7296 | if (err) |
| 7297 | return err; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7298 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7299 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7300 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7301 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7302 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 7303 | wiphy = &rdev->wiphy; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7304 | |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 7305 | connect.bg_scan_period = -1; |
| 7306 | if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] && |
| 7307 | (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) { |
| 7308 | connect.bg_scan_period = |
| 7309 | nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]); |
| 7310 | } |
| 7311 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7312 | if (info->attrs[NL80211_ATTR_MAC]) |
| 7313 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 7314 | else if (info->attrs[NL80211_ATTR_MAC_HINT]) |
| 7315 | connect.bssid_hint = |
| 7316 | nla_data(info->attrs[NL80211_ATTR_MAC_HINT]); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7317 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 7318 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 7319 | |
| 7320 | if (info->attrs[NL80211_ATTR_IE]) { |
| 7321 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 7322 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 7323 | } |
| 7324 | |
Jouni Malinen | cee00a9 | 2013-01-15 17:15:57 +0200 | [diff] [blame] | 7325 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
| 7326 | connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
| 7327 | if (connect.mfp != NL80211_MFP_REQUIRED && |
| 7328 | connect.mfp != NL80211_MFP_NO) |
| 7329 | return -EINVAL; |
| 7330 | } else { |
| 7331 | connect.mfp = NL80211_MFP_NO; |
| 7332 | } |
| 7333 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7334 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 7335 | connect.channel = nl80211_get_valid_chan( |
| 7336 | wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 7337 | if (!connect.channel) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7338 | return -EINVAL; |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 7339 | } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) { |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 7340 | connect.channel_hint = nl80211_get_valid_chan( |
| 7341 | wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]); |
| 7342 | if (!connect.channel_hint) |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 7343 | return -EINVAL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7344 | } |
| 7345 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7346 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
| 7347 | connkeys = nl80211_parse_connkeys(rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 7348 | info->attrs[NL80211_ATTR_KEYS], NULL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7349 | if (IS_ERR(connkeys)) |
| 7350 | return PTR_ERR(connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7351 | } |
| 7352 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 7353 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
| 7354 | connect.flags |= ASSOC_REQ_DISABLE_HT; |
| 7355 | |
| 7356 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 7357 | memcpy(&connect.ht_capa_mask, |
| 7358 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 7359 | sizeof(connect.ht_capa_mask)); |
| 7360 | |
| 7361 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 7362 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) { |
Johannes Berg | b47f610 | 2014-09-10 13:39:54 +0300 | [diff] [blame] | 7363 | kzfree(connkeys); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 7364 | return -EINVAL; |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 7365 | } |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 7366 | memcpy(&connect.ht_capa, |
| 7367 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 7368 | sizeof(connect.ht_capa)); |
| 7369 | } |
| 7370 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 7371 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
| 7372 | connect.flags |= ASSOC_REQ_DISABLE_VHT; |
| 7373 | |
| 7374 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
| 7375 | memcpy(&connect.vht_capa_mask, |
| 7376 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), |
| 7377 | sizeof(connect.vht_capa_mask)); |
| 7378 | |
| 7379 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { |
| 7380 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) { |
Johannes Berg | b47f610 | 2014-09-10 13:39:54 +0300 | [diff] [blame] | 7381 | kzfree(connkeys); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 7382 | return -EINVAL; |
| 7383 | } |
| 7384 | memcpy(&connect.vht_capa, |
| 7385 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), |
| 7386 | sizeof(connect.vht_capa)); |
| 7387 | } |
| 7388 | |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 7389 | if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) { |
| 7390 | if (!(rdev->wiphy.features & |
| 7391 | NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) || |
| 7392 | !(rdev->wiphy.features & NL80211_FEATURE_QUIET)) |
| 7393 | return -EINVAL; |
| 7394 | connect.flags |= ASSOC_REQ_USE_RRM; |
| 7395 | } |
| 7396 | |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7397 | wdev_lock(dev->ieee80211_ptr); |
| 7398 | err = cfg80211_connect(rdev, dev, &connect, connkeys, NULL); |
| 7399 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7400 | if (err) |
Johannes Berg | b47f610 | 2014-09-10 13:39:54 +0300 | [diff] [blame] | 7401 | kzfree(connkeys); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7402 | return err; |
| 7403 | } |
| 7404 | |
| 7405 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) |
| 7406 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7407 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7408 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7409 | u16 reason; |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7410 | int ret; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7411 | |
| 7412 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 7413 | reason = WLAN_REASON_DEAUTH_LEAVING; |
| 7414 | else |
| 7415 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 7416 | |
| 7417 | if (reason == 0) |
| 7418 | return -EINVAL; |
| 7419 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7420 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7421 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7422 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7423 | |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7424 | wdev_lock(dev->ieee80211_ptr); |
| 7425 | ret = cfg80211_disconnect(rdev, dev, reason, true); |
| 7426 | wdev_unlock(dev->ieee80211_ptr); |
| 7427 | return ret; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7428 | } |
| 7429 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7430 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
| 7431 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7432 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7433 | struct net *net; |
| 7434 | int err; |
| 7435 | u32 pid; |
| 7436 | |
| 7437 | if (!info->attrs[NL80211_ATTR_PID]) |
| 7438 | return -EINVAL; |
| 7439 | |
| 7440 | pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); |
| 7441 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7442 | net = get_net_ns_by_pid(pid); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7443 | if (IS_ERR(net)) |
| 7444 | return PTR_ERR(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7445 | |
| 7446 | err = 0; |
| 7447 | |
| 7448 | /* check if anything to do */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7449 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
| 7450 | err = cfg80211_switch_netns(rdev, net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7451 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7452 | put_net(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7453 | return err; |
| 7454 | } |
| 7455 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7456 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 7457 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7458 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7459 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
| 7460 | struct cfg80211_pmksa *pmksa) = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7461 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7462 | struct cfg80211_pmksa pmksa; |
| 7463 | |
| 7464 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); |
| 7465 | |
| 7466 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 7467 | return -EINVAL; |
| 7468 | |
| 7469 | if (!info->attrs[NL80211_ATTR_PMKID]) |
| 7470 | return -EINVAL; |
| 7471 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7472 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
| 7473 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 7474 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7475 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7476 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7477 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7478 | |
| 7479 | switch (info->genlhdr->cmd) { |
| 7480 | case NL80211_CMD_SET_PMKSA: |
| 7481 | rdev_ops = rdev->ops->set_pmksa; |
| 7482 | break; |
| 7483 | case NL80211_CMD_DEL_PMKSA: |
| 7484 | rdev_ops = rdev->ops->del_pmksa; |
| 7485 | break; |
| 7486 | default: |
| 7487 | WARN_ON(1); |
| 7488 | break; |
| 7489 | } |
| 7490 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7491 | if (!rdev_ops) |
| 7492 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7493 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7494 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7495 | } |
| 7496 | |
| 7497 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 7498 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7499 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7500 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7501 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7502 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7503 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7504 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7505 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7506 | if (!rdev->ops->flush_pmksa) |
| 7507 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7508 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7509 | return rdev_flush_pmksa(rdev, dev); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7510 | } |
| 7511 | |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7512 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) |
| 7513 | { |
| 7514 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7515 | struct net_device *dev = info->user_ptr[1]; |
| 7516 | u8 action_code, dialog_token; |
Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 7517 | u32 peer_capability = 0; |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7518 | u16 status_code; |
| 7519 | u8 *peer; |
Arik Nemtsov | 31fa97c | 2014-06-11 17:18:21 +0300 | [diff] [blame] | 7520 | bool initiator; |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7521 | |
| 7522 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 7523 | !rdev->ops->tdls_mgmt) |
| 7524 | return -EOPNOTSUPP; |
| 7525 | |
| 7526 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || |
| 7527 | !info->attrs[NL80211_ATTR_STATUS_CODE] || |
| 7528 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || |
| 7529 | !info->attrs[NL80211_ATTR_IE] || |
| 7530 | !info->attrs[NL80211_ATTR_MAC]) |
| 7531 | return -EINVAL; |
| 7532 | |
| 7533 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 7534 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); |
| 7535 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); |
| 7536 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); |
Arik Nemtsov | 31fa97c | 2014-06-11 17:18:21 +0300 | [diff] [blame] | 7537 | initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]); |
Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 7538 | if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]) |
| 7539 | peer_capability = |
| 7540 | nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7541 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7542 | return rdev_tdls_mgmt(rdev, dev, peer, action_code, |
Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 7543 | dialog_token, status_code, peer_capability, |
Arik Nemtsov | 31fa97c | 2014-06-11 17:18:21 +0300 | [diff] [blame] | 7544 | initiator, |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7545 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 7546 | nla_len(info->attrs[NL80211_ATTR_IE])); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7547 | } |
| 7548 | |
| 7549 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) |
| 7550 | { |
| 7551 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7552 | struct net_device *dev = info->user_ptr[1]; |
| 7553 | enum nl80211_tdls_operation operation; |
| 7554 | u8 *peer; |
| 7555 | |
| 7556 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 7557 | !rdev->ops->tdls_oper) |
| 7558 | return -EOPNOTSUPP; |
| 7559 | |
| 7560 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || |
| 7561 | !info->attrs[NL80211_ATTR_MAC]) |
| 7562 | return -EINVAL; |
| 7563 | |
| 7564 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); |
| 7565 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 7566 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7567 | return rdev_tdls_oper(rdev, dev, peer, operation); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7568 | } |
| 7569 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7570 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
| 7571 | struct genl_info *info) |
| 7572 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7573 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7574 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7575 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7576 | struct sk_buff *msg; |
| 7577 | void *hdr; |
| 7578 | u64 cookie; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7579 | u32 duration; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7580 | int err; |
| 7581 | |
| 7582 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 7583 | !info->attrs[NL80211_ATTR_DURATION]) |
| 7584 | return -EINVAL; |
| 7585 | |
| 7586 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
| 7587 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 7588 | if (!rdev->ops->remain_on_channel || |
| 7589 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7590 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7591 | |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 7592 | /* |
| 7593 | * We should be on that channel for at least a minimum amount of |
| 7594 | * time (10ms) but no longer than the driver supports. |
| 7595 | */ |
| 7596 | if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 7597 | duration > rdev->wiphy.max_remain_on_channel_duration) |
| 7598 | return -EINVAL; |
| 7599 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7600 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 7601 | if (err) |
| 7602 | return err; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7603 | |
| 7604 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7605 | if (!msg) |
| 7606 | return -ENOMEM; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7607 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7608 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7609 | NL80211_CMD_REMAIN_ON_CHANNEL); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 7610 | if (!hdr) { |
| 7611 | err = -ENOBUFS; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7612 | goto free_msg; |
| 7613 | } |
| 7614 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7615 | err = rdev_remain_on_channel(rdev, wdev, chandef.chan, |
| 7616 | duration, &cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7617 | |
| 7618 | if (err) |
| 7619 | goto free_msg; |
| 7620 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7621 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 7622 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7623 | |
| 7624 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7625 | |
| 7626 | return genlmsg_reply(msg, info); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7627 | |
| 7628 | nla_put_failure: |
| 7629 | err = -ENOBUFS; |
| 7630 | free_msg: |
| 7631 | nlmsg_free(msg); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7632 | return err; |
| 7633 | } |
| 7634 | |
| 7635 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, |
| 7636 | struct genl_info *info) |
| 7637 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7638 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7639 | struct wireless_dev *wdev = info->user_ptr[1]; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7640 | u64 cookie; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7641 | |
| 7642 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 7643 | return -EINVAL; |
| 7644 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7645 | if (!rdev->ops->cancel_remain_on_channel) |
| 7646 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7647 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7648 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 7649 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7650 | return rdev_cancel_remain_on_channel(rdev, wdev, cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7651 | } |
| 7652 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7653 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
| 7654 | u8 *rates, u8 rates_len) |
| 7655 | { |
| 7656 | u8 i; |
| 7657 | u32 mask = 0; |
| 7658 | |
| 7659 | for (i = 0; i < rates_len; i++) { |
| 7660 | int rate = (rates[i] & 0x7f) * 5; |
| 7661 | int ridx; |
| 7662 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { |
| 7663 | struct ieee80211_rate *srate = |
| 7664 | &sband->bitrates[ridx]; |
| 7665 | if (rate == srate->bitrate) { |
| 7666 | mask |= 1 << ridx; |
| 7667 | break; |
| 7668 | } |
| 7669 | } |
| 7670 | if (ridx == sband->n_bitrates) |
| 7671 | return 0; /* rate not found */ |
| 7672 | } |
| 7673 | |
| 7674 | return mask; |
| 7675 | } |
| 7676 | |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7677 | static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, |
| 7678 | u8 *rates, u8 rates_len, |
| 7679 | u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) |
| 7680 | { |
| 7681 | u8 i; |
| 7682 | |
| 7683 | memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); |
| 7684 | |
| 7685 | for (i = 0; i < rates_len; i++) { |
| 7686 | int ridx, rbit; |
| 7687 | |
| 7688 | ridx = rates[i] / 8; |
| 7689 | rbit = BIT(rates[i] % 8); |
| 7690 | |
| 7691 | /* check validity */ |
Dan Carpenter | 910570b5 | 2012-02-01 10:42:11 +0300 | [diff] [blame] | 7692 | if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7693 | return false; |
| 7694 | |
| 7695 | /* check availability */ |
| 7696 | if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) |
| 7697 | mcs[ridx] |= rbit; |
| 7698 | else |
| 7699 | return false; |
| 7700 | } |
| 7701 | |
| 7702 | return true; |
| 7703 | } |
| 7704 | |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 7705 | static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map) |
| 7706 | { |
| 7707 | u16 mcs_mask = 0; |
| 7708 | |
| 7709 | switch (vht_mcs_map) { |
| 7710 | case IEEE80211_VHT_MCS_NOT_SUPPORTED: |
| 7711 | break; |
| 7712 | case IEEE80211_VHT_MCS_SUPPORT_0_7: |
| 7713 | mcs_mask = 0x00FF; |
| 7714 | break; |
| 7715 | case IEEE80211_VHT_MCS_SUPPORT_0_8: |
| 7716 | mcs_mask = 0x01FF; |
| 7717 | break; |
| 7718 | case IEEE80211_VHT_MCS_SUPPORT_0_9: |
| 7719 | mcs_mask = 0x03FF; |
| 7720 | break; |
| 7721 | default: |
| 7722 | break; |
| 7723 | } |
| 7724 | |
| 7725 | return mcs_mask; |
| 7726 | } |
| 7727 | |
| 7728 | static void vht_build_mcs_mask(u16 vht_mcs_map, |
| 7729 | u16 vht_mcs_mask[NL80211_VHT_NSS_MAX]) |
| 7730 | { |
| 7731 | u8 nss; |
| 7732 | |
| 7733 | for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) { |
| 7734 | vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03); |
| 7735 | vht_mcs_map >>= 2; |
| 7736 | } |
| 7737 | } |
| 7738 | |
| 7739 | static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband, |
| 7740 | struct nl80211_txrate_vht *txrate, |
| 7741 | u16 mcs[NL80211_VHT_NSS_MAX]) |
| 7742 | { |
| 7743 | u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); |
| 7744 | u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {}; |
| 7745 | u8 i; |
| 7746 | |
| 7747 | if (!sband->vht_cap.vht_supported) |
| 7748 | return false; |
| 7749 | |
| 7750 | memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX); |
| 7751 | |
| 7752 | /* Build vht_mcs_mask from VHT capabilities */ |
| 7753 | vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask); |
| 7754 | |
| 7755 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) { |
| 7756 | if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i]) |
| 7757 | mcs[i] = txrate->mcs[i]; |
| 7758 | else |
| 7759 | return false; |
| 7760 | } |
| 7761 | |
| 7762 | return true; |
| 7763 | } |
| 7764 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 7765 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7766 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
| 7767 | .len = NL80211_MAX_SUPP_RATES }, |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 7768 | [NL80211_TXRATE_HT] = { .type = NLA_BINARY, |
| 7769 | .len = NL80211_MAX_SUPP_HT_RATES }, |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 7770 | [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)}, |
Janusz Dziedzic | 0b9323f | 2014-01-08 08:46:02 +0100 | [diff] [blame] | 7771 | [NL80211_TXRATE_GI] = { .type = NLA_U8 }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7772 | }; |
| 7773 | |
| 7774 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, |
| 7775 | struct genl_info *info) |
| 7776 | { |
| 7777 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7778 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7779 | struct cfg80211_bitrate_mask mask; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7780 | int rem, i; |
| 7781 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7782 | struct nlattr *tx_rates; |
| 7783 | struct ieee80211_supported_band *sband; |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 7784 | u16 vht_tx_mcs_map; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7785 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7786 | if (!rdev->ops->set_bitrate_mask) |
| 7787 | return -EOPNOTSUPP; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7788 | |
| 7789 | memset(&mask, 0, sizeof(mask)); |
| 7790 | /* Default to all rates enabled */ |
| 7791 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) { |
| 7792 | sband = rdev->wiphy.bands[i]; |
Janusz Dziedzic | 7869303 | 2013-12-03 09:50:44 +0100 | [diff] [blame] | 7793 | |
| 7794 | if (!sband) |
| 7795 | continue; |
| 7796 | |
| 7797 | mask.control[i].legacy = (1 << sband->n_bitrates) - 1; |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 7798 | memcpy(mask.control[i].ht_mcs, |
Janusz Dziedzic | 7869303 | 2013-12-03 09:50:44 +0100 | [diff] [blame] | 7799 | sband->ht_cap.mcs.rx_mask, |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 7800 | sizeof(mask.control[i].ht_mcs)); |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 7801 | |
| 7802 | if (!sband->vht_cap.vht_supported) |
| 7803 | continue; |
| 7804 | |
| 7805 | vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); |
| 7806 | 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] | 7807 | } |
| 7808 | |
Janusz Dziedzic | b9243ab | 2013-12-05 10:02:14 +0100 | [diff] [blame] | 7809 | /* if no rates are given set it back to the defaults */ |
| 7810 | if (!info->attrs[NL80211_ATTR_TX_RATES]) |
| 7811 | goto out; |
| 7812 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7813 | /* |
| 7814 | * The nested attribute uses enum nl80211_band as the index. This maps |
| 7815 | * directly to the enum ieee80211_band values used in cfg80211. |
| 7816 | */ |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7817 | 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] | 7818 | 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] | 7819 | enum ieee80211_band band = nla_type(tx_rates); |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 7820 | int err; |
| 7821 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7822 | if (band < 0 || band >= IEEE80211_NUM_BANDS) |
| 7823 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7824 | sband = rdev->wiphy.bands[band]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7825 | if (sband == NULL) |
| 7826 | return -EINVAL; |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 7827 | err = nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), |
| 7828 | nla_len(tx_rates), nl80211_txattr_policy); |
| 7829 | if (err) |
| 7830 | return err; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7831 | if (tb[NL80211_TXRATE_LEGACY]) { |
| 7832 | mask.control[band].legacy = rateset_to_mask( |
| 7833 | sband, |
| 7834 | nla_data(tb[NL80211_TXRATE_LEGACY]), |
| 7835 | nla_len(tb[NL80211_TXRATE_LEGACY])); |
Bala Shanmugam | 218d2e2 | 2012-04-20 19:12:58 +0530 | [diff] [blame] | 7836 | if ((mask.control[band].legacy == 0) && |
| 7837 | nla_len(tb[NL80211_TXRATE_LEGACY])) |
| 7838 | return -EINVAL; |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7839 | } |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 7840 | if (tb[NL80211_TXRATE_HT]) { |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7841 | if (!ht_rateset_to_mask( |
| 7842 | sband, |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 7843 | nla_data(tb[NL80211_TXRATE_HT]), |
| 7844 | nla_len(tb[NL80211_TXRATE_HT]), |
| 7845 | mask.control[band].ht_mcs)) |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7846 | return -EINVAL; |
| 7847 | } |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 7848 | if (tb[NL80211_TXRATE_VHT]) { |
| 7849 | if (!vht_set_mcs_mask( |
| 7850 | sband, |
| 7851 | nla_data(tb[NL80211_TXRATE_VHT]), |
| 7852 | mask.control[band].vht_mcs)) |
| 7853 | return -EINVAL; |
| 7854 | } |
Janusz Dziedzic | 0b9323f | 2014-01-08 08:46:02 +0100 | [diff] [blame] | 7855 | if (tb[NL80211_TXRATE_GI]) { |
| 7856 | mask.control[band].gi = |
| 7857 | nla_get_u8(tb[NL80211_TXRATE_GI]); |
| 7858 | if (mask.control[band].gi > NL80211_TXRATE_FORCE_LGI) |
| 7859 | return -EINVAL; |
| 7860 | } |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7861 | |
| 7862 | if (mask.control[band].legacy == 0) { |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 7863 | /* don't allow empty legacy rates if HT or VHT |
| 7864 | * are not even supported. |
| 7865 | */ |
| 7866 | if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported || |
| 7867 | rdev->wiphy.bands[band]->vht_cap.vht_supported)) |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7868 | return -EINVAL; |
| 7869 | |
| 7870 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 7871 | if (mask.control[band].ht_mcs[i]) |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 7872 | goto out; |
| 7873 | |
| 7874 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) |
| 7875 | if (mask.control[band].vht_mcs[i]) |
| 7876 | goto out; |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7877 | |
| 7878 | /* legacy and mcs rates may not be both empty */ |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 7879 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7880 | } |
| 7881 | } |
| 7882 | |
Janusz Dziedzic | b9243ab | 2013-12-05 10:02:14 +0100 | [diff] [blame] | 7883 | out: |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7884 | return rdev_set_bitrate_mask(rdev, dev, NULL, &mask); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7885 | } |
| 7886 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7887 | 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] | 7888 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7889 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7890 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7891 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7892 | |
| 7893 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) |
| 7894 | return -EINVAL; |
| 7895 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7896 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
| 7897 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7898 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7899 | switch (wdev->iftype) { |
| 7900 | case NL80211_IFTYPE_STATION: |
| 7901 | case NL80211_IFTYPE_ADHOC: |
| 7902 | case NL80211_IFTYPE_P2P_CLIENT: |
| 7903 | case NL80211_IFTYPE_AP: |
| 7904 | case NL80211_IFTYPE_AP_VLAN: |
| 7905 | case NL80211_IFTYPE_MESH_POINT: |
| 7906 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7907 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7908 | break; |
| 7909 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7910 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7911 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7912 | |
| 7913 | /* not much point in registering if we can't reply */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7914 | if (!rdev->ops->mgmt_tx) |
| 7915 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7916 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7917 | return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7918 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
| 7919 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7920 | } |
| 7921 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7922 | 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] | 7923 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7924 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7925 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7926 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7927 | int err; |
Johannes Berg | d64d373 | 2011-11-10 09:44:46 +0100 | [diff] [blame] | 7928 | void *hdr = NULL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7929 | u64 cookie; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7930 | struct sk_buff *msg = NULL; |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7931 | struct cfg80211_mgmt_tx_params params = { |
| 7932 | .dont_wait_for_ack = |
| 7933 | info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK], |
| 7934 | }; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7935 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7936 | if (!info->attrs[NL80211_ATTR_FRAME]) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7937 | return -EINVAL; |
| 7938 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7939 | if (!rdev->ops->mgmt_tx) |
| 7940 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7941 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7942 | switch (wdev->iftype) { |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 7943 | case NL80211_IFTYPE_P2P_DEVICE: |
| 7944 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 7945 | return -EINVAL; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7946 | case NL80211_IFTYPE_STATION: |
| 7947 | case NL80211_IFTYPE_ADHOC: |
| 7948 | case NL80211_IFTYPE_P2P_CLIENT: |
| 7949 | case NL80211_IFTYPE_AP: |
| 7950 | case NL80211_IFTYPE_AP_VLAN: |
| 7951 | case NL80211_IFTYPE_MESH_POINT: |
| 7952 | case NL80211_IFTYPE_P2P_GO: |
| 7953 | break; |
| 7954 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7955 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7956 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7957 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7958 | if (info->attrs[NL80211_ATTR_DURATION]) { |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 7959 | if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7960 | return -EINVAL; |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7961 | params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 7962 | |
| 7963 | /* |
| 7964 | * We should wait on the channel for at least a minimum amount |
| 7965 | * of time (10ms) but no longer than the driver supports. |
| 7966 | */ |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7967 | if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 7968 | params.wait > rdev->wiphy.max_remain_on_channel_duration) |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 7969 | return -EINVAL; |
| 7970 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7971 | } |
| 7972 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7973 | params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7974 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7975 | if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 7976 | return -EINVAL; |
| 7977 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7978 | 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] | 7979 | |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 7980 | /* get the channel if any has been specified, otherwise pass NULL to |
| 7981 | * the driver. The latter will use the current one |
| 7982 | */ |
| 7983 | chandef.chan = NULL; |
| 7984 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 7985 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 7986 | if (err) |
| 7987 | return err; |
| 7988 | } |
| 7989 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7990 | if (!chandef.chan && params.offchan) |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 7991 | return -EINVAL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7992 | |
Andrei Otcheretianski | 34d22ce | 2014-05-09 14:11:44 +0300 | [diff] [blame] | 7993 | params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]); |
| 7994 | params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]); |
| 7995 | |
| 7996 | if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) { |
| 7997 | int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]); |
| 7998 | int i; |
| 7999 | |
| 8000 | if (len % sizeof(u16)) |
| 8001 | return -EINVAL; |
| 8002 | |
| 8003 | params.n_csa_offsets = len / sizeof(u16); |
| 8004 | params.csa_offsets = |
| 8005 | nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]); |
| 8006 | |
| 8007 | /* check that all the offsets fit the frame */ |
| 8008 | for (i = 0; i < params.n_csa_offsets; i++) { |
| 8009 | if (params.csa_offsets[i] >= params.len) |
| 8010 | return -EINVAL; |
| 8011 | } |
| 8012 | } |
| 8013 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 8014 | if (!params.dont_wait_for_ack) { |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 8015 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 8016 | if (!msg) |
| 8017 | return -ENOMEM; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8018 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8019 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 8020 | NL80211_CMD_FRAME); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 8021 | if (!hdr) { |
| 8022 | err = -ENOBUFS; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 8023 | goto free_msg; |
| 8024 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8025 | } |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 8026 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 8027 | params.chan = chandef.chan; |
| 8028 | err = cfg80211_mlme_mgmt_tx(rdev, wdev, ¶ms, &cookie); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8029 | if (err) |
| 8030 | goto free_msg; |
| 8031 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 8032 | if (msg) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8033 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 8034 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8035 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 8036 | genlmsg_end(msg, hdr); |
| 8037 | return genlmsg_reply(msg, info); |
| 8038 | } |
| 8039 | |
| 8040 | return 0; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8041 | |
| 8042 | nla_put_failure: |
| 8043 | err = -ENOBUFS; |
| 8044 | free_msg: |
| 8045 | nlmsg_free(msg); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8046 | return err; |
| 8047 | } |
| 8048 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8049 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
| 8050 | { |
| 8051 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8052 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8053 | u64 cookie; |
| 8054 | |
| 8055 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 8056 | return -EINVAL; |
| 8057 | |
| 8058 | if (!rdev->ops->mgmt_tx_cancel_wait) |
| 8059 | return -EOPNOTSUPP; |
| 8060 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8061 | switch (wdev->iftype) { |
| 8062 | case NL80211_IFTYPE_STATION: |
| 8063 | case NL80211_IFTYPE_ADHOC: |
| 8064 | case NL80211_IFTYPE_P2P_CLIENT: |
| 8065 | case NL80211_IFTYPE_AP: |
| 8066 | case NL80211_IFTYPE_AP_VLAN: |
| 8067 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8068 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8069 | break; |
| 8070 | default: |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8071 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8072 | } |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8073 | |
| 8074 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 8075 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8076 | return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie); |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8077 | } |
| 8078 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8079 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
| 8080 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8081 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8082 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8083 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8084 | u8 ps_state; |
| 8085 | bool state; |
| 8086 | int err; |
| 8087 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8088 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
| 8089 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8090 | |
| 8091 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); |
| 8092 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8093 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
| 8094 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8095 | |
| 8096 | wdev = dev->ieee80211_ptr; |
| 8097 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8098 | if (!rdev->ops->set_power_mgmt) |
| 8099 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8100 | |
| 8101 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; |
| 8102 | |
| 8103 | if (state == wdev->ps) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8104 | return 0; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8105 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8106 | err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8107 | if (!err) |
| 8108 | wdev->ps = state; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8109 | return err; |
| 8110 | } |
| 8111 | |
| 8112 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) |
| 8113 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8114 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8115 | enum nl80211_ps_state ps_state; |
| 8116 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8117 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8118 | struct sk_buff *msg; |
| 8119 | void *hdr; |
| 8120 | int err; |
| 8121 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8122 | wdev = dev->ieee80211_ptr; |
| 8123 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8124 | if (!rdev->ops->set_power_mgmt) |
| 8125 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8126 | |
| 8127 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8128 | if (!msg) |
| 8129 | return -ENOMEM; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8130 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8131 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8132 | NL80211_CMD_GET_POWER_SAVE); |
| 8133 | if (!hdr) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8134 | err = -ENOBUFS; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8135 | goto free_msg; |
| 8136 | } |
| 8137 | |
| 8138 | if (wdev->ps) |
| 8139 | ps_state = NL80211_PS_ENABLED; |
| 8140 | else |
| 8141 | ps_state = NL80211_PS_DISABLED; |
| 8142 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8143 | if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) |
| 8144 | goto nla_put_failure; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8145 | |
| 8146 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8147 | return genlmsg_reply(msg, info); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8148 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8149 | nla_put_failure: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8150 | err = -ENOBUFS; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8151 | free_msg: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8152 | nlmsg_free(msg); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8153 | return err; |
| 8154 | } |
| 8155 | |
Johannes Berg | 94e860f | 2014-01-20 23:58:15 +0100 | [diff] [blame] | 8156 | static const struct nla_policy |
| 8157 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = { |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8158 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, |
| 8159 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, |
| 8160 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 8161 | [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 }, |
| 8162 | [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 }, |
| 8163 | [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8164 | }; |
| 8165 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 8166 | static int nl80211_set_cqm_txe(struct genl_info *info, |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 8167 | u32 rate, u32 pkts, u32 intvl) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 8168 | { |
| 8169 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 8170 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 8171 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 8172 | |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 8173 | if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 8174 | return -EINVAL; |
| 8175 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 8176 | if (!rdev->ops->set_cqm_txe_config) |
| 8177 | return -EOPNOTSUPP; |
| 8178 | |
| 8179 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
| 8180 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 8181 | return -EOPNOTSUPP; |
| 8182 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8183 | return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 8184 | } |
| 8185 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8186 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
| 8187 | s32 threshold, u32 hysteresis) |
| 8188 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8189 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8190 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 8191 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8192 | |
| 8193 | if (threshold > 0) |
| 8194 | return -EINVAL; |
| 8195 | |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 8196 | /* disabling - hysteresis should also be zero then */ |
| 8197 | if (threshold == 0) |
| 8198 | hysteresis = 0; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8199 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8200 | if (!rdev->ops->set_cqm_rssi_config) |
| 8201 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8202 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 8203 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8204 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 8205 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8206 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8207 | return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8208 | } |
| 8209 | |
| 8210 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) |
| 8211 | { |
| 8212 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; |
| 8213 | struct nlattr *cqm; |
| 8214 | int err; |
| 8215 | |
| 8216 | cqm = info->attrs[NL80211_ATTR_CQM]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 8217 | if (!cqm) |
| 8218 | return -EINVAL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8219 | |
| 8220 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, |
| 8221 | nl80211_attr_cqm_policy); |
| 8222 | if (err) |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 8223 | return err; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8224 | |
| 8225 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && |
| 8226 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 8227 | s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
| 8228 | u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8229 | |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 8230 | return nl80211_set_cqm_rssi(info, threshold, hysteresis); |
| 8231 | } |
| 8232 | |
| 8233 | if (attrs[NL80211_ATTR_CQM_TXE_RATE] && |
| 8234 | attrs[NL80211_ATTR_CQM_TXE_PKTS] && |
| 8235 | attrs[NL80211_ATTR_CQM_TXE_INTVL]) { |
| 8236 | u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]); |
| 8237 | u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]); |
| 8238 | u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]); |
| 8239 | |
| 8240 | return nl80211_set_cqm_txe(info, rate, pkts, intvl); |
| 8241 | } |
| 8242 | |
| 8243 | return -EINVAL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8244 | } |
| 8245 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8246 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
| 8247 | { |
| 8248 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8249 | struct net_device *dev = info->user_ptr[1]; |
| 8250 | struct mesh_config cfg; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 8251 | struct mesh_setup setup; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8252 | int err; |
| 8253 | |
| 8254 | /* start with default */ |
| 8255 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 8256 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8257 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 8258 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8259 | /* and parse parameters if given */ |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 8260 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8261 | if (err) |
| 8262 | return err; |
| 8263 | } |
| 8264 | |
| 8265 | if (!info->attrs[NL80211_ATTR_MESH_ID] || |
| 8266 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) |
| 8267 | return -EINVAL; |
| 8268 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 8269 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
| 8270 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 8271 | |
Chun-Yeow Yeoh | 4bb6234 | 2011-11-24 17:15:20 -0800 | [diff] [blame] | 8272 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 8273 | !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, |
| 8274 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 8275 | return -EINVAL; |
| 8276 | |
Marco Porsch | 9bdbf04 | 2013-01-07 16:04:51 +0100 | [diff] [blame] | 8277 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 8278 | setup.beacon_interval = |
| 8279 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 8280 | if (setup.beacon_interval < 10 || |
| 8281 | setup.beacon_interval > 10000) |
| 8282 | return -EINVAL; |
| 8283 | } |
| 8284 | |
| 8285 | if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) { |
| 8286 | setup.dtim_period = |
| 8287 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 8288 | if (setup.dtim_period < 1 || setup.dtim_period > 100) |
| 8289 | return -EINVAL; |
| 8290 | } |
| 8291 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 8292 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
| 8293 | /* parse additional setup parameters if given */ |
| 8294 | err = nl80211_parse_mesh_setup(info, &setup); |
| 8295 | if (err) |
| 8296 | return err; |
| 8297 | } |
| 8298 | |
Thomas Pedersen | d37bb18 | 2013-03-04 13:06:13 -0800 | [diff] [blame] | 8299 | if (setup.user_mpm) |
| 8300 | cfg.auto_open_plinks = false; |
| 8301 | |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 8302 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 8303 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
| 8304 | if (err) |
| 8305 | return err; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 8306 | } else { |
| 8307 | /* cfg80211_join_mesh() will sort it out */ |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 8308 | setup.chandef.chan = NULL; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 8309 | } |
| 8310 | |
Ashok Nagarajan | ffb3cf3 | 2013-06-03 10:33:36 -0700 | [diff] [blame] | 8311 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 8312 | u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 8313 | int n_rates = |
| 8314 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 8315 | struct ieee80211_supported_band *sband; |
| 8316 | |
| 8317 | if (!setup.chandef.chan) |
| 8318 | return -EINVAL; |
| 8319 | |
| 8320 | sband = rdev->wiphy.bands[setup.chandef.chan->band]; |
| 8321 | |
| 8322 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 8323 | &setup.basic_rates); |
| 8324 | if (err) |
| 8325 | return err; |
| 8326 | } |
| 8327 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 8328 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8329 | } |
| 8330 | |
| 8331 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) |
| 8332 | { |
| 8333 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8334 | struct net_device *dev = info->user_ptr[1]; |
| 8335 | |
| 8336 | return cfg80211_leave_mesh(rdev, dev); |
| 8337 | } |
| 8338 | |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 8339 | #ifdef CONFIG_PM |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8340 | static int nl80211_send_wowlan_patterns(struct sk_buff *msg, |
| 8341 | struct cfg80211_registered_device *rdev) |
| 8342 | { |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8343 | struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config; |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8344 | struct nlattr *nl_pats, *nl_pat; |
| 8345 | int i, pat_len; |
| 8346 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8347 | if (!wowlan->n_patterns) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8348 | return 0; |
| 8349 | |
| 8350 | nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN); |
| 8351 | if (!nl_pats) |
| 8352 | return -ENOBUFS; |
| 8353 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8354 | for (i = 0; i < wowlan->n_patterns; i++) { |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8355 | nl_pat = nla_nest_start(msg, i + 1); |
| 8356 | if (!nl_pat) |
| 8357 | return -ENOBUFS; |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8358 | pat_len = wowlan->patterns[i].pattern_len; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8359 | 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] | 8360 | wowlan->patterns[i].mask) || |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8361 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
| 8362 | wowlan->patterns[i].pattern) || |
| 8363 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8364 | wowlan->patterns[i].pkt_offset)) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8365 | return -ENOBUFS; |
| 8366 | nla_nest_end(msg, nl_pat); |
| 8367 | } |
| 8368 | nla_nest_end(msg, nl_pats); |
| 8369 | |
| 8370 | return 0; |
| 8371 | } |
| 8372 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8373 | static int nl80211_send_wowlan_tcp(struct sk_buff *msg, |
| 8374 | struct cfg80211_wowlan_tcp *tcp) |
| 8375 | { |
| 8376 | struct nlattr *nl_tcp; |
| 8377 | |
| 8378 | if (!tcp) |
| 8379 | return 0; |
| 8380 | |
| 8381 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); |
| 8382 | if (!nl_tcp) |
| 8383 | return -ENOBUFS; |
| 8384 | |
| 8385 | if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) || |
| 8386 | nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) || |
| 8387 | nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) || |
| 8388 | nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) || |
| 8389 | nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) || |
| 8390 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 8391 | tcp->payload_len, tcp->payload) || |
| 8392 | nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, |
| 8393 | tcp->data_interval) || |
| 8394 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, |
| 8395 | tcp->wake_len, tcp->wake_data) || |
| 8396 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK, |
| 8397 | DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask)) |
| 8398 | return -ENOBUFS; |
| 8399 | |
| 8400 | if (tcp->payload_seq.len && |
| 8401 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ, |
| 8402 | sizeof(tcp->payload_seq), &tcp->payload_seq)) |
| 8403 | return -ENOBUFS; |
| 8404 | |
| 8405 | if (tcp->payload_tok.len && |
| 8406 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, |
| 8407 | sizeof(tcp->payload_tok) + tcp->tokens_size, |
| 8408 | &tcp->payload_tok)) |
| 8409 | return -ENOBUFS; |
| 8410 | |
Johannes Berg | e248ad3 | 2013-05-16 10:24:28 +0200 | [diff] [blame] | 8411 | nla_nest_end(msg, nl_tcp); |
| 8412 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8413 | return 0; |
| 8414 | } |
| 8415 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8416 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 8417 | { |
| 8418 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8419 | struct sk_buff *msg; |
| 8420 | void *hdr; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8421 | u32 size = NLMSG_DEFAULT_SIZE; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8422 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8423 | if (!rdev->wiphy.wowlan) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8424 | return -EOPNOTSUPP; |
| 8425 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8426 | if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) { |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8427 | /* adjust size to have room for all the data */ |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8428 | size += rdev->wiphy.wowlan_config->tcp->tokens_size + |
| 8429 | rdev->wiphy.wowlan_config->tcp->payload_len + |
| 8430 | rdev->wiphy.wowlan_config->tcp->wake_len + |
| 8431 | rdev->wiphy.wowlan_config->tcp->wake_len / 8; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8432 | } |
| 8433 | |
| 8434 | msg = nlmsg_new(size, GFP_KERNEL); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8435 | if (!msg) |
| 8436 | return -ENOMEM; |
| 8437 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8438 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8439 | NL80211_CMD_GET_WOWLAN); |
| 8440 | if (!hdr) |
| 8441 | goto nla_put_failure; |
| 8442 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8443 | if (rdev->wiphy.wowlan_config) { |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8444 | struct nlattr *nl_wowlan; |
| 8445 | |
| 8446 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
| 8447 | if (!nl_wowlan) |
| 8448 | goto nla_put_failure; |
| 8449 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8450 | if ((rdev->wiphy.wowlan_config->any && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8451 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8452 | (rdev->wiphy.wowlan_config->disconnect && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8453 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8454 | (rdev->wiphy.wowlan_config->magic_pkt && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8455 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8456 | (rdev->wiphy.wowlan_config->gtk_rekey_failure && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8457 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8458 | (rdev->wiphy.wowlan_config->eap_identity_req && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8459 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8460 | (rdev->wiphy.wowlan_config->four_way_handshake && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8461 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8462 | (rdev->wiphy.wowlan_config->rfkill_release && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8463 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 8464 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8465 | |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8466 | if (nl80211_send_wowlan_patterns(msg, rdev)) |
| 8467 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8468 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8469 | if (nl80211_send_wowlan_tcp(msg, |
| 8470 | rdev->wiphy.wowlan_config->tcp)) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8471 | goto nla_put_failure; |
| 8472 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8473 | nla_nest_end(msg, nl_wowlan); |
| 8474 | } |
| 8475 | |
| 8476 | genlmsg_end(msg, hdr); |
| 8477 | return genlmsg_reply(msg, info); |
| 8478 | |
| 8479 | nla_put_failure: |
| 8480 | nlmsg_free(msg); |
| 8481 | return -ENOBUFS; |
| 8482 | } |
| 8483 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8484 | static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev, |
| 8485 | struct nlattr *attr, |
| 8486 | struct cfg80211_wowlan *trig) |
| 8487 | { |
| 8488 | struct nlattr *tb[NUM_NL80211_WOWLAN_TCP]; |
| 8489 | struct cfg80211_wowlan_tcp *cfg; |
| 8490 | struct nl80211_wowlan_tcp_data_token *tok = NULL; |
| 8491 | struct nl80211_wowlan_tcp_data_seq *seq = NULL; |
| 8492 | u32 size; |
| 8493 | u32 data_size, wake_size, tokens_size = 0, wake_mask_size; |
| 8494 | int err, port; |
| 8495 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8496 | if (!rdev->wiphy.wowlan->tcp) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8497 | return -EINVAL; |
| 8498 | |
| 8499 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP, |
| 8500 | nla_data(attr), nla_len(attr), |
| 8501 | nl80211_wowlan_tcp_policy); |
| 8502 | if (err) |
| 8503 | return err; |
| 8504 | |
| 8505 | if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] || |
| 8506 | !tb[NL80211_WOWLAN_TCP_DST_IPV4] || |
| 8507 | !tb[NL80211_WOWLAN_TCP_DST_MAC] || |
| 8508 | !tb[NL80211_WOWLAN_TCP_DST_PORT] || |
| 8509 | !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] || |
| 8510 | !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] || |
| 8511 | !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] || |
| 8512 | !tb[NL80211_WOWLAN_TCP_WAKE_MASK]) |
| 8513 | return -EINVAL; |
| 8514 | |
| 8515 | data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8516 | if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8517 | return -EINVAL; |
| 8518 | |
| 8519 | if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) > |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8520 | rdev->wiphy.wowlan->tcp->data_interval_max || |
Johannes Berg | 723d568 | 2013-02-26 13:56:40 +0100 | [diff] [blame] | 8521 | nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8522 | return -EINVAL; |
| 8523 | |
| 8524 | wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8525 | if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8526 | return -EINVAL; |
| 8527 | |
| 8528 | wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]); |
| 8529 | if (wake_mask_size != DIV_ROUND_UP(wake_size, 8)) |
| 8530 | return -EINVAL; |
| 8531 | |
| 8532 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) { |
| 8533 | u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 8534 | |
| 8535 | tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 8536 | tokens_size = tokln - sizeof(*tok); |
| 8537 | |
| 8538 | if (!tok->len || tokens_size % tok->len) |
| 8539 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8540 | if (!rdev->wiphy.wowlan->tcp->tok) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8541 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8542 | if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8543 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8544 | if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8545 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8546 | if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8547 | return -EINVAL; |
| 8548 | if (tok->offset + tok->len > data_size) |
| 8549 | return -EINVAL; |
| 8550 | } |
| 8551 | |
| 8552 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) { |
| 8553 | seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8554 | if (!rdev->wiphy.wowlan->tcp->seq) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8555 | return -EINVAL; |
| 8556 | if (seq->len == 0 || seq->len > 4) |
| 8557 | return -EINVAL; |
| 8558 | if (seq->len + seq->offset > data_size) |
| 8559 | return -EINVAL; |
| 8560 | } |
| 8561 | |
| 8562 | size = sizeof(*cfg); |
| 8563 | size += data_size; |
| 8564 | size += wake_size + wake_mask_size; |
| 8565 | size += tokens_size; |
| 8566 | |
| 8567 | cfg = kzalloc(size, GFP_KERNEL); |
| 8568 | if (!cfg) |
| 8569 | return -ENOMEM; |
| 8570 | cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]); |
| 8571 | cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]); |
| 8572 | memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]), |
| 8573 | ETH_ALEN); |
| 8574 | if (tb[NL80211_WOWLAN_TCP_SRC_PORT]) |
| 8575 | port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]); |
| 8576 | else |
| 8577 | port = 0; |
| 8578 | #ifdef CONFIG_INET |
| 8579 | /* allocate a socket and port for it and use it */ |
| 8580 | err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM, |
| 8581 | IPPROTO_TCP, &cfg->sock, 1); |
| 8582 | if (err) { |
| 8583 | kfree(cfg); |
| 8584 | return err; |
| 8585 | } |
| 8586 | if (inet_csk_get_port(cfg->sock->sk, port)) { |
| 8587 | sock_release(cfg->sock); |
| 8588 | kfree(cfg); |
| 8589 | return -EADDRINUSE; |
| 8590 | } |
| 8591 | cfg->src_port = inet_sk(cfg->sock->sk)->inet_num; |
| 8592 | #else |
| 8593 | if (!port) { |
| 8594 | kfree(cfg); |
| 8595 | return -EINVAL; |
| 8596 | } |
| 8597 | cfg->src_port = port; |
| 8598 | #endif |
| 8599 | |
| 8600 | cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]); |
| 8601 | cfg->payload_len = data_size; |
| 8602 | cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size; |
| 8603 | memcpy((void *)cfg->payload, |
| 8604 | nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]), |
| 8605 | data_size); |
| 8606 | if (seq) |
| 8607 | cfg->payload_seq = *seq; |
| 8608 | cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]); |
| 8609 | cfg->wake_len = wake_size; |
| 8610 | cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size; |
| 8611 | memcpy((void *)cfg->wake_data, |
| 8612 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]), |
| 8613 | wake_size); |
| 8614 | cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size + |
| 8615 | data_size + wake_size; |
| 8616 | memcpy((void *)cfg->wake_mask, |
| 8617 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]), |
| 8618 | wake_mask_size); |
| 8619 | if (tok) { |
| 8620 | cfg->tokens_size = tokens_size; |
| 8621 | memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size); |
| 8622 | } |
| 8623 | |
| 8624 | trig->tcp = cfg; |
| 8625 | |
| 8626 | return 0; |
| 8627 | } |
| 8628 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8629 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 8630 | { |
| 8631 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8632 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8633 | struct cfg80211_wowlan new_triggers = {}; |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8634 | struct cfg80211_wowlan *ntrig; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8635 | const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8636 | int err, i; |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8637 | bool prev_enabled = rdev->wiphy.wowlan_config; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8638 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8639 | if (!wowlan) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8640 | return -EOPNOTSUPP; |
| 8641 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8642 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) { |
| 8643 | cfg80211_rdev_free_wowlan(rdev); |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8644 | rdev->wiphy.wowlan_config = NULL; |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8645 | goto set_wakeup; |
| 8646 | } |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8647 | |
| 8648 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG, |
| 8649 | nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 8650 | nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 8651 | nl80211_wowlan_policy); |
| 8652 | if (err) |
| 8653 | return err; |
| 8654 | |
| 8655 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { |
| 8656 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) |
| 8657 | return -EINVAL; |
| 8658 | new_triggers.any = true; |
| 8659 | } |
| 8660 | |
| 8661 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { |
| 8662 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) |
| 8663 | return -EINVAL; |
| 8664 | new_triggers.disconnect = true; |
| 8665 | } |
| 8666 | |
| 8667 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { |
| 8668 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) |
| 8669 | return -EINVAL; |
| 8670 | new_triggers.magic_pkt = true; |
| 8671 | } |
| 8672 | |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 8673 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
| 8674 | return -EINVAL; |
| 8675 | |
| 8676 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { |
| 8677 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) |
| 8678 | return -EINVAL; |
| 8679 | new_triggers.gtk_rekey_failure = true; |
| 8680 | } |
| 8681 | |
| 8682 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { |
| 8683 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) |
| 8684 | return -EINVAL; |
| 8685 | new_triggers.eap_identity_req = true; |
| 8686 | } |
| 8687 | |
| 8688 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { |
| 8689 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) |
| 8690 | return -EINVAL; |
| 8691 | new_triggers.four_way_handshake = true; |
| 8692 | } |
| 8693 | |
| 8694 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { |
| 8695 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) |
| 8696 | return -EINVAL; |
| 8697 | new_triggers.rfkill_release = true; |
| 8698 | } |
| 8699 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8700 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
| 8701 | struct nlattr *pat; |
| 8702 | int n_patterns = 0; |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8703 | int rem, pat_len, mask_len, pkt_offset; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8704 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8705 | |
| 8706 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 8707 | rem) |
| 8708 | n_patterns++; |
| 8709 | if (n_patterns > wowlan->n_patterns) |
| 8710 | return -EINVAL; |
| 8711 | |
| 8712 | new_triggers.patterns = kcalloc(n_patterns, |
| 8713 | sizeof(new_triggers.patterns[0]), |
| 8714 | GFP_KERNEL); |
| 8715 | if (!new_triggers.patterns) |
| 8716 | return -ENOMEM; |
| 8717 | |
| 8718 | new_triggers.n_patterns = n_patterns; |
| 8719 | i = 0; |
| 8720 | |
| 8721 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 8722 | rem) { |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 8723 | u8 *mask_pat; |
| 8724 | |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8725 | nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat), |
| 8726 | nla_len(pat), NULL); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8727 | err = -EINVAL; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8728 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
| 8729 | !pat_tb[NL80211_PKTPAT_PATTERN]) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8730 | goto error; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8731 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8732 | mask_len = DIV_ROUND_UP(pat_len, 8); |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8733 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8734 | goto error; |
| 8735 | if (pat_len > wowlan->pattern_max_len || |
| 8736 | pat_len < wowlan->pattern_min_len) |
| 8737 | goto error; |
| 8738 | |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8739 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8740 | pkt_offset = 0; |
| 8741 | else |
| 8742 | pkt_offset = nla_get_u32( |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8743 | pat_tb[NL80211_PKTPAT_OFFSET]); |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8744 | if (pkt_offset > wowlan->max_pkt_offset) |
| 8745 | goto error; |
| 8746 | new_triggers.patterns[i].pkt_offset = pkt_offset; |
| 8747 | |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 8748 | mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 8749 | if (!mask_pat) { |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8750 | err = -ENOMEM; |
| 8751 | goto error; |
| 8752 | } |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 8753 | new_triggers.patterns[i].mask = mask_pat; |
| 8754 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]), |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8755 | mask_len); |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 8756 | mask_pat += mask_len; |
| 8757 | new_triggers.patterns[i].pattern = mask_pat; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8758 | new_triggers.patterns[i].pattern_len = pat_len; |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 8759 | memcpy(mask_pat, |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8760 | nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8761 | pat_len); |
| 8762 | i++; |
| 8763 | } |
| 8764 | } |
| 8765 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8766 | if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) { |
| 8767 | err = nl80211_parse_wowlan_tcp( |
| 8768 | rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION], |
| 8769 | &new_triggers); |
| 8770 | if (err) |
| 8771 | goto error; |
| 8772 | } |
| 8773 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8774 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL); |
| 8775 | if (!ntrig) { |
| 8776 | err = -ENOMEM; |
| 8777 | goto error; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8778 | } |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8779 | cfg80211_rdev_free_wowlan(rdev); |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8780 | rdev->wiphy.wowlan_config = ntrig; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8781 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8782 | set_wakeup: |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8783 | if (rdev->ops->set_wakeup && |
| 8784 | prev_enabled != !!rdev->wiphy.wowlan_config) |
| 8785 | rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config); |
Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame] | 8786 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8787 | return 0; |
| 8788 | error: |
| 8789 | for (i = 0; i < new_triggers.n_patterns; i++) |
| 8790 | kfree(new_triggers.patterns[i].mask); |
| 8791 | kfree(new_triggers.patterns); |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8792 | if (new_triggers.tcp && new_triggers.tcp->sock) |
| 8793 | sock_release(new_triggers.tcp->sock); |
| 8794 | kfree(new_triggers.tcp); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8795 | return err; |
| 8796 | } |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 8797 | #endif |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8798 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 8799 | static int nl80211_send_coalesce_rules(struct sk_buff *msg, |
| 8800 | struct cfg80211_registered_device *rdev) |
| 8801 | { |
| 8802 | struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules; |
| 8803 | int i, j, pat_len; |
| 8804 | struct cfg80211_coalesce_rules *rule; |
| 8805 | |
| 8806 | if (!rdev->coalesce->n_rules) |
| 8807 | return 0; |
| 8808 | |
| 8809 | nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE); |
| 8810 | if (!nl_rules) |
| 8811 | return -ENOBUFS; |
| 8812 | |
| 8813 | for (i = 0; i < rdev->coalesce->n_rules; i++) { |
| 8814 | nl_rule = nla_nest_start(msg, i + 1); |
| 8815 | if (!nl_rule) |
| 8816 | return -ENOBUFS; |
| 8817 | |
| 8818 | rule = &rdev->coalesce->rules[i]; |
| 8819 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY, |
| 8820 | rule->delay)) |
| 8821 | return -ENOBUFS; |
| 8822 | |
| 8823 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION, |
| 8824 | rule->condition)) |
| 8825 | return -ENOBUFS; |
| 8826 | |
| 8827 | nl_pats = nla_nest_start(msg, |
| 8828 | NL80211_ATTR_COALESCE_RULE_PKT_PATTERN); |
| 8829 | if (!nl_pats) |
| 8830 | return -ENOBUFS; |
| 8831 | |
| 8832 | for (j = 0; j < rule->n_patterns; j++) { |
| 8833 | nl_pat = nla_nest_start(msg, j + 1); |
| 8834 | if (!nl_pat) |
| 8835 | return -ENOBUFS; |
| 8836 | pat_len = rule->patterns[j].pattern_len; |
| 8837 | if (nla_put(msg, NL80211_PKTPAT_MASK, |
| 8838 | DIV_ROUND_UP(pat_len, 8), |
| 8839 | rule->patterns[j].mask) || |
| 8840 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
| 8841 | rule->patterns[j].pattern) || |
| 8842 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, |
| 8843 | rule->patterns[j].pkt_offset)) |
| 8844 | return -ENOBUFS; |
| 8845 | nla_nest_end(msg, nl_pat); |
| 8846 | } |
| 8847 | nla_nest_end(msg, nl_pats); |
| 8848 | nla_nest_end(msg, nl_rule); |
| 8849 | } |
| 8850 | nla_nest_end(msg, nl_rules); |
| 8851 | |
| 8852 | return 0; |
| 8853 | } |
| 8854 | |
| 8855 | static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info) |
| 8856 | { |
| 8857 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8858 | struct sk_buff *msg; |
| 8859 | void *hdr; |
| 8860 | |
| 8861 | if (!rdev->wiphy.coalesce) |
| 8862 | return -EOPNOTSUPP; |
| 8863 | |
| 8864 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 8865 | if (!msg) |
| 8866 | return -ENOMEM; |
| 8867 | |
| 8868 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 8869 | NL80211_CMD_GET_COALESCE); |
| 8870 | if (!hdr) |
| 8871 | goto nla_put_failure; |
| 8872 | |
| 8873 | if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev)) |
| 8874 | goto nla_put_failure; |
| 8875 | |
| 8876 | genlmsg_end(msg, hdr); |
| 8877 | return genlmsg_reply(msg, info); |
| 8878 | |
| 8879 | nla_put_failure: |
| 8880 | nlmsg_free(msg); |
| 8881 | return -ENOBUFS; |
| 8882 | } |
| 8883 | |
| 8884 | void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev) |
| 8885 | { |
| 8886 | struct cfg80211_coalesce *coalesce = rdev->coalesce; |
| 8887 | int i, j; |
| 8888 | struct cfg80211_coalesce_rules *rule; |
| 8889 | |
| 8890 | if (!coalesce) |
| 8891 | return; |
| 8892 | |
| 8893 | for (i = 0; i < coalesce->n_rules; i++) { |
| 8894 | rule = &coalesce->rules[i]; |
| 8895 | for (j = 0; j < rule->n_patterns; j++) |
| 8896 | kfree(rule->patterns[j].mask); |
| 8897 | kfree(rule->patterns); |
| 8898 | } |
| 8899 | kfree(coalesce->rules); |
| 8900 | kfree(coalesce); |
| 8901 | rdev->coalesce = NULL; |
| 8902 | } |
| 8903 | |
| 8904 | static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev, |
| 8905 | struct nlattr *rule, |
| 8906 | struct cfg80211_coalesce_rules *new_rule) |
| 8907 | { |
| 8908 | int err, i; |
| 8909 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; |
| 8910 | struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat; |
| 8911 | int rem, pat_len, mask_len, pkt_offset, n_patterns = 0; |
| 8912 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
| 8913 | |
| 8914 | err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule), |
| 8915 | nla_len(rule), nl80211_coalesce_policy); |
| 8916 | if (err) |
| 8917 | return err; |
| 8918 | |
| 8919 | if (tb[NL80211_ATTR_COALESCE_RULE_DELAY]) |
| 8920 | new_rule->delay = |
| 8921 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]); |
| 8922 | if (new_rule->delay > coalesce->max_delay) |
| 8923 | return -EINVAL; |
| 8924 | |
| 8925 | if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION]) |
| 8926 | new_rule->condition = |
| 8927 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]); |
| 8928 | if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH && |
| 8929 | new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH) |
| 8930 | return -EINVAL; |
| 8931 | |
| 8932 | if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN]) |
| 8933 | return -EINVAL; |
| 8934 | |
| 8935 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], |
| 8936 | rem) |
| 8937 | n_patterns++; |
| 8938 | if (n_patterns > coalesce->n_patterns) |
| 8939 | return -EINVAL; |
| 8940 | |
| 8941 | new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]), |
| 8942 | GFP_KERNEL); |
| 8943 | if (!new_rule->patterns) |
| 8944 | return -ENOMEM; |
| 8945 | |
| 8946 | new_rule->n_patterns = n_patterns; |
| 8947 | i = 0; |
| 8948 | |
| 8949 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], |
| 8950 | rem) { |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 8951 | u8 *mask_pat; |
| 8952 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 8953 | nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat), |
| 8954 | nla_len(pat), NULL); |
| 8955 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
| 8956 | !pat_tb[NL80211_PKTPAT_PATTERN]) |
| 8957 | return -EINVAL; |
| 8958 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
| 8959 | mask_len = DIV_ROUND_UP(pat_len, 8); |
| 8960 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
| 8961 | return -EINVAL; |
| 8962 | if (pat_len > coalesce->pattern_max_len || |
| 8963 | pat_len < coalesce->pattern_min_len) |
| 8964 | return -EINVAL; |
| 8965 | |
| 8966 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
| 8967 | pkt_offset = 0; |
| 8968 | else |
| 8969 | pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]); |
| 8970 | if (pkt_offset > coalesce->max_pkt_offset) |
| 8971 | return -EINVAL; |
| 8972 | new_rule->patterns[i].pkt_offset = pkt_offset; |
| 8973 | |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 8974 | mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 8975 | if (!mask_pat) |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 8976 | return -ENOMEM; |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 8977 | |
| 8978 | new_rule->patterns[i].mask = mask_pat; |
| 8979 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]), |
| 8980 | mask_len); |
| 8981 | |
| 8982 | mask_pat += mask_len; |
| 8983 | new_rule->patterns[i].pattern = mask_pat; |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 8984 | new_rule->patterns[i].pattern_len = pat_len; |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 8985 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
| 8986 | pat_len); |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 8987 | i++; |
| 8988 | } |
| 8989 | |
| 8990 | return 0; |
| 8991 | } |
| 8992 | |
| 8993 | static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info) |
| 8994 | { |
| 8995 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8996 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; |
| 8997 | struct cfg80211_coalesce new_coalesce = {}; |
| 8998 | struct cfg80211_coalesce *n_coalesce; |
| 8999 | int err, rem_rule, n_rules = 0, i, j; |
| 9000 | struct nlattr *rule; |
| 9001 | struct cfg80211_coalesce_rules *tmp_rule; |
| 9002 | |
| 9003 | if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce) |
| 9004 | return -EOPNOTSUPP; |
| 9005 | |
| 9006 | if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) { |
| 9007 | cfg80211_rdev_free_coalesce(rdev); |
| 9008 | rdev->ops->set_coalesce(&rdev->wiphy, NULL); |
| 9009 | return 0; |
| 9010 | } |
| 9011 | |
| 9012 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], |
| 9013 | rem_rule) |
| 9014 | n_rules++; |
| 9015 | if (n_rules > coalesce->n_rules) |
| 9016 | return -EINVAL; |
| 9017 | |
| 9018 | new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]), |
| 9019 | GFP_KERNEL); |
| 9020 | if (!new_coalesce.rules) |
| 9021 | return -ENOMEM; |
| 9022 | |
| 9023 | new_coalesce.n_rules = n_rules; |
| 9024 | i = 0; |
| 9025 | |
| 9026 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], |
| 9027 | rem_rule) { |
| 9028 | err = nl80211_parse_coalesce_rule(rdev, rule, |
| 9029 | &new_coalesce.rules[i]); |
| 9030 | if (err) |
| 9031 | goto error; |
| 9032 | |
| 9033 | i++; |
| 9034 | } |
| 9035 | |
| 9036 | err = rdev->ops->set_coalesce(&rdev->wiphy, &new_coalesce); |
| 9037 | if (err) |
| 9038 | goto error; |
| 9039 | |
| 9040 | n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL); |
| 9041 | if (!n_coalesce) { |
| 9042 | err = -ENOMEM; |
| 9043 | goto error; |
| 9044 | } |
| 9045 | cfg80211_rdev_free_coalesce(rdev); |
| 9046 | rdev->coalesce = n_coalesce; |
| 9047 | |
| 9048 | return 0; |
| 9049 | error: |
| 9050 | for (i = 0; i < new_coalesce.n_rules; i++) { |
| 9051 | tmp_rule = &new_coalesce.rules[i]; |
| 9052 | for (j = 0; j < tmp_rule->n_patterns; j++) |
| 9053 | kfree(tmp_rule->patterns[j].mask); |
| 9054 | kfree(tmp_rule->patterns); |
| 9055 | } |
| 9056 | kfree(new_coalesce.rules); |
| 9057 | |
| 9058 | return err; |
| 9059 | } |
| 9060 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 9061 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
| 9062 | { |
| 9063 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9064 | struct net_device *dev = info->user_ptr[1]; |
| 9065 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9066 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; |
| 9067 | struct cfg80211_gtk_rekey_data rekey_data; |
| 9068 | int err; |
| 9069 | |
| 9070 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) |
| 9071 | return -EINVAL; |
| 9072 | |
| 9073 | err = nla_parse(tb, MAX_NL80211_REKEY_DATA, |
| 9074 | nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 9075 | nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 9076 | nl80211_rekey_policy); |
| 9077 | if (err) |
| 9078 | return err; |
| 9079 | |
| 9080 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) |
| 9081 | return -ERANGE; |
| 9082 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) |
| 9083 | return -ERANGE; |
| 9084 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) |
| 9085 | return -ERANGE; |
| 9086 | |
Johannes Berg | 78f686c | 2014-09-10 22:28:06 +0300 | [diff] [blame] | 9087 | rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]); |
| 9088 | rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]); |
| 9089 | rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 9090 | |
| 9091 | wdev_lock(wdev); |
| 9092 | if (!wdev->current_bss) { |
| 9093 | err = -ENOTCONN; |
| 9094 | goto out; |
| 9095 | } |
| 9096 | |
| 9097 | if (!rdev->ops->set_rekey_data) { |
| 9098 | err = -EOPNOTSUPP; |
| 9099 | goto out; |
| 9100 | } |
| 9101 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 9102 | err = rdev_set_rekey_data(rdev, dev, &rekey_data); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 9103 | out: |
| 9104 | wdev_unlock(wdev); |
| 9105 | return err; |
| 9106 | } |
| 9107 | |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9108 | static int nl80211_register_unexpected_frame(struct sk_buff *skb, |
| 9109 | struct genl_info *info) |
| 9110 | { |
| 9111 | struct net_device *dev = info->user_ptr[1]; |
| 9112 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9113 | |
| 9114 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 9115 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 9116 | return -EINVAL; |
| 9117 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9118 | if (wdev->ap_unexpected_nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9119 | return -EBUSY; |
| 9120 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9121 | wdev->ap_unexpected_nlportid = info->snd_portid; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9122 | return 0; |
| 9123 | } |
| 9124 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9125 | static int nl80211_probe_client(struct sk_buff *skb, |
| 9126 | struct genl_info *info) |
| 9127 | { |
| 9128 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9129 | struct net_device *dev = info->user_ptr[1]; |
| 9130 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9131 | struct sk_buff *msg; |
| 9132 | void *hdr; |
| 9133 | const u8 *addr; |
| 9134 | u64 cookie; |
| 9135 | int err; |
| 9136 | |
| 9137 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 9138 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 9139 | return -EOPNOTSUPP; |
| 9140 | |
| 9141 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 9142 | return -EINVAL; |
| 9143 | |
| 9144 | if (!rdev->ops->probe_client) |
| 9145 | return -EOPNOTSUPP; |
| 9146 | |
| 9147 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 9148 | if (!msg) |
| 9149 | return -ENOMEM; |
| 9150 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9151 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9152 | NL80211_CMD_PROBE_CLIENT); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 9153 | if (!hdr) { |
| 9154 | err = -ENOBUFS; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9155 | goto free_msg; |
| 9156 | } |
| 9157 | |
| 9158 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 9159 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 9160 | err = rdev_probe_client(rdev, dev, addr, &cookie); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9161 | if (err) |
| 9162 | goto free_msg; |
| 9163 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9164 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 9165 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9166 | |
| 9167 | genlmsg_end(msg, hdr); |
| 9168 | |
| 9169 | return genlmsg_reply(msg, info); |
| 9170 | |
| 9171 | nla_put_failure: |
| 9172 | err = -ENOBUFS; |
| 9173 | free_msg: |
| 9174 | nlmsg_free(msg); |
| 9175 | return err; |
| 9176 | } |
| 9177 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9178 | static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) |
| 9179 | { |
| 9180 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9181 | struct cfg80211_beacon_registration *reg, *nreg; |
| 9182 | int rv; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9183 | |
| 9184 | if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) |
| 9185 | return -EOPNOTSUPP; |
| 9186 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9187 | nreg = kzalloc(sizeof(*nreg), GFP_KERNEL); |
| 9188 | if (!nreg) |
| 9189 | return -ENOMEM; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9190 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9191 | /* First, check if already registered. */ |
| 9192 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 9193 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 9194 | if (reg->nlportid == info->snd_portid) { |
| 9195 | rv = -EALREADY; |
| 9196 | goto out_err; |
| 9197 | } |
| 9198 | } |
| 9199 | /* Add it to the list */ |
| 9200 | nreg->nlportid = info->snd_portid; |
| 9201 | list_add(&nreg->list, &rdev->beacon_registrations); |
| 9202 | |
| 9203 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9204 | |
| 9205 | return 0; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9206 | out_err: |
| 9207 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 9208 | kfree(nreg); |
| 9209 | return rv; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9210 | } |
| 9211 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9212 | static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 9213 | { |
| 9214 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9215 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 9216 | int err; |
| 9217 | |
| 9218 | if (!rdev->ops->start_p2p_device) |
| 9219 | return -EOPNOTSUPP; |
| 9220 | |
| 9221 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 9222 | return -EOPNOTSUPP; |
| 9223 | |
| 9224 | if (wdev->p2p_started) |
| 9225 | return 0; |
| 9226 | |
Luciano Coelho | b6a5501 | 2014-02-27 11:07:21 +0200 | [diff] [blame] | 9227 | if (rfkill_blocked(rdev->rfkill)) |
| 9228 | return -ERFKILL; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9229 | |
Johannes Berg | eeb126e | 2012-10-23 15:16:50 +0200 | [diff] [blame] | 9230 | err = rdev_start_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9231 | if (err) |
| 9232 | return err; |
| 9233 | |
| 9234 | wdev->p2p_started = true; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9235 | rdev->opencount++; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9236 | |
| 9237 | return 0; |
| 9238 | } |
| 9239 | |
| 9240 | static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 9241 | { |
| 9242 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9243 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 9244 | |
| 9245 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 9246 | return -EOPNOTSUPP; |
| 9247 | |
| 9248 | if (!rdev->ops->stop_p2p_device) |
| 9249 | return -EOPNOTSUPP; |
| 9250 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 9251 | cfg80211_stop_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9252 | |
| 9253 | return 0; |
| 9254 | } |
| 9255 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 9256 | static int nl80211_get_protocol_features(struct sk_buff *skb, |
| 9257 | struct genl_info *info) |
| 9258 | { |
| 9259 | void *hdr; |
| 9260 | struct sk_buff *msg; |
| 9261 | |
| 9262 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 9263 | if (!msg) |
| 9264 | return -ENOMEM; |
| 9265 | |
| 9266 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 9267 | NL80211_CMD_GET_PROTOCOL_FEATURES); |
| 9268 | if (!hdr) |
| 9269 | goto nla_put_failure; |
| 9270 | |
| 9271 | if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES, |
| 9272 | NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)) |
| 9273 | goto nla_put_failure; |
| 9274 | |
| 9275 | genlmsg_end(msg, hdr); |
| 9276 | return genlmsg_reply(msg, info); |
| 9277 | |
| 9278 | nla_put_failure: |
| 9279 | kfree_skb(msg); |
| 9280 | return -ENOBUFS; |
| 9281 | } |
| 9282 | |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 9283 | static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info) |
| 9284 | { |
| 9285 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9286 | struct cfg80211_update_ft_ies_params ft_params; |
| 9287 | struct net_device *dev = info->user_ptr[1]; |
| 9288 | |
| 9289 | if (!rdev->ops->update_ft_ies) |
| 9290 | return -EOPNOTSUPP; |
| 9291 | |
| 9292 | if (!info->attrs[NL80211_ATTR_MDID] || |
| 9293 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 9294 | return -EINVAL; |
| 9295 | |
| 9296 | memset(&ft_params, 0, sizeof(ft_params)); |
| 9297 | ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]); |
| 9298 | ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 9299 | ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 9300 | |
| 9301 | return rdev_update_ft_ies(rdev, dev, &ft_params); |
| 9302 | } |
| 9303 | |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 9304 | static int nl80211_crit_protocol_start(struct sk_buff *skb, |
| 9305 | struct genl_info *info) |
| 9306 | { |
| 9307 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9308 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 9309 | enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC; |
| 9310 | u16 duration; |
| 9311 | int ret; |
| 9312 | |
| 9313 | if (!rdev->ops->crit_proto_start) |
| 9314 | return -EOPNOTSUPP; |
| 9315 | |
| 9316 | if (WARN_ON(!rdev->ops->crit_proto_stop)) |
| 9317 | return -EINVAL; |
| 9318 | |
| 9319 | if (rdev->crit_proto_nlportid) |
| 9320 | return -EBUSY; |
| 9321 | |
| 9322 | /* determine protocol if provided */ |
| 9323 | if (info->attrs[NL80211_ATTR_CRIT_PROT_ID]) |
| 9324 | proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]); |
| 9325 | |
| 9326 | if (proto >= NUM_NL80211_CRIT_PROTO) |
| 9327 | return -EINVAL; |
| 9328 | |
| 9329 | /* timeout must be provided */ |
| 9330 | if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]) |
| 9331 | return -EINVAL; |
| 9332 | |
| 9333 | duration = |
| 9334 | nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]); |
| 9335 | |
| 9336 | if (duration > NL80211_CRIT_PROTO_MAX_DURATION) |
| 9337 | return -ERANGE; |
| 9338 | |
| 9339 | ret = rdev_crit_proto_start(rdev, wdev, proto, duration); |
| 9340 | if (!ret) |
| 9341 | rdev->crit_proto_nlportid = info->snd_portid; |
| 9342 | |
| 9343 | return ret; |
| 9344 | } |
| 9345 | |
| 9346 | static int nl80211_crit_protocol_stop(struct sk_buff *skb, |
| 9347 | struct genl_info *info) |
| 9348 | { |
| 9349 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9350 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 9351 | |
| 9352 | if (!rdev->ops->crit_proto_stop) |
| 9353 | return -EOPNOTSUPP; |
| 9354 | |
| 9355 | if (rdev->crit_proto_nlportid) { |
| 9356 | rdev->crit_proto_nlportid = 0; |
| 9357 | rdev_crit_proto_stop(rdev, wdev); |
| 9358 | } |
| 9359 | return 0; |
| 9360 | } |
| 9361 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 9362 | static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info) |
| 9363 | { |
| 9364 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9365 | struct wireless_dev *wdev = |
| 9366 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); |
| 9367 | int i, err; |
| 9368 | u32 vid, subcmd; |
| 9369 | |
| 9370 | if (!rdev->wiphy.vendor_commands) |
| 9371 | return -EOPNOTSUPP; |
| 9372 | |
| 9373 | if (IS_ERR(wdev)) { |
| 9374 | err = PTR_ERR(wdev); |
| 9375 | if (err != -EINVAL) |
| 9376 | return err; |
| 9377 | wdev = NULL; |
| 9378 | } else if (wdev->wiphy != &rdev->wiphy) { |
| 9379 | return -EINVAL; |
| 9380 | } |
| 9381 | |
| 9382 | if (!info->attrs[NL80211_ATTR_VENDOR_ID] || |
| 9383 | !info->attrs[NL80211_ATTR_VENDOR_SUBCMD]) |
| 9384 | return -EINVAL; |
| 9385 | |
| 9386 | vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]); |
| 9387 | subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]); |
| 9388 | for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { |
| 9389 | const struct wiphy_vendor_command *vcmd; |
| 9390 | void *data = NULL; |
| 9391 | int len = 0; |
| 9392 | |
| 9393 | vcmd = &rdev->wiphy.vendor_commands[i]; |
| 9394 | |
| 9395 | if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd) |
| 9396 | continue; |
| 9397 | |
| 9398 | if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV | |
| 9399 | WIPHY_VENDOR_CMD_NEED_NETDEV)) { |
| 9400 | if (!wdev) |
| 9401 | return -EINVAL; |
| 9402 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV && |
| 9403 | !wdev->netdev) |
| 9404 | return -EINVAL; |
| 9405 | |
| 9406 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) { |
| 9407 | if (wdev->netdev && |
| 9408 | !netif_running(wdev->netdev)) |
| 9409 | return -ENETDOWN; |
| 9410 | if (!wdev->netdev && !wdev->p2p_started) |
| 9411 | return -ENETDOWN; |
| 9412 | } |
| 9413 | } else { |
| 9414 | wdev = NULL; |
| 9415 | } |
| 9416 | |
| 9417 | if (info->attrs[NL80211_ATTR_VENDOR_DATA]) { |
| 9418 | data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]); |
| 9419 | len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]); |
| 9420 | } |
| 9421 | |
| 9422 | rdev->cur_cmd_info = info; |
| 9423 | err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev, |
| 9424 | data, len); |
| 9425 | rdev->cur_cmd_info = NULL; |
| 9426 | return err; |
| 9427 | } |
| 9428 | |
| 9429 | return -EOPNOTSUPP; |
| 9430 | } |
| 9431 | |
| 9432 | struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy, |
| 9433 | enum nl80211_commands cmd, |
| 9434 | enum nl80211_attrs attr, |
| 9435 | int approxlen) |
| 9436 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 9437 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 9438 | |
| 9439 | if (WARN_ON(!rdev->cur_cmd_info)) |
| 9440 | return NULL; |
| 9441 | |
| 9442 | return __cfg80211_alloc_vendor_skb(rdev, approxlen, |
| 9443 | rdev->cur_cmd_info->snd_portid, |
| 9444 | rdev->cur_cmd_info->snd_seq, |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 9445 | cmd, attr, NULL, GFP_KERNEL); |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 9446 | } |
| 9447 | EXPORT_SYMBOL(__cfg80211_alloc_reply_skb); |
| 9448 | |
| 9449 | int cfg80211_vendor_cmd_reply(struct sk_buff *skb) |
| 9450 | { |
| 9451 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 9452 | void *hdr = ((void **)skb->cb)[1]; |
| 9453 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 9454 | |
Johannes Berg | bd8c78e | 2014-07-30 14:55:26 +0200 | [diff] [blame] | 9455 | /* clear CB data for netlink core to own from now on */ |
| 9456 | memset(skb->cb, 0, sizeof(skb->cb)); |
| 9457 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 9458 | if (WARN_ON(!rdev->cur_cmd_info)) { |
| 9459 | kfree_skb(skb); |
| 9460 | return -EINVAL; |
| 9461 | } |
| 9462 | |
| 9463 | nla_nest_end(skb, data); |
| 9464 | genlmsg_end(skb, hdr); |
| 9465 | return genlmsg_reply(skb, rdev->cur_cmd_info); |
| 9466 | } |
| 9467 | EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply); |
| 9468 | |
| 9469 | |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 9470 | static int nl80211_set_qos_map(struct sk_buff *skb, |
| 9471 | struct genl_info *info) |
| 9472 | { |
| 9473 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9474 | struct cfg80211_qos_map *qos_map = NULL; |
| 9475 | struct net_device *dev = info->user_ptr[1]; |
| 9476 | u8 *pos, len, num_des, des_len, des; |
| 9477 | int ret; |
| 9478 | |
| 9479 | if (!rdev->ops->set_qos_map) |
| 9480 | return -EOPNOTSUPP; |
| 9481 | |
| 9482 | if (info->attrs[NL80211_ATTR_QOS_MAP]) { |
| 9483 | pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]); |
| 9484 | len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]); |
| 9485 | |
| 9486 | if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN || |
| 9487 | len > IEEE80211_QOS_MAP_LEN_MAX) |
| 9488 | return -EINVAL; |
| 9489 | |
| 9490 | qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL); |
| 9491 | if (!qos_map) |
| 9492 | return -ENOMEM; |
| 9493 | |
| 9494 | num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1; |
| 9495 | if (num_des) { |
| 9496 | des_len = num_des * |
| 9497 | sizeof(struct cfg80211_dscp_exception); |
| 9498 | memcpy(qos_map->dscp_exception, pos, des_len); |
| 9499 | qos_map->num_des = num_des; |
| 9500 | for (des = 0; des < num_des; des++) { |
| 9501 | if (qos_map->dscp_exception[des].up > 7) { |
| 9502 | kfree(qos_map); |
| 9503 | return -EINVAL; |
| 9504 | } |
| 9505 | } |
| 9506 | pos += des_len; |
| 9507 | } |
| 9508 | memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN); |
| 9509 | } |
| 9510 | |
| 9511 | wdev_lock(dev->ieee80211_ptr); |
| 9512 | ret = nl80211_key_allowed(dev->ieee80211_ptr); |
| 9513 | if (!ret) |
| 9514 | ret = rdev_set_qos_map(rdev, dev, qos_map); |
| 9515 | wdev_unlock(dev->ieee80211_ptr); |
| 9516 | |
| 9517 | kfree(qos_map); |
| 9518 | return ret; |
| 9519 | } |
| 9520 | |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 9521 | static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info) |
| 9522 | { |
| 9523 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9524 | struct net_device *dev = info->user_ptr[1]; |
| 9525 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9526 | const u8 *peer; |
| 9527 | u8 tsid, up; |
| 9528 | u16 admitted_time = 0; |
| 9529 | int err; |
| 9530 | |
| 9531 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_WMM_ADMISSION)) |
| 9532 | return -EOPNOTSUPP; |
| 9533 | |
| 9534 | if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] || |
| 9535 | !info->attrs[NL80211_ATTR_USER_PRIO]) |
| 9536 | return -EINVAL; |
| 9537 | |
| 9538 | tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]); |
| 9539 | if (tsid >= IEEE80211_NUM_TIDS) |
| 9540 | return -EINVAL; |
| 9541 | |
| 9542 | up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]); |
| 9543 | if (up >= IEEE80211_NUM_UPS) |
| 9544 | return -EINVAL; |
| 9545 | |
| 9546 | /* WMM uses TIDs 0-7 even for TSPEC */ |
| 9547 | if (tsid < IEEE80211_FIRST_TSPEC_TSID) { |
| 9548 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_WMM_ADMISSION)) |
| 9549 | return -EINVAL; |
| 9550 | } else { |
| 9551 | /* TODO: handle 802.11 TSPEC/admission control |
| 9552 | * need more attributes for that (e.g. BA session requirement) |
| 9553 | */ |
| 9554 | return -EINVAL; |
| 9555 | } |
| 9556 | |
| 9557 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 9558 | |
| 9559 | if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) { |
| 9560 | admitted_time = |
| 9561 | nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]); |
| 9562 | if (!admitted_time) |
| 9563 | return -EINVAL; |
| 9564 | } |
| 9565 | |
| 9566 | wdev_lock(wdev); |
| 9567 | switch (wdev->iftype) { |
| 9568 | case NL80211_IFTYPE_STATION: |
| 9569 | case NL80211_IFTYPE_P2P_CLIENT: |
| 9570 | if (wdev->current_bss) |
| 9571 | break; |
| 9572 | err = -ENOTCONN; |
| 9573 | goto out; |
| 9574 | default: |
| 9575 | err = -EOPNOTSUPP; |
| 9576 | goto out; |
| 9577 | } |
| 9578 | |
| 9579 | err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time); |
| 9580 | |
| 9581 | out: |
| 9582 | wdev_unlock(wdev); |
| 9583 | return err; |
| 9584 | } |
| 9585 | |
| 9586 | static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info) |
| 9587 | { |
| 9588 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9589 | struct net_device *dev = info->user_ptr[1]; |
| 9590 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9591 | const u8 *peer; |
| 9592 | u8 tsid; |
| 9593 | int err; |
| 9594 | |
| 9595 | if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC]) |
| 9596 | return -EINVAL; |
| 9597 | |
| 9598 | tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]); |
| 9599 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 9600 | |
| 9601 | wdev_lock(wdev); |
| 9602 | err = rdev_del_tx_ts(rdev, dev, tsid, peer); |
| 9603 | wdev_unlock(wdev); |
| 9604 | |
| 9605 | return err; |
| 9606 | } |
| 9607 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9608 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
| 9609 | #define NL80211_FLAG_NEED_NETDEV 0x02 |
| 9610 | #define NL80211_FLAG_NEED_RTNL 0x04 |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9611 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
| 9612 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ |
| 9613 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 9614 | #define NL80211_FLAG_NEED_WDEV 0x10 |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9615 | /* 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] | 9616 | #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\ |
| 9617 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 9618 | #define NL80211_FLAG_CLEAR_SKB 0x20 |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9619 | |
Johannes Berg | f84f771 | 2013-11-14 17:14:45 +0100 | [diff] [blame] | 9620 | 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] | 9621 | struct genl_info *info) |
| 9622 | { |
| 9623 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 9624 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9625 | struct net_device *dev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9626 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
| 9627 | |
| 9628 | if (rtnl) |
| 9629 | rtnl_lock(); |
| 9630 | |
| 9631 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 9632 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9633 | if (IS_ERR(rdev)) { |
| 9634 | if (rtnl) |
| 9635 | rtnl_unlock(); |
| 9636 | return PTR_ERR(rdev); |
| 9637 | } |
| 9638 | info->user_ptr[0] = rdev; |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 9639 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV || |
| 9640 | ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 9641 | ASSERT_RTNL(); |
| 9642 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 9643 | wdev = __cfg80211_wdev_from_attrs(genl_info_net(info), |
| 9644 | info->attrs); |
| 9645 | if (IS_ERR(wdev)) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9646 | if (rtnl) |
| 9647 | rtnl_unlock(); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 9648 | return PTR_ERR(wdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9649 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 9650 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 9651 | dev = wdev->netdev; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 9652 | rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 9653 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 9654 | if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
| 9655 | if (!dev) { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 9656 | if (rtnl) |
| 9657 | rtnl_unlock(); |
| 9658 | return -EINVAL; |
| 9659 | } |
| 9660 | |
| 9661 | info->user_ptr[1] = dev; |
| 9662 | } else { |
| 9663 | info->user_ptr[1] = wdev; |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9664 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 9665 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 9666 | if (dev) { |
| 9667 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && |
| 9668 | !netif_running(dev)) { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 9669 | if (rtnl) |
| 9670 | rtnl_unlock(); |
| 9671 | return -ENETDOWN; |
| 9672 | } |
| 9673 | |
| 9674 | dev_hold(dev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9675 | } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) { |
| 9676 | if (!wdev->p2p_started) { |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9677 | if (rtnl) |
| 9678 | rtnl_unlock(); |
| 9679 | return -ENETDOWN; |
| 9680 | } |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 9681 | } |
| 9682 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9683 | info->user_ptr[0] = rdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9684 | } |
| 9685 | |
| 9686 | return 0; |
| 9687 | } |
| 9688 | |
Johannes Berg | f84f771 | 2013-11-14 17:14:45 +0100 | [diff] [blame] | 9689 | 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] | 9690 | struct genl_info *info) |
| 9691 | { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 9692 | if (info->user_ptr[1]) { |
| 9693 | if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
| 9694 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 9695 | |
| 9696 | if (wdev->netdev) |
| 9697 | dev_put(wdev->netdev); |
| 9698 | } else { |
| 9699 | dev_put(info->user_ptr[1]); |
| 9700 | } |
| 9701 | } |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 9702 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9703 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
| 9704 | rtnl_unlock(); |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 9705 | |
| 9706 | /* If needed, clear the netlink message payload from the SKB |
| 9707 | * as it might contain key data that shouldn't stick around on |
| 9708 | * the heap after the SKB is freed. The netlink message header |
| 9709 | * is still needed for further processing, so leave it intact. |
| 9710 | */ |
| 9711 | if (ops->internal_flags & NL80211_FLAG_CLEAR_SKB) { |
| 9712 | struct nlmsghdr *nlh = nlmsg_hdr(skb); |
| 9713 | |
| 9714 | memset(nlmsg_data(nlh), 0, nlmsg_len(nlh)); |
| 9715 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9716 | } |
| 9717 | |
Johannes Berg | 4534de8 | 2013-11-14 17:14:46 +0100 | [diff] [blame] | 9718 | static const struct genl_ops nl80211_ops[] = { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9719 | { |
| 9720 | .cmd = NL80211_CMD_GET_WIPHY, |
| 9721 | .doit = nl80211_get_wiphy, |
| 9722 | .dumpit = nl80211_dump_wiphy, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 9723 | .done = nl80211_dump_wiphy_done, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9724 | .policy = nl80211_policy, |
| 9725 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 9726 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9727 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9728 | }, |
| 9729 | { |
| 9730 | .cmd = NL80211_CMD_SET_WIPHY, |
| 9731 | .doit = nl80211_set_wiphy, |
| 9732 | .policy = nl80211_policy, |
| 9733 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9734 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9735 | }, |
| 9736 | { |
| 9737 | .cmd = NL80211_CMD_GET_INTERFACE, |
| 9738 | .doit = nl80211_get_interface, |
| 9739 | .dumpit = nl80211_dump_interface, |
| 9740 | .policy = nl80211_policy, |
| 9741 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 9742 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 9743 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9744 | }, |
| 9745 | { |
| 9746 | .cmd = NL80211_CMD_SET_INTERFACE, |
| 9747 | .doit = nl80211_set_interface, |
| 9748 | .policy = nl80211_policy, |
| 9749 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9750 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9751 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9752 | }, |
| 9753 | { |
| 9754 | .cmd = NL80211_CMD_NEW_INTERFACE, |
| 9755 | .doit = nl80211_new_interface, |
| 9756 | .policy = nl80211_policy, |
| 9757 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9758 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9759 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9760 | }, |
| 9761 | { |
| 9762 | .cmd = NL80211_CMD_DEL_INTERFACE, |
| 9763 | .doit = nl80211_del_interface, |
| 9764 | .policy = nl80211_policy, |
| 9765 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 9766 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9767 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9768 | }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 9769 | { |
| 9770 | .cmd = NL80211_CMD_GET_KEY, |
| 9771 | .doit = nl80211_get_key, |
| 9772 | .policy = nl80211_policy, |
| 9773 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9774 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9775 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 9776 | }, |
| 9777 | { |
| 9778 | .cmd = NL80211_CMD_SET_KEY, |
| 9779 | .doit = nl80211_set_key, |
| 9780 | .policy = nl80211_policy, |
| 9781 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9782 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 9783 | NL80211_FLAG_NEED_RTNL | |
| 9784 | NL80211_FLAG_CLEAR_SKB, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 9785 | }, |
| 9786 | { |
| 9787 | .cmd = NL80211_CMD_NEW_KEY, |
| 9788 | .doit = nl80211_new_key, |
| 9789 | .policy = nl80211_policy, |
| 9790 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9791 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 9792 | NL80211_FLAG_NEED_RTNL | |
| 9793 | NL80211_FLAG_CLEAR_SKB, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 9794 | }, |
| 9795 | { |
| 9796 | .cmd = NL80211_CMD_DEL_KEY, |
| 9797 | .doit = nl80211_del_key, |
| 9798 | .policy = nl80211_policy, |
| 9799 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9800 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9801 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 9802 | }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 9803 | { |
| 9804 | .cmd = NL80211_CMD_SET_BEACON, |
| 9805 | .policy = nl80211_policy, |
| 9806 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 9807 | .doit = nl80211_set_beacon, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9808 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9809 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 9810 | }, |
| 9811 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 9812 | .cmd = NL80211_CMD_START_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 9813 | .policy = nl80211_policy, |
| 9814 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 9815 | .doit = nl80211_start_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9816 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9817 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 9818 | }, |
| 9819 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 9820 | .cmd = NL80211_CMD_STOP_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 9821 | .policy = nl80211_policy, |
| 9822 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 9823 | .doit = nl80211_stop_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9824 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9825 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 9826 | }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 9827 | { |
| 9828 | .cmd = NL80211_CMD_GET_STATION, |
| 9829 | .doit = nl80211_get_station, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9830 | .dumpit = nl80211_dump_station, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 9831 | .policy = nl80211_policy, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9832 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9833 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 9834 | }, |
| 9835 | { |
| 9836 | .cmd = NL80211_CMD_SET_STATION, |
| 9837 | .doit = nl80211_set_station, |
| 9838 | .policy = nl80211_policy, |
| 9839 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9840 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9841 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 9842 | }, |
| 9843 | { |
| 9844 | .cmd = NL80211_CMD_NEW_STATION, |
| 9845 | .doit = nl80211_new_station, |
| 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 | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9849 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 9850 | }, |
| 9851 | { |
| 9852 | .cmd = NL80211_CMD_DEL_STATION, |
| 9853 | .doit = nl80211_del_station, |
| 9854 | .policy = nl80211_policy, |
| 9855 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9856 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9857 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 9858 | }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9859 | { |
| 9860 | .cmd = NL80211_CMD_GET_MPATH, |
| 9861 | .doit = nl80211_get_mpath, |
| 9862 | .dumpit = nl80211_dump_mpath, |
| 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, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9867 | }, |
| 9868 | { |
Henning Rogge | 66be7d2 | 2014-09-12 08:58:49 +0200 | [diff] [blame] | 9869 | .cmd = NL80211_CMD_GET_MPP, |
| 9870 | .doit = nl80211_get_mpp, |
| 9871 | .dumpit = nl80211_dump_mpp, |
| 9872 | .policy = nl80211_policy, |
| 9873 | .flags = GENL_ADMIN_PERM, |
| 9874 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9875 | NL80211_FLAG_NEED_RTNL, |
| 9876 | }, |
| 9877 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9878 | .cmd = NL80211_CMD_SET_MPATH, |
| 9879 | .doit = nl80211_set_mpath, |
| 9880 | .policy = nl80211_policy, |
| 9881 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9882 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9883 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9884 | }, |
| 9885 | { |
| 9886 | .cmd = NL80211_CMD_NEW_MPATH, |
| 9887 | .doit = nl80211_new_mpath, |
| 9888 | .policy = nl80211_policy, |
| 9889 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9890 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9891 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9892 | }, |
| 9893 | { |
| 9894 | .cmd = NL80211_CMD_DEL_MPATH, |
| 9895 | .doit = nl80211_del_mpath, |
| 9896 | .policy = nl80211_policy, |
| 9897 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9898 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9899 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9900 | }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 9901 | { |
| 9902 | .cmd = NL80211_CMD_SET_BSS, |
| 9903 | .doit = nl80211_set_bss, |
| 9904 | .policy = nl80211_policy, |
| 9905 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9906 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9907 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 9908 | }, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 9909 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 9910 | .cmd = NL80211_CMD_GET_REG, |
| 9911 | .doit = nl80211_get_reg, |
| 9912 | .policy = nl80211_policy, |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 9913 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 9914 | /* can be retrieved by unprivileged users */ |
| 9915 | }, |
| 9916 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 9917 | .cmd = NL80211_CMD_SET_REG, |
| 9918 | .doit = nl80211_set_reg, |
| 9919 | .policy = nl80211_policy, |
| 9920 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 9921 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 9922 | }, |
| 9923 | { |
| 9924 | .cmd = NL80211_CMD_REQ_SET_REG, |
| 9925 | .doit = nl80211_req_set_reg, |
| 9926 | .policy = nl80211_policy, |
| 9927 | .flags = GENL_ADMIN_PERM, |
| 9928 | }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 9929 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 9930 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
| 9931 | .doit = nl80211_get_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 9932 | .policy = nl80211_policy, |
| 9933 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9934 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9935 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 9936 | }, |
| 9937 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 9938 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
| 9939 | .doit = nl80211_update_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 9940 | .policy = nl80211_policy, |
| 9941 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 9942 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9943 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 9944 | }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 9945 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9946 | .cmd = NL80211_CMD_TRIGGER_SCAN, |
| 9947 | .doit = nl80211_trigger_scan, |
| 9948 | .policy = nl80211_policy, |
| 9949 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9950 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9951 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9952 | }, |
| 9953 | { |
| 9954 | .cmd = NL80211_CMD_GET_SCAN, |
| 9955 | .policy = nl80211_policy, |
| 9956 | .dumpit = nl80211_dump_scan, |
| 9957 | }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9958 | { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9959 | .cmd = NL80211_CMD_START_SCHED_SCAN, |
| 9960 | .doit = nl80211_start_sched_scan, |
| 9961 | .policy = nl80211_policy, |
| 9962 | .flags = GENL_ADMIN_PERM, |
| 9963 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9964 | NL80211_FLAG_NEED_RTNL, |
| 9965 | }, |
| 9966 | { |
| 9967 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, |
| 9968 | .doit = nl80211_stop_sched_scan, |
| 9969 | .policy = nl80211_policy, |
| 9970 | .flags = GENL_ADMIN_PERM, |
| 9971 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9972 | NL80211_FLAG_NEED_RTNL, |
| 9973 | }, |
| 9974 | { |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9975 | .cmd = NL80211_CMD_AUTHENTICATE, |
| 9976 | .doit = nl80211_authenticate, |
| 9977 | .policy = nl80211_policy, |
| 9978 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9979 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 9980 | NL80211_FLAG_NEED_RTNL | |
| 9981 | NL80211_FLAG_CLEAR_SKB, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9982 | }, |
| 9983 | { |
| 9984 | .cmd = NL80211_CMD_ASSOCIATE, |
| 9985 | .doit = nl80211_associate, |
| 9986 | .policy = nl80211_policy, |
| 9987 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9988 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9989 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9990 | }, |
| 9991 | { |
| 9992 | .cmd = NL80211_CMD_DEAUTHENTICATE, |
| 9993 | .doit = nl80211_deauthenticate, |
| 9994 | .policy = nl80211_policy, |
| 9995 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9996 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9997 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9998 | }, |
| 9999 | { |
| 10000 | .cmd = NL80211_CMD_DISASSOCIATE, |
| 10001 | .doit = nl80211_disassociate, |
| 10002 | .policy = nl80211_policy, |
| 10003 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10004 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10005 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 10006 | }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10007 | { |
| 10008 | .cmd = NL80211_CMD_JOIN_IBSS, |
| 10009 | .doit = nl80211_join_ibss, |
| 10010 | .policy = nl80211_policy, |
| 10011 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10012 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10013 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10014 | }, |
| 10015 | { |
| 10016 | .cmd = NL80211_CMD_LEAVE_IBSS, |
| 10017 | .doit = nl80211_leave_ibss, |
| 10018 | .policy = nl80211_policy, |
| 10019 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10020 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10021 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10022 | }, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 10023 | #ifdef CONFIG_NL80211_TESTMODE |
| 10024 | { |
| 10025 | .cmd = NL80211_CMD_TESTMODE, |
| 10026 | .doit = nl80211_testmode_do, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 10027 | .dumpit = nl80211_testmode_dump, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 10028 | .policy = nl80211_policy, |
| 10029 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10030 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 10031 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 10032 | }, |
| 10033 | #endif |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10034 | { |
| 10035 | .cmd = NL80211_CMD_CONNECT, |
| 10036 | .doit = nl80211_connect, |
| 10037 | .policy = nl80211_policy, |
| 10038 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10039 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10040 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10041 | }, |
| 10042 | { |
| 10043 | .cmd = NL80211_CMD_DISCONNECT, |
| 10044 | .doit = nl80211_disconnect, |
| 10045 | .policy = nl80211_policy, |
| 10046 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10047 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10048 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10049 | }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 10050 | { |
| 10051 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, |
| 10052 | .doit = nl80211_wiphy_netns, |
| 10053 | .policy = nl80211_policy, |
| 10054 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10055 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 10056 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 10057 | }, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 10058 | { |
| 10059 | .cmd = NL80211_CMD_GET_SURVEY, |
| 10060 | .policy = nl80211_policy, |
| 10061 | .dumpit = nl80211_dump_survey, |
| 10062 | }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 10063 | { |
| 10064 | .cmd = NL80211_CMD_SET_PMKSA, |
| 10065 | .doit = nl80211_setdel_pmksa, |
| 10066 | .policy = nl80211_policy, |
| 10067 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 10068 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10069 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 10070 | }, |
| 10071 | { |
| 10072 | .cmd = NL80211_CMD_DEL_PMKSA, |
| 10073 | .doit = nl80211_setdel_pmksa, |
| 10074 | .policy = nl80211_policy, |
| 10075 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 10076 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10077 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 10078 | }, |
| 10079 | { |
| 10080 | .cmd = NL80211_CMD_FLUSH_PMKSA, |
| 10081 | .doit = nl80211_flush_pmksa, |
| 10082 | .policy = nl80211_policy, |
| 10083 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 10084 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10085 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 10086 | }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10087 | { |
| 10088 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, |
| 10089 | .doit = nl80211_remain_on_channel, |
| 10090 | .policy = nl80211_policy, |
| 10091 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10092 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10093 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10094 | }, |
| 10095 | { |
| 10096 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
| 10097 | .doit = nl80211_cancel_remain_on_channel, |
| 10098 | .policy = nl80211_policy, |
| 10099 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10100 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10101 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10102 | }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 10103 | { |
| 10104 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, |
| 10105 | .doit = nl80211_set_tx_bitrate_mask, |
| 10106 | .policy = nl80211_policy, |
| 10107 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10108 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 10109 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 10110 | }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10111 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 10112 | .cmd = NL80211_CMD_REGISTER_FRAME, |
| 10113 | .doit = nl80211_register_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10114 | .policy = nl80211_policy, |
| 10115 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10116 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10117 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10118 | }, |
| 10119 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 10120 | .cmd = NL80211_CMD_FRAME, |
| 10121 | .doit = nl80211_tx_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10122 | .policy = nl80211_policy, |
| 10123 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10124 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10125 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10126 | }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 10127 | { |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 10128 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, |
| 10129 | .doit = nl80211_tx_mgmt_cancel_wait, |
| 10130 | .policy = nl80211_policy, |
| 10131 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10132 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 10133 | NL80211_FLAG_NEED_RTNL, |
| 10134 | }, |
| 10135 | { |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 10136 | .cmd = NL80211_CMD_SET_POWER_SAVE, |
| 10137 | .doit = nl80211_set_power_save, |
| 10138 | .policy = nl80211_policy, |
| 10139 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10140 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 10141 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 10142 | }, |
| 10143 | { |
| 10144 | .cmd = NL80211_CMD_GET_POWER_SAVE, |
| 10145 | .doit = nl80211_get_power_save, |
| 10146 | .policy = nl80211_policy, |
| 10147 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10148 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 10149 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 10150 | }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10151 | { |
| 10152 | .cmd = NL80211_CMD_SET_CQM, |
| 10153 | .doit = nl80211_set_cqm, |
| 10154 | .policy = nl80211_policy, |
| 10155 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10156 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 10157 | NL80211_FLAG_NEED_RTNL, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10158 | }, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 10159 | { |
| 10160 | .cmd = NL80211_CMD_SET_CHANNEL, |
| 10161 | .doit = nl80211_set_channel, |
| 10162 | .policy = nl80211_policy, |
| 10163 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10164 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 10165 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 10166 | }, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 10167 | { |
| 10168 | .cmd = NL80211_CMD_SET_WDS_PEER, |
| 10169 | .doit = nl80211_set_wds_peer, |
| 10170 | .policy = nl80211_policy, |
| 10171 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 10172 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 10173 | NL80211_FLAG_NEED_RTNL, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 10174 | }, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 10175 | { |
| 10176 | .cmd = NL80211_CMD_JOIN_MESH, |
| 10177 | .doit = nl80211_join_mesh, |
| 10178 | .policy = nl80211_policy, |
| 10179 | .flags = GENL_ADMIN_PERM, |
| 10180 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10181 | NL80211_FLAG_NEED_RTNL, |
| 10182 | }, |
| 10183 | { |
| 10184 | .cmd = NL80211_CMD_LEAVE_MESH, |
| 10185 | .doit = nl80211_leave_mesh, |
| 10186 | .policy = nl80211_policy, |
| 10187 | .flags = GENL_ADMIN_PERM, |
| 10188 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10189 | NL80211_FLAG_NEED_RTNL, |
| 10190 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 10191 | #ifdef CONFIG_PM |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10192 | { |
| 10193 | .cmd = NL80211_CMD_GET_WOWLAN, |
| 10194 | .doit = nl80211_get_wowlan, |
| 10195 | .policy = nl80211_policy, |
| 10196 | /* can be retrieved by unprivileged users */ |
| 10197 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 10198 | NL80211_FLAG_NEED_RTNL, |
| 10199 | }, |
| 10200 | { |
| 10201 | .cmd = NL80211_CMD_SET_WOWLAN, |
| 10202 | .doit = nl80211_set_wowlan, |
| 10203 | .policy = nl80211_policy, |
| 10204 | .flags = GENL_ADMIN_PERM, |
| 10205 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 10206 | NL80211_FLAG_NEED_RTNL, |
| 10207 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 10208 | #endif |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10209 | { |
| 10210 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, |
| 10211 | .doit = nl80211_set_rekey_data, |
| 10212 | .policy = nl80211_policy, |
| 10213 | .flags = GENL_ADMIN_PERM, |
| 10214 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 10215 | NL80211_FLAG_NEED_RTNL | |
| 10216 | NL80211_FLAG_CLEAR_SKB, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10217 | }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 10218 | { |
| 10219 | .cmd = NL80211_CMD_TDLS_MGMT, |
| 10220 | .doit = nl80211_tdls_mgmt, |
| 10221 | .policy = nl80211_policy, |
| 10222 | .flags = GENL_ADMIN_PERM, |
| 10223 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10224 | NL80211_FLAG_NEED_RTNL, |
| 10225 | }, |
| 10226 | { |
| 10227 | .cmd = NL80211_CMD_TDLS_OPER, |
| 10228 | .doit = nl80211_tdls_oper, |
| 10229 | .policy = nl80211_policy, |
| 10230 | .flags = GENL_ADMIN_PERM, |
| 10231 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10232 | NL80211_FLAG_NEED_RTNL, |
| 10233 | }, |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10234 | { |
| 10235 | .cmd = NL80211_CMD_UNEXPECTED_FRAME, |
| 10236 | .doit = nl80211_register_unexpected_frame, |
| 10237 | .policy = nl80211_policy, |
| 10238 | .flags = GENL_ADMIN_PERM, |
| 10239 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 10240 | NL80211_FLAG_NEED_RTNL, |
| 10241 | }, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 10242 | { |
| 10243 | .cmd = NL80211_CMD_PROBE_CLIENT, |
| 10244 | .doit = nl80211_probe_client, |
| 10245 | .policy = nl80211_policy, |
| 10246 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 10247 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 10248 | NL80211_FLAG_NEED_RTNL, |
| 10249 | }, |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10250 | { |
| 10251 | .cmd = NL80211_CMD_REGISTER_BEACONS, |
| 10252 | .doit = nl80211_register_beacons, |
| 10253 | .policy = nl80211_policy, |
| 10254 | .flags = GENL_ADMIN_PERM, |
| 10255 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 10256 | NL80211_FLAG_NEED_RTNL, |
| 10257 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 10258 | { |
| 10259 | .cmd = NL80211_CMD_SET_NOACK_MAP, |
| 10260 | .doit = nl80211_set_noack_map, |
| 10261 | .policy = nl80211_policy, |
| 10262 | .flags = GENL_ADMIN_PERM, |
| 10263 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 10264 | NL80211_FLAG_NEED_RTNL, |
| 10265 | }, |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 10266 | { |
| 10267 | .cmd = NL80211_CMD_START_P2P_DEVICE, |
| 10268 | .doit = nl80211_start_p2p_device, |
| 10269 | .policy = nl80211_policy, |
| 10270 | .flags = GENL_ADMIN_PERM, |
| 10271 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 10272 | NL80211_FLAG_NEED_RTNL, |
| 10273 | }, |
| 10274 | { |
| 10275 | .cmd = NL80211_CMD_STOP_P2P_DEVICE, |
| 10276 | .doit = nl80211_stop_p2p_device, |
| 10277 | .policy = nl80211_policy, |
| 10278 | .flags = GENL_ADMIN_PERM, |
| 10279 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 10280 | NL80211_FLAG_NEED_RTNL, |
| 10281 | }, |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 10282 | { |
| 10283 | .cmd = NL80211_CMD_SET_MCAST_RATE, |
| 10284 | .doit = nl80211_set_mcast_rate, |
| 10285 | .policy = nl80211_policy, |
| 10286 | .flags = GENL_ADMIN_PERM, |
| 10287 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 10288 | NL80211_FLAG_NEED_RTNL, |
| 10289 | }, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 10290 | { |
| 10291 | .cmd = NL80211_CMD_SET_MAC_ACL, |
| 10292 | .doit = nl80211_set_mac_acl, |
| 10293 | .policy = nl80211_policy, |
| 10294 | .flags = GENL_ADMIN_PERM, |
| 10295 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 10296 | NL80211_FLAG_NEED_RTNL, |
| 10297 | }, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 10298 | { |
| 10299 | .cmd = NL80211_CMD_RADAR_DETECT, |
| 10300 | .doit = nl80211_start_radar_detection, |
| 10301 | .policy = nl80211_policy, |
| 10302 | .flags = GENL_ADMIN_PERM, |
| 10303 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10304 | NL80211_FLAG_NEED_RTNL, |
| 10305 | }, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 10306 | { |
| 10307 | .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES, |
| 10308 | .doit = nl80211_get_protocol_features, |
| 10309 | .policy = nl80211_policy, |
| 10310 | }, |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 10311 | { |
| 10312 | .cmd = NL80211_CMD_UPDATE_FT_IES, |
| 10313 | .doit = nl80211_update_ft_ies, |
| 10314 | .policy = nl80211_policy, |
| 10315 | .flags = GENL_ADMIN_PERM, |
| 10316 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10317 | NL80211_FLAG_NEED_RTNL, |
| 10318 | }, |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 10319 | { |
| 10320 | .cmd = NL80211_CMD_CRIT_PROTOCOL_START, |
| 10321 | .doit = nl80211_crit_protocol_start, |
| 10322 | .policy = nl80211_policy, |
| 10323 | .flags = GENL_ADMIN_PERM, |
| 10324 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 10325 | NL80211_FLAG_NEED_RTNL, |
| 10326 | }, |
| 10327 | { |
| 10328 | .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP, |
| 10329 | .doit = nl80211_crit_protocol_stop, |
| 10330 | .policy = nl80211_policy, |
| 10331 | .flags = GENL_ADMIN_PERM, |
| 10332 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 10333 | NL80211_FLAG_NEED_RTNL, |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 10334 | }, |
| 10335 | { |
| 10336 | .cmd = NL80211_CMD_GET_COALESCE, |
| 10337 | .doit = nl80211_get_coalesce, |
| 10338 | .policy = nl80211_policy, |
| 10339 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 10340 | NL80211_FLAG_NEED_RTNL, |
| 10341 | }, |
| 10342 | { |
| 10343 | .cmd = NL80211_CMD_SET_COALESCE, |
| 10344 | .doit = nl80211_set_coalesce, |
| 10345 | .policy = nl80211_policy, |
| 10346 | .flags = GENL_ADMIN_PERM, |
| 10347 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 10348 | NL80211_FLAG_NEED_RTNL, |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 10349 | }, |
| 10350 | { |
| 10351 | .cmd = NL80211_CMD_CHANNEL_SWITCH, |
| 10352 | .doit = nl80211_channel_switch, |
| 10353 | .policy = nl80211_policy, |
| 10354 | .flags = GENL_ADMIN_PERM, |
| 10355 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10356 | NL80211_FLAG_NEED_RTNL, |
| 10357 | }, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 10358 | { |
| 10359 | .cmd = NL80211_CMD_VENDOR, |
| 10360 | .doit = nl80211_vendor_cmd, |
| 10361 | .policy = nl80211_policy, |
| 10362 | .flags = GENL_ADMIN_PERM, |
| 10363 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 10364 | NL80211_FLAG_NEED_RTNL, |
| 10365 | }, |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 10366 | { |
| 10367 | .cmd = NL80211_CMD_SET_QOS_MAP, |
| 10368 | .doit = nl80211_set_qos_map, |
| 10369 | .policy = nl80211_policy, |
| 10370 | .flags = GENL_ADMIN_PERM, |
| 10371 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10372 | NL80211_FLAG_NEED_RTNL, |
| 10373 | }, |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 10374 | { |
| 10375 | .cmd = NL80211_CMD_ADD_TX_TS, |
| 10376 | .doit = nl80211_add_tx_ts, |
| 10377 | .policy = nl80211_policy, |
| 10378 | .flags = GENL_ADMIN_PERM, |
| 10379 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10380 | NL80211_FLAG_NEED_RTNL, |
| 10381 | }, |
| 10382 | { |
| 10383 | .cmd = NL80211_CMD_DEL_TX_TS, |
| 10384 | .doit = nl80211_del_tx_ts, |
| 10385 | .policy = nl80211_policy, |
| 10386 | .flags = GENL_ADMIN_PERM, |
| 10387 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10388 | NL80211_FLAG_NEED_RTNL, |
| 10389 | }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10390 | }; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10391 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10392 | /* notification functions */ |
| 10393 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 10394 | void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev, |
| 10395 | enum nl80211_commands cmd) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10396 | { |
| 10397 | struct sk_buff *msg; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 10398 | struct nl80211_dump_wiphy_state state = {}; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10399 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 10400 | WARN_ON(cmd != NL80211_CMD_NEW_WIPHY && |
| 10401 | cmd != NL80211_CMD_DEL_WIPHY); |
| 10402 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 10403 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10404 | if (!msg) |
| 10405 | return; |
| 10406 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 10407 | if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10408 | nlmsg_free(msg); |
| 10409 | return; |
| 10410 | } |
| 10411 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10412 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10413 | NL80211_MCGRP_CONFIG, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10414 | } |
| 10415 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 10416 | static int nl80211_add_scan_req(struct sk_buff *msg, |
| 10417 | struct cfg80211_registered_device *rdev) |
| 10418 | { |
| 10419 | struct cfg80211_scan_request *req = rdev->scan_req; |
| 10420 | struct nlattr *nest; |
| 10421 | int i; |
| 10422 | |
| 10423 | if (WARN_ON(!req)) |
| 10424 | return 0; |
| 10425 | |
| 10426 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); |
| 10427 | if (!nest) |
| 10428 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10429 | for (i = 0; i < req->n_ssids; i++) { |
| 10430 | if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) |
| 10431 | goto nla_put_failure; |
| 10432 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 10433 | nla_nest_end(msg, nest); |
| 10434 | |
| 10435 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 10436 | if (!nest) |
| 10437 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10438 | for (i = 0; i < req->n_channels; i++) { |
| 10439 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) |
| 10440 | goto nla_put_failure; |
| 10441 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 10442 | nla_nest_end(msg, nest); |
| 10443 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10444 | if (req->ie && |
| 10445 | nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie)) |
| 10446 | goto nla_put_failure; |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 10447 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 10448 | if (req->flags && |
| 10449 | nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags)) |
| 10450 | goto nla_put_failure; |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 10451 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 10452 | return 0; |
| 10453 | nla_put_failure: |
| 10454 | return -ENOBUFS; |
| 10455 | } |
| 10456 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 10457 | static int nl80211_send_scan_msg(struct sk_buff *msg, |
| 10458 | struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 10459 | struct wireless_dev *wdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10460 | u32 portid, u32 seq, int flags, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 10461 | u32 cmd) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10462 | { |
| 10463 | void *hdr; |
| 10464 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10465 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10466 | if (!hdr) |
| 10467 | return -1; |
| 10468 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10469 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 10470 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 10471 | wdev->netdev->ifindex)) || |
| 10472 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10473 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10474 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 10475 | /* ignore errors and send incomplete event anyway */ |
| 10476 | nl80211_add_scan_req(msg, rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10477 | |
| 10478 | return genlmsg_end(msg, hdr); |
| 10479 | |
| 10480 | nla_put_failure: |
| 10481 | genlmsg_cancel(msg, hdr); |
| 10482 | return -EMSGSIZE; |
| 10483 | } |
| 10484 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 10485 | static int |
| 10486 | nl80211_send_sched_scan_msg(struct sk_buff *msg, |
| 10487 | struct cfg80211_registered_device *rdev, |
| 10488 | struct net_device *netdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10489 | u32 portid, u32 seq, int flags, u32 cmd) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 10490 | { |
| 10491 | void *hdr; |
| 10492 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10493 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 10494 | if (!hdr) |
| 10495 | return -1; |
| 10496 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10497 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10498 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 10499 | goto nla_put_failure; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 10500 | |
| 10501 | return genlmsg_end(msg, hdr); |
| 10502 | |
| 10503 | nla_put_failure: |
| 10504 | genlmsg_cancel(msg, hdr); |
| 10505 | return -EMSGSIZE; |
| 10506 | } |
| 10507 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 10508 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 10509 | struct wireless_dev *wdev) |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 10510 | { |
| 10511 | struct sk_buff *msg; |
| 10512 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10513 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 10514 | if (!msg) |
| 10515 | return; |
| 10516 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 10517 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 10518 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
| 10519 | nlmsg_free(msg); |
| 10520 | return; |
| 10521 | } |
| 10522 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10523 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10524 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 10525 | } |
| 10526 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 10527 | struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev, |
| 10528 | struct wireless_dev *wdev, bool aborted) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10529 | { |
| 10530 | struct sk_buff *msg; |
| 10531 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 10532 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10533 | if (!msg) |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 10534 | return NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10535 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 10536 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 10537 | aborted ? NL80211_CMD_SCAN_ABORTED : |
| 10538 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10539 | nlmsg_free(msg); |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 10540 | return NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10541 | } |
| 10542 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 10543 | return msg; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10544 | } |
| 10545 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 10546 | void nl80211_send_scan_result(struct cfg80211_registered_device *rdev, |
| 10547 | struct sk_buff *msg) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10548 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10549 | if (!msg) |
| 10550 | return; |
| 10551 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10552 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10553 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10554 | } |
| 10555 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 10556 | void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev, |
| 10557 | struct net_device *netdev) |
| 10558 | { |
| 10559 | struct sk_buff *msg; |
| 10560 | |
| 10561 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 10562 | if (!msg) |
| 10563 | return; |
| 10564 | |
| 10565 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 10566 | NL80211_CMD_SCHED_SCAN_RESULTS) < 0) { |
| 10567 | nlmsg_free(msg); |
| 10568 | return; |
| 10569 | } |
| 10570 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10571 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10572 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 10573 | } |
| 10574 | |
| 10575 | void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev, |
| 10576 | struct net_device *netdev, u32 cmd) |
| 10577 | { |
| 10578 | struct sk_buff *msg; |
| 10579 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10580 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 10581 | if (!msg) |
| 10582 | return; |
| 10583 | |
| 10584 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) { |
| 10585 | nlmsg_free(msg); |
| 10586 | return; |
| 10587 | } |
| 10588 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10589 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10590 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 10591 | } |
| 10592 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 10593 | /* |
| 10594 | * This can happen on global regulatory changes or device specific settings |
| 10595 | * based on custom world regulatory domains. |
| 10596 | */ |
| 10597 | void nl80211_send_reg_change_event(struct regulatory_request *request) |
| 10598 | { |
| 10599 | struct sk_buff *msg; |
| 10600 | void *hdr; |
| 10601 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 10602 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 10603 | if (!msg) |
| 10604 | return; |
| 10605 | |
| 10606 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE); |
| 10607 | if (!hdr) { |
| 10608 | nlmsg_free(msg); |
| 10609 | return; |
| 10610 | } |
| 10611 | |
| 10612 | /* Userspace can always count this one always being set */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10613 | if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator)) |
| 10614 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 10615 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10616 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') { |
| 10617 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 10618 | NL80211_REGDOM_TYPE_WORLD)) |
| 10619 | goto nla_put_failure; |
| 10620 | } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') { |
| 10621 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 10622 | NL80211_REGDOM_TYPE_CUSTOM_WORLD)) |
| 10623 | goto nla_put_failure; |
| 10624 | } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || |
| 10625 | request->intersect) { |
| 10626 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 10627 | NL80211_REGDOM_TYPE_INTERSECTION)) |
| 10628 | goto nla_put_failure; |
| 10629 | } else { |
| 10630 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 10631 | NL80211_REGDOM_TYPE_COUNTRY) || |
| 10632 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, |
| 10633 | request->alpha2)) |
| 10634 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 10635 | } |
| 10636 | |
Johannes Berg | f417376 | 2012-12-03 18:23:37 +0100 | [diff] [blame] | 10637 | if (request->wiphy_idx != WIPHY_IDX_INVALID && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10638 | nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) |
| 10639 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 10640 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10641 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 10642 | |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 10643 | rcu_read_lock(); |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10644 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10645 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 10646 | rcu_read_unlock(); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 10647 | |
| 10648 | return; |
| 10649 | |
| 10650 | nla_put_failure: |
| 10651 | genlmsg_cancel(msg, hdr); |
| 10652 | nlmsg_free(msg); |
| 10653 | } |
| 10654 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10655 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
| 10656 | struct net_device *netdev, |
| 10657 | const u8 *buf, size_t len, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 10658 | enum nl80211_commands cmd, gfp_t gfp, |
| 10659 | int uapsd_queues) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10660 | { |
| 10661 | struct sk_buff *msg; |
| 10662 | void *hdr; |
| 10663 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10664 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10665 | if (!msg) |
| 10666 | return; |
| 10667 | |
| 10668 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 10669 | if (!hdr) { |
| 10670 | nlmsg_free(msg); |
| 10671 | return; |
| 10672 | } |
| 10673 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10674 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10675 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10676 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) |
| 10677 | goto nla_put_failure; |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10678 | |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 10679 | if (uapsd_queues >= 0) { |
| 10680 | struct nlattr *nla_wmm = |
| 10681 | nla_nest_start(msg, NL80211_ATTR_STA_WME); |
| 10682 | if (!nla_wmm) |
| 10683 | goto nla_put_failure; |
| 10684 | |
| 10685 | if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES, |
| 10686 | uapsd_queues)) |
| 10687 | goto nla_put_failure; |
| 10688 | |
| 10689 | nla_nest_end(msg, nla_wmm); |
| 10690 | } |
| 10691 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10692 | genlmsg_end(msg, hdr); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10693 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10694 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10695 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10696 | return; |
| 10697 | |
| 10698 | nla_put_failure: |
| 10699 | genlmsg_cancel(msg, hdr); |
| 10700 | nlmsg_free(msg); |
| 10701 | } |
| 10702 | |
| 10703 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10704 | struct net_device *netdev, const u8 *buf, |
| 10705 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10706 | { |
| 10707 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 10708 | NL80211_CMD_AUTHENTICATE, gfp, -1); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10709 | } |
| 10710 | |
| 10711 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, |
| 10712 | struct net_device *netdev, const u8 *buf, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 10713 | size_t len, gfp_t gfp, int uapsd_queues) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10714 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10715 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 10716 | NL80211_CMD_ASSOCIATE, gfp, uapsd_queues); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10717 | } |
| 10718 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 10719 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10720 | struct net_device *netdev, const u8 *buf, |
| 10721 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10722 | { |
| 10723 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 10724 | NL80211_CMD_DEAUTHENTICATE, gfp, -1); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10725 | } |
| 10726 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 10727 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
| 10728 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10729 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10730 | { |
| 10731 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 10732 | NL80211_CMD_DISASSOCIATE, gfp, -1); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10733 | } |
| 10734 | |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 10735 | void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf, |
| 10736 | size_t len) |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 10737 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10738 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10739 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 10740 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 10741 | const struct ieee80211_mgmt *mgmt = (void *)buf; |
| 10742 | u32 cmd; |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 10743 | |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 10744 | if (WARN_ON(len < 2)) |
| 10745 | return; |
| 10746 | |
| 10747 | if (ieee80211_is_deauth(mgmt->frame_control)) |
| 10748 | cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE; |
| 10749 | else |
| 10750 | cmd = NL80211_CMD_UNPROT_DISASSOCIATE; |
| 10751 | |
| 10752 | trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len); |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 10753 | nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1); |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 10754 | } |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 10755 | EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt); |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 10756 | |
Luis R. Rodriguez | 1b06bb4 | 2009-05-02 00:34:48 -0400 | [diff] [blame] | 10757 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
| 10758 | struct net_device *netdev, int cmd, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10759 | const u8 *addr, gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10760 | { |
| 10761 | struct sk_buff *msg; |
| 10762 | void *hdr; |
| 10763 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10764 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10765 | if (!msg) |
| 10766 | return; |
| 10767 | |
| 10768 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 10769 | if (!hdr) { |
| 10770 | nlmsg_free(msg); |
| 10771 | return; |
| 10772 | } |
| 10773 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10774 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10775 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10776 | nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || |
| 10777 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 10778 | goto nla_put_failure; |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10779 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10780 | genlmsg_end(msg, hdr); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10781 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10782 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10783 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10784 | return; |
| 10785 | |
| 10786 | nla_put_failure: |
| 10787 | genlmsg_cancel(msg, hdr); |
| 10788 | nlmsg_free(msg); |
| 10789 | } |
| 10790 | |
| 10791 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10792 | struct net_device *netdev, const u8 *addr, |
| 10793 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10794 | { |
| 10795 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10796 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10797 | } |
| 10798 | |
| 10799 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10800 | struct net_device *netdev, const u8 *addr, |
| 10801 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10802 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10803 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
| 10804 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10805 | } |
| 10806 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10807 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
| 10808 | struct net_device *netdev, const u8 *bssid, |
| 10809 | const u8 *req_ie, size_t req_ie_len, |
| 10810 | const u8 *resp_ie, size_t resp_ie_len, |
| 10811 | u16 status, gfp_t gfp) |
| 10812 | { |
| 10813 | struct sk_buff *msg; |
| 10814 | void *hdr; |
| 10815 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10816 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10817 | if (!msg) |
| 10818 | return; |
| 10819 | |
| 10820 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); |
| 10821 | if (!hdr) { |
| 10822 | nlmsg_free(msg); |
| 10823 | return; |
| 10824 | } |
| 10825 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10826 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10827 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10828 | (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) || |
| 10829 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) || |
| 10830 | (req_ie && |
| 10831 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 10832 | (resp_ie && |
| 10833 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 10834 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10835 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10836 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10837 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10838 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10839 | NL80211_MCGRP_MLME, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10840 | return; |
| 10841 | |
| 10842 | nla_put_failure: |
| 10843 | genlmsg_cancel(msg, hdr); |
| 10844 | nlmsg_free(msg); |
| 10845 | |
| 10846 | } |
| 10847 | |
| 10848 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, |
| 10849 | struct net_device *netdev, const u8 *bssid, |
| 10850 | const u8 *req_ie, size_t req_ie_len, |
| 10851 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) |
| 10852 | { |
| 10853 | struct sk_buff *msg; |
| 10854 | void *hdr; |
| 10855 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10856 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10857 | if (!msg) |
| 10858 | return; |
| 10859 | |
| 10860 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); |
| 10861 | if (!hdr) { |
| 10862 | nlmsg_free(msg); |
| 10863 | return; |
| 10864 | } |
| 10865 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10866 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10867 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10868 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) || |
| 10869 | (req_ie && |
| 10870 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 10871 | (resp_ie && |
| 10872 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 10873 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10874 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10875 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10876 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10877 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10878 | NL80211_MCGRP_MLME, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10879 | return; |
| 10880 | |
| 10881 | nla_put_failure: |
| 10882 | genlmsg_cancel(msg, hdr); |
| 10883 | nlmsg_free(msg); |
| 10884 | |
| 10885 | } |
| 10886 | |
| 10887 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, |
| 10888 | struct net_device *netdev, u16 reason, |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 10889 | const u8 *ie, size_t ie_len, bool from_ap) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10890 | { |
| 10891 | struct sk_buff *msg; |
| 10892 | void *hdr; |
| 10893 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10894 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10895 | if (!msg) |
| 10896 | return; |
| 10897 | |
| 10898 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); |
| 10899 | if (!hdr) { |
| 10900 | nlmsg_free(msg); |
| 10901 | return; |
| 10902 | } |
| 10903 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10904 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10905 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10906 | (from_ap && reason && |
| 10907 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) || |
| 10908 | (from_ap && |
| 10909 | nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) || |
| 10910 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) |
| 10911 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10912 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10913 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10914 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10915 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10916 | NL80211_MCGRP_MLME, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10917 | return; |
| 10918 | |
| 10919 | nla_put_failure: |
| 10920 | genlmsg_cancel(msg, hdr); |
| 10921 | nlmsg_free(msg); |
| 10922 | |
| 10923 | } |
| 10924 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10925 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
| 10926 | struct net_device *netdev, const u8 *bssid, |
| 10927 | gfp_t gfp) |
| 10928 | { |
| 10929 | struct sk_buff *msg; |
| 10930 | void *hdr; |
| 10931 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 10932 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10933 | if (!msg) |
| 10934 | return; |
| 10935 | |
| 10936 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); |
| 10937 | if (!hdr) { |
| 10938 | nlmsg_free(msg); |
| 10939 | return; |
| 10940 | } |
| 10941 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10942 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10943 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10944 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 10945 | goto nla_put_failure; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10946 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10947 | genlmsg_end(msg, hdr); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10948 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10949 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10950 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10951 | return; |
| 10952 | |
| 10953 | nla_put_failure: |
| 10954 | genlmsg_cancel(msg, hdr); |
| 10955 | nlmsg_free(msg); |
| 10956 | } |
| 10957 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10958 | void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr, |
| 10959 | const u8* ie, u8 ie_len, gfp_t gfp) |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10960 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10961 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 10962 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10963 | struct sk_buff *msg; |
| 10964 | void *hdr; |
| 10965 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10966 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT)) |
| 10967 | return; |
| 10968 | |
| 10969 | trace_cfg80211_notify_new_peer_candidate(dev, addr); |
| 10970 | |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10971 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 10972 | if (!msg) |
| 10973 | return; |
| 10974 | |
| 10975 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); |
| 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 | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10982 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 10983 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10984 | (ie_len && ie && |
| 10985 | nla_put(msg, NL80211_ATTR_IE, ie_len , ie))) |
| 10986 | goto nla_put_failure; |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10987 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10988 | genlmsg_end(msg, hdr); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10989 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10990 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10991 | NL80211_MCGRP_MLME, gfp); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10992 | return; |
| 10993 | |
| 10994 | nla_put_failure: |
| 10995 | genlmsg_cancel(msg, hdr); |
| 10996 | nlmsg_free(msg); |
| 10997 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10998 | EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10999 | |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 11000 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
| 11001 | struct net_device *netdev, const u8 *addr, |
| 11002 | enum nl80211_key_type key_type, int key_id, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 11003 | const u8 *tsc, gfp_t gfp) |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 11004 | { |
| 11005 | struct sk_buff *msg; |
| 11006 | void *hdr; |
| 11007 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 11008 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 11009 | if (!msg) |
| 11010 | return; |
| 11011 | |
| 11012 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); |
| 11013 | if (!hdr) { |
| 11014 | nlmsg_free(msg); |
| 11015 | return; |
| 11016 | } |
| 11017 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11018 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11019 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 11020 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
| 11021 | nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) || |
| 11022 | (key_id != -1 && |
| 11023 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) || |
| 11024 | (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc))) |
| 11025 | goto nla_put_failure; |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 11026 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11027 | genlmsg_end(msg, hdr); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 11028 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11029 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11030 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 11031 | return; |
| 11032 | |
| 11033 | nla_put_failure: |
| 11034 | genlmsg_cancel(msg, hdr); |
| 11035 | nlmsg_free(msg); |
| 11036 | } |
| 11037 | |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 11038 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
| 11039 | struct ieee80211_channel *channel_before, |
| 11040 | struct ieee80211_channel *channel_after) |
| 11041 | { |
| 11042 | struct sk_buff *msg; |
| 11043 | void *hdr; |
| 11044 | struct nlattr *nl_freq; |
| 11045 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 11046 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 11047 | if (!msg) |
| 11048 | return; |
| 11049 | |
| 11050 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); |
| 11051 | if (!hdr) { |
| 11052 | nlmsg_free(msg); |
| 11053 | return; |
| 11054 | } |
| 11055 | |
| 11056 | /* |
| 11057 | * Since we are applying the beacon hint to a wiphy we know its |
| 11058 | * wiphy_idx is valid |
| 11059 | */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11060 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 11061 | goto nla_put_failure; |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 11062 | |
| 11063 | /* Before */ |
| 11064 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); |
| 11065 | if (!nl_freq) |
| 11066 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 11067 | if (nl80211_msg_put_channel(msg, channel_before, false)) |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 11068 | goto nla_put_failure; |
| 11069 | nla_nest_end(msg, nl_freq); |
| 11070 | |
| 11071 | /* After */ |
| 11072 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); |
| 11073 | if (!nl_freq) |
| 11074 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 11075 | if (nl80211_msg_put_channel(msg, channel_after, false)) |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 11076 | goto nla_put_failure; |
| 11077 | nla_nest_end(msg, nl_freq); |
| 11078 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11079 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 11080 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 11081 | rcu_read_lock(); |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11082 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11083 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 11084 | rcu_read_unlock(); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 11085 | |
| 11086 | return; |
| 11087 | |
| 11088 | nla_put_failure: |
| 11089 | genlmsg_cancel(msg, hdr); |
| 11090 | nlmsg_free(msg); |
| 11091 | } |
| 11092 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11093 | static void nl80211_send_remain_on_chan_event( |
| 11094 | int cmd, struct cfg80211_registered_device *rdev, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11095 | struct wireless_dev *wdev, u64 cookie, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11096 | struct ieee80211_channel *chan, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11097 | unsigned int duration, gfp_t gfp) |
| 11098 | { |
| 11099 | struct sk_buff *msg; |
| 11100 | void *hdr; |
| 11101 | |
| 11102 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 11103 | if (!msg) |
| 11104 | return; |
| 11105 | |
| 11106 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 11107 | if (!hdr) { |
| 11108 | nlmsg_free(msg); |
| 11109 | return; |
| 11110 | } |
| 11111 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11112 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11113 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 11114 | wdev->netdev->ifindex)) || |
Johannes Berg | 00f5335 | 2012-07-17 11:53:12 +0200 | [diff] [blame] | 11115 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11116 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) || |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 11117 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 11118 | NL80211_CHAN_NO_HT) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11119 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 11120 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11121 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11122 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL && |
| 11123 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) |
| 11124 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11125 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11126 | genlmsg_end(msg, hdr); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11127 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11128 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11129 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11130 | return; |
| 11131 | |
| 11132 | nla_put_failure: |
| 11133 | genlmsg_cancel(msg, hdr); |
| 11134 | nlmsg_free(msg); |
| 11135 | } |
| 11136 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11137 | void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie, |
| 11138 | struct ieee80211_channel *chan, |
| 11139 | unsigned int duration, gfp_t gfp) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11140 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11141 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11142 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11143 | |
| 11144 | trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11145 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11146 | rdev, wdev, cookie, chan, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 11147 | duration, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11148 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11149 | EXPORT_SYMBOL(cfg80211_ready_on_channel); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11150 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11151 | void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie, |
| 11152 | struct ieee80211_channel *chan, |
| 11153 | gfp_t gfp) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11154 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11155 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11156 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11157 | |
| 11158 | trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11159 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 11160 | rdev, wdev, cookie, chan, 0, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11161 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11162 | EXPORT_SYMBOL(cfg80211_remain_on_channel_expired); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11163 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11164 | void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr, |
| 11165 | struct station_info *sinfo, gfp_t gfp) |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 11166 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11167 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11168 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 11169 | struct sk_buff *msg; |
| 11170 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11171 | trace_cfg80211_new_sta(dev, mac_addr, sinfo); |
| 11172 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11173 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 11174 | if (!msg) |
| 11175 | return; |
| 11176 | |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 11177 | if (nl80211_send_station(msg, 0, 0, 0, |
| 11178 | rdev, dev, mac_addr, sinfo) < 0) { |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 11179 | nlmsg_free(msg); |
| 11180 | return; |
| 11181 | } |
| 11182 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11183 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11184 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 11185 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11186 | EXPORT_SYMBOL(cfg80211_new_sta); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 11187 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11188 | 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] | 11189 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11190 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11191 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 11192 | struct sk_buff *msg; |
| 11193 | void *hdr; |
| 11194 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11195 | trace_cfg80211_del_sta(dev, mac_addr); |
| 11196 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11197 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 11198 | if (!msg) |
| 11199 | return; |
| 11200 | |
| 11201 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION); |
| 11202 | if (!hdr) { |
| 11203 | nlmsg_free(msg); |
| 11204 | return; |
| 11205 | } |
| 11206 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11207 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 11208 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 11209 | goto nla_put_failure; |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 11210 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11211 | genlmsg_end(msg, hdr); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 11212 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11213 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11214 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 11215 | return; |
| 11216 | |
| 11217 | nla_put_failure: |
| 11218 | genlmsg_cancel(msg, hdr); |
| 11219 | nlmsg_free(msg); |
| 11220 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11221 | EXPORT_SYMBOL(cfg80211_del_sta); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 11222 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11223 | void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr, |
| 11224 | enum nl80211_connect_failed_reason reason, |
| 11225 | gfp_t gfp) |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 11226 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11227 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11228 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 11229 | struct sk_buff *msg; |
| 11230 | void *hdr; |
| 11231 | |
| 11232 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 11233 | if (!msg) |
| 11234 | return; |
| 11235 | |
| 11236 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED); |
| 11237 | if (!hdr) { |
| 11238 | nlmsg_free(msg); |
| 11239 | return; |
| 11240 | } |
| 11241 | |
| 11242 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 11243 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 11244 | nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason)) |
| 11245 | goto nla_put_failure; |
| 11246 | |
| 11247 | genlmsg_end(msg, hdr); |
| 11248 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11249 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11250 | NL80211_MCGRP_MLME, gfp); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 11251 | return; |
| 11252 | |
| 11253 | nla_put_failure: |
| 11254 | genlmsg_cancel(msg, hdr); |
| 11255 | nlmsg_free(msg); |
| 11256 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11257 | EXPORT_SYMBOL(cfg80211_conn_failed); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 11258 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 11259 | static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, |
| 11260 | const u8 *addr, gfp_t gfp) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 11261 | { |
| 11262 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11263 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 11264 | struct sk_buff *msg; |
| 11265 | void *hdr; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11266 | u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 11267 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11268 | if (!nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 11269 | return false; |
| 11270 | |
| 11271 | msg = nlmsg_new(100, gfp); |
| 11272 | if (!msg) |
| 11273 | return true; |
| 11274 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 11275 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 11276 | if (!hdr) { |
| 11277 | nlmsg_free(msg); |
| 11278 | return true; |
| 11279 | } |
| 11280 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11281 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11282 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 11283 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 11284 | goto nla_put_failure; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 11285 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 11286 | genlmsg_end(msg, hdr); |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11287 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 11288 | return true; |
| 11289 | |
| 11290 | nla_put_failure: |
| 11291 | genlmsg_cancel(msg, hdr); |
| 11292 | nlmsg_free(msg); |
| 11293 | return true; |
| 11294 | } |
| 11295 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11296 | bool cfg80211_rx_spurious_frame(struct net_device *dev, |
| 11297 | const u8 *addr, gfp_t gfp) |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 11298 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11299 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11300 | bool ret; |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 11301 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11302 | trace_cfg80211_rx_spurious_frame(dev, addr); |
| 11303 | |
| 11304 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 11305 | wdev->iftype != NL80211_IFTYPE_P2P_GO)) { |
| 11306 | trace_cfg80211_return_bool(false); |
| 11307 | return false; |
| 11308 | } |
| 11309 | ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, |
| 11310 | addr, gfp); |
| 11311 | trace_cfg80211_return_bool(ret); |
| 11312 | return ret; |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 11313 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11314 | EXPORT_SYMBOL(cfg80211_rx_spurious_frame); |
| 11315 | |
| 11316 | bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev, |
| 11317 | const u8 *addr, gfp_t gfp) |
| 11318 | { |
| 11319 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11320 | bool ret; |
| 11321 | |
| 11322 | trace_cfg80211_rx_unexpected_4addr_frame(dev, addr); |
| 11323 | |
| 11324 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 11325 | wdev->iftype != NL80211_IFTYPE_P2P_GO && |
| 11326 | wdev->iftype != NL80211_IFTYPE_AP_VLAN)) { |
| 11327 | trace_cfg80211_return_bool(false); |
| 11328 | return false; |
| 11329 | } |
| 11330 | ret = __nl80211_unexpected_frame(dev, |
| 11331 | NL80211_CMD_UNEXPECTED_4ADDR_FRAME, |
| 11332 | addr, gfp); |
| 11333 | trace_cfg80211_return_bool(ret); |
| 11334 | return ret; |
| 11335 | } |
| 11336 | EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame); |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 11337 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 11338 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11339 | struct wireless_dev *wdev, u32 nlportid, |
Johannes Berg | 804483e | 2012-03-05 22:18:41 +0100 | [diff] [blame] | 11340 | int freq, int sig_dbm, |
Vladimir Kondratiev | 19504cf | 2013-08-15 14:51:28 +0300 | [diff] [blame] | 11341 | const u8 *buf, size_t len, u32 flags, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11342 | { |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11343 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11344 | struct sk_buff *msg; |
| 11345 | void *hdr; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11346 | |
| 11347 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 11348 | if (!msg) |
| 11349 | return -ENOMEM; |
| 11350 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 11351 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11352 | if (!hdr) { |
| 11353 | nlmsg_free(msg); |
| 11354 | return -ENOMEM; |
| 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) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11358 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 11359 | netdev->ifindex)) || |
Ilan Peer | a838490 | 2013-05-08 16:35:55 +0300 | [diff] [blame] | 11360 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11361 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
| 11362 | (sig_dbm && |
| 11363 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
Vladimir Kondratiev | 19504cf | 2013-08-15 14:51:28 +0300 | [diff] [blame] | 11364 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
| 11365 | (flags && |
| 11366 | nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11367 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11368 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11369 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11370 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11371 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11372 | |
| 11373 | nla_put_failure: |
| 11374 | genlmsg_cancel(msg, hdr); |
| 11375 | nlmsg_free(msg); |
| 11376 | return -ENOBUFS; |
| 11377 | } |
| 11378 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11379 | void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie, |
| 11380 | const u8 *buf, size_t len, bool ack, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11381 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11382 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11383 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11384 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11385 | struct sk_buff *msg; |
| 11386 | void *hdr; |
| 11387 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11388 | trace_cfg80211_mgmt_tx_status(wdev, cookie, ack); |
| 11389 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11390 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 11391 | if (!msg) |
| 11392 | return; |
| 11393 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 11394 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11395 | if (!hdr) { |
| 11396 | nlmsg_free(msg); |
| 11397 | return; |
| 11398 | } |
| 11399 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11400 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11401 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 11402 | netdev->ifindex)) || |
Ilan Peer | a838490 | 2013-05-08 16:35:55 +0300 | [diff] [blame] | 11403 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11404 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
| 11405 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || |
| 11406 | (ack && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 11407 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11408 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11409 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11410 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11411 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11412 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11413 | return; |
| 11414 | |
| 11415 | nla_put_failure: |
| 11416 | genlmsg_cancel(msg, hdr); |
| 11417 | nlmsg_free(msg); |
| 11418 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11419 | EXPORT_SYMBOL(cfg80211_mgmt_tx_status); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11420 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11421 | void cfg80211_cqm_rssi_notify(struct net_device *dev, |
| 11422 | enum nl80211_cqm_rssi_threshold_event rssi_event, |
| 11423 | gfp_t gfp) |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11424 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11425 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11426 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11427 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11428 | struct sk_buff *msg; |
| 11429 | struct nlattr *pinfoattr; |
| 11430 | void *hdr; |
| 11431 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11432 | trace_cfg80211_cqm_rssi_notify(dev, rssi_event); |
| 11433 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11434 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11435 | if (!msg) |
| 11436 | return; |
| 11437 | |
| 11438 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 11439 | if (!hdr) { |
| 11440 | nlmsg_free(msg); |
| 11441 | return; |
| 11442 | } |
| 11443 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11444 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11445 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11446 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11447 | |
| 11448 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 11449 | if (!pinfoattr) |
| 11450 | goto nla_put_failure; |
| 11451 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11452 | if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, |
| 11453 | rssi_event)) |
| 11454 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11455 | |
| 11456 | nla_nest_end(msg, pinfoattr); |
| 11457 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11458 | genlmsg_end(msg, hdr); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11459 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11460 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11461 | NL80211_MCGRP_MLME, gfp); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11462 | return; |
| 11463 | |
| 11464 | nla_put_failure: |
| 11465 | genlmsg_cancel(msg, hdr); |
| 11466 | nlmsg_free(msg); |
| 11467 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11468 | EXPORT_SYMBOL(cfg80211_cqm_rssi_notify); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11469 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11470 | static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
| 11471 | struct net_device *netdev, const u8 *bssid, |
| 11472 | const u8 *replay_ctr, gfp_t gfp) |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 11473 | { |
| 11474 | struct sk_buff *msg; |
| 11475 | struct nlattr *rekey_attr; |
| 11476 | void *hdr; |
| 11477 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11478 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 11479 | if (!msg) |
| 11480 | return; |
| 11481 | |
| 11482 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); |
| 11483 | if (!hdr) { |
| 11484 | nlmsg_free(msg); |
| 11485 | return; |
| 11486 | } |
| 11487 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11488 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11489 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 11490 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 11491 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 11492 | |
| 11493 | rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); |
| 11494 | if (!rekey_attr) |
| 11495 | goto nla_put_failure; |
| 11496 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11497 | if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
| 11498 | NL80211_REPLAY_CTR_LEN, replay_ctr)) |
| 11499 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 11500 | |
| 11501 | nla_nest_end(msg, rekey_attr); |
| 11502 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11503 | genlmsg_end(msg, hdr); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 11504 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11505 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11506 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 11507 | return; |
| 11508 | |
| 11509 | nla_put_failure: |
| 11510 | genlmsg_cancel(msg, hdr); |
| 11511 | nlmsg_free(msg); |
| 11512 | } |
| 11513 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11514 | void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid, |
| 11515 | const u8 *replay_ctr, gfp_t gfp) |
| 11516 | { |
| 11517 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11518 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11519 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11520 | |
| 11521 | trace_cfg80211_gtk_rekey_notify(dev, bssid); |
| 11522 | nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp); |
| 11523 | } |
| 11524 | EXPORT_SYMBOL(cfg80211_gtk_rekey_notify); |
| 11525 | |
| 11526 | static void |
| 11527 | nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, |
| 11528 | struct net_device *netdev, int index, |
| 11529 | const u8 *bssid, bool preauth, gfp_t gfp) |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 11530 | { |
| 11531 | struct sk_buff *msg; |
| 11532 | struct nlattr *attr; |
| 11533 | void *hdr; |
| 11534 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11535 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 11536 | if (!msg) |
| 11537 | return; |
| 11538 | |
| 11539 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); |
| 11540 | if (!hdr) { |
| 11541 | nlmsg_free(msg); |
| 11542 | return; |
| 11543 | } |
| 11544 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11545 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11546 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 11547 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 11548 | |
| 11549 | attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE); |
| 11550 | if (!attr) |
| 11551 | goto nla_put_failure; |
| 11552 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11553 | if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) || |
| 11554 | nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) || |
| 11555 | (preauth && |
| 11556 | nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH))) |
| 11557 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 11558 | |
| 11559 | nla_nest_end(msg, attr); |
| 11560 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11561 | genlmsg_end(msg, hdr); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 11562 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11563 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11564 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 11565 | return; |
| 11566 | |
| 11567 | nla_put_failure: |
| 11568 | genlmsg_cancel(msg, hdr); |
| 11569 | nlmsg_free(msg); |
| 11570 | } |
| 11571 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11572 | void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index, |
| 11573 | const u8 *bssid, bool preauth, gfp_t gfp) |
| 11574 | { |
| 11575 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11576 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11577 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11578 | |
| 11579 | trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth); |
| 11580 | nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp); |
| 11581 | } |
| 11582 | EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify); |
| 11583 | |
| 11584 | static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev, |
| 11585 | struct net_device *netdev, |
| 11586 | struct cfg80211_chan_def *chandef, |
| 11587 | gfp_t gfp) |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 11588 | { |
| 11589 | struct sk_buff *msg; |
| 11590 | void *hdr; |
| 11591 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11592 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 11593 | if (!msg) |
| 11594 | return; |
| 11595 | |
| 11596 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY); |
| 11597 | if (!hdr) { |
| 11598 | nlmsg_free(msg); |
| 11599 | return; |
| 11600 | } |
| 11601 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 11602 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 11603 | goto nla_put_failure; |
| 11604 | |
| 11605 | if (nl80211_send_chandef(msg, chandef)) |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 11606 | goto nla_put_failure; |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 11607 | |
| 11608 | genlmsg_end(msg, hdr); |
| 11609 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11610 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11611 | NL80211_MCGRP_MLME, gfp); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 11612 | return; |
| 11613 | |
| 11614 | nla_put_failure: |
| 11615 | genlmsg_cancel(msg, hdr); |
| 11616 | nlmsg_free(msg); |
| 11617 | } |
| 11618 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11619 | void cfg80211_ch_switch_notify(struct net_device *dev, |
| 11620 | struct cfg80211_chan_def *chandef) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 11621 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11622 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11623 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11624 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11625 | |
Simon Wunderlich | e487eae | 2013-11-21 18:19:51 +0100 | [diff] [blame] | 11626 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11627 | |
Simon Wunderlich | e487eae | 2013-11-21 18:19:51 +0100 | [diff] [blame] | 11628 | trace_cfg80211_ch_switch_notify(dev, chandef); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11629 | |
| 11630 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 11631 | wdev->iftype != NL80211_IFTYPE_P2P_GO && |
Chun-Yeow Yeoh | b8456a1 | 2013-10-17 15:55:02 -0700 | [diff] [blame] | 11632 | wdev->iftype != NL80211_IFTYPE_ADHOC && |
| 11633 | wdev->iftype != NL80211_IFTYPE_MESH_POINT)) |
Simon Wunderlich | e487eae | 2013-11-21 18:19:51 +0100 | [diff] [blame] | 11634 | return; |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11635 | |
Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 11636 | wdev->chandef = *chandef; |
Janusz Dziedzic | 96f55f1 | 2014-01-24 14:29:21 +0100 | [diff] [blame] | 11637 | wdev->preset_chandef = *chandef; |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11638 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11639 | } |
| 11640 | EXPORT_SYMBOL(cfg80211_ch_switch_notify); |
| 11641 | |
| 11642 | void cfg80211_cqm_txe_notify(struct net_device *dev, |
| 11643 | const u8 *peer, u32 num_packets, |
| 11644 | u32 rate, u32 intvl, gfp_t gfp) |
| 11645 | { |
| 11646 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11647 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11648 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 11649 | struct sk_buff *msg; |
| 11650 | struct nlattr *pinfoattr; |
| 11651 | void *hdr; |
| 11652 | |
| 11653 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 11654 | if (!msg) |
| 11655 | return; |
| 11656 | |
| 11657 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 11658 | if (!hdr) { |
| 11659 | nlmsg_free(msg); |
| 11660 | return; |
| 11661 | } |
| 11662 | |
| 11663 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11664 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 11665 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
| 11666 | goto nla_put_failure; |
| 11667 | |
| 11668 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 11669 | if (!pinfoattr) |
| 11670 | goto nla_put_failure; |
| 11671 | |
| 11672 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets)) |
| 11673 | goto nla_put_failure; |
| 11674 | |
| 11675 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate)) |
| 11676 | goto nla_put_failure; |
| 11677 | |
| 11678 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl)) |
| 11679 | goto nla_put_failure; |
| 11680 | |
| 11681 | nla_nest_end(msg, pinfoattr); |
| 11682 | |
| 11683 | genlmsg_end(msg, hdr); |
| 11684 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11685 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11686 | NL80211_MCGRP_MLME, gfp); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 11687 | return; |
| 11688 | |
| 11689 | nla_put_failure: |
| 11690 | genlmsg_cancel(msg, hdr); |
| 11691 | nlmsg_free(msg); |
| 11692 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11693 | EXPORT_SYMBOL(cfg80211_cqm_txe_notify); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 11694 | |
| 11695 | void |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 11696 | nl80211_radar_notify(struct cfg80211_registered_device *rdev, |
Janusz Dziedzic | d2859df | 2013-11-06 13:55:51 +0100 | [diff] [blame] | 11697 | const struct cfg80211_chan_def *chandef, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 11698 | enum nl80211_radar_event event, |
| 11699 | struct net_device *netdev, gfp_t gfp) |
| 11700 | { |
| 11701 | struct sk_buff *msg; |
| 11702 | void *hdr; |
| 11703 | |
| 11704 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 11705 | if (!msg) |
| 11706 | return; |
| 11707 | |
| 11708 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT); |
| 11709 | if (!hdr) { |
| 11710 | nlmsg_free(msg); |
| 11711 | return; |
| 11712 | } |
| 11713 | |
| 11714 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 11715 | goto nla_put_failure; |
| 11716 | |
| 11717 | /* NOP and radar events don't need a netdev parameter */ |
| 11718 | if (netdev) { |
| 11719 | struct wireless_dev *wdev = netdev->ieee80211_ptr; |
| 11720 | |
| 11721 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 11722 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 11723 | goto nla_put_failure; |
| 11724 | } |
| 11725 | |
| 11726 | if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event)) |
| 11727 | goto nla_put_failure; |
| 11728 | |
| 11729 | if (nl80211_send_chandef(msg, chandef)) |
| 11730 | goto nla_put_failure; |
| 11731 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 11732 | genlmsg_end(msg, hdr); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 11733 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11734 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11735 | NL80211_MCGRP_MLME, gfp); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 11736 | return; |
| 11737 | |
| 11738 | nla_put_failure: |
| 11739 | genlmsg_cancel(msg, hdr); |
| 11740 | nlmsg_free(msg); |
| 11741 | } |
| 11742 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11743 | void cfg80211_cqm_pktloss_notify(struct net_device *dev, |
| 11744 | const u8 *peer, u32 num_packets, gfp_t gfp) |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 11745 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11746 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11747 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11748 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 11749 | struct sk_buff *msg; |
| 11750 | struct nlattr *pinfoattr; |
| 11751 | void *hdr; |
| 11752 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11753 | trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets); |
| 11754 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11755 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 11756 | if (!msg) |
| 11757 | return; |
| 11758 | |
| 11759 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 11760 | if (!hdr) { |
| 11761 | nlmsg_free(msg); |
| 11762 | return; |
| 11763 | } |
| 11764 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11765 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11766 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11767 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
| 11768 | goto nla_put_failure; |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 11769 | |
| 11770 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 11771 | if (!pinfoattr) |
| 11772 | goto nla_put_failure; |
| 11773 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11774 | if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets)) |
| 11775 | goto nla_put_failure; |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 11776 | |
| 11777 | nla_nest_end(msg, pinfoattr); |
| 11778 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11779 | genlmsg_end(msg, hdr); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 11780 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11781 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11782 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 11783 | return; |
| 11784 | |
| 11785 | nla_put_failure: |
| 11786 | genlmsg_cancel(msg, hdr); |
| 11787 | nlmsg_free(msg); |
| 11788 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11789 | EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 11790 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11791 | void cfg80211_probe_status(struct net_device *dev, const u8 *addr, |
| 11792 | u64 cookie, bool acked, gfp_t gfp) |
| 11793 | { |
| 11794 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11795 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11796 | struct sk_buff *msg; |
| 11797 | void *hdr; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11798 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 11799 | trace_cfg80211_probe_status(dev, addr, cookie, acked); |
| 11800 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11801 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 11802 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11803 | if (!msg) |
| 11804 | return; |
| 11805 | |
| 11806 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); |
| 11807 | if (!hdr) { |
| 11808 | nlmsg_free(msg); |
| 11809 | return; |
| 11810 | } |
| 11811 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11812 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11813 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 11814 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 11815 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || |
| 11816 | (acked && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 11817 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11818 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 11819 | genlmsg_end(msg, hdr); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11820 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11821 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11822 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11823 | return; |
| 11824 | |
| 11825 | nla_put_failure: |
| 11826 | genlmsg_cancel(msg, hdr); |
| 11827 | nlmsg_free(msg); |
| 11828 | } |
| 11829 | EXPORT_SYMBOL(cfg80211_probe_status); |
| 11830 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11831 | void cfg80211_report_obss_beacon(struct wiphy *wiphy, |
| 11832 | const u8 *frame, size_t len, |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11833 | int freq, int sig_dbm) |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11834 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11835 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11836 | struct sk_buff *msg; |
| 11837 | void *hdr; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11838 | struct cfg80211_beacon_registration *reg; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11839 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 11840 | trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm); |
| 11841 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11842 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 11843 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 11844 | msg = nlmsg_new(len + 100, GFP_ATOMIC); |
| 11845 | if (!msg) { |
| 11846 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 11847 | return; |
| 11848 | } |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11849 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11850 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
| 11851 | if (!hdr) |
| 11852 | goto nla_put_failure; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11853 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11854 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11855 | (freq && |
| 11856 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || |
| 11857 | (sig_dbm && |
| 11858 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
| 11859 | nla_put(msg, NL80211_ATTR_FRAME, len, frame)) |
| 11860 | goto nla_put_failure; |
| 11861 | |
| 11862 | genlmsg_end(msg, hdr); |
| 11863 | |
| 11864 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11865 | } |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11866 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11867 | return; |
| 11868 | |
| 11869 | nla_put_failure: |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11870 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 11871 | if (hdr) |
| 11872 | genlmsg_cancel(msg, hdr); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11873 | nlmsg_free(msg); |
| 11874 | } |
| 11875 | EXPORT_SYMBOL(cfg80211_report_obss_beacon); |
| 11876 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 11877 | #ifdef CONFIG_PM |
| 11878 | void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev, |
| 11879 | struct cfg80211_wowlan_wakeup *wakeup, |
| 11880 | gfp_t gfp) |
| 11881 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11882 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 11883 | struct sk_buff *msg; |
| 11884 | void *hdr; |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 11885 | int size = 200; |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 11886 | |
| 11887 | trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup); |
| 11888 | |
| 11889 | if (wakeup) |
| 11890 | size += wakeup->packet_present_len; |
| 11891 | |
| 11892 | msg = nlmsg_new(size, gfp); |
| 11893 | if (!msg) |
| 11894 | return; |
| 11895 | |
| 11896 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN); |
| 11897 | if (!hdr) |
| 11898 | goto free_msg; |
| 11899 | |
| 11900 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11901 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 11902 | goto free_msg; |
| 11903 | |
| 11904 | if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 11905 | wdev->netdev->ifindex)) |
| 11906 | goto free_msg; |
| 11907 | |
| 11908 | if (wakeup) { |
| 11909 | struct nlattr *reasons; |
| 11910 | |
| 11911 | reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
Johannes Berg | 7fa322c | 2013-10-25 11:16:58 +0200 | [diff] [blame] | 11912 | if (!reasons) |
| 11913 | goto free_msg; |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 11914 | |
| 11915 | if (wakeup->disconnect && |
| 11916 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) |
| 11917 | goto free_msg; |
| 11918 | if (wakeup->magic_pkt && |
| 11919 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) |
| 11920 | goto free_msg; |
| 11921 | if (wakeup->gtk_rekey_failure && |
| 11922 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) |
| 11923 | goto free_msg; |
| 11924 | if (wakeup->eap_identity_req && |
| 11925 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) |
| 11926 | goto free_msg; |
| 11927 | if (wakeup->four_way_handshake && |
| 11928 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) |
| 11929 | goto free_msg; |
| 11930 | if (wakeup->rfkill_release && |
| 11931 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)) |
| 11932 | goto free_msg; |
| 11933 | |
| 11934 | if (wakeup->pattern_idx >= 0 && |
| 11935 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 11936 | wakeup->pattern_idx)) |
| 11937 | goto free_msg; |
| 11938 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 11939 | if (wakeup->tcp_match && |
| 11940 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH)) |
| 11941 | goto free_msg; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11942 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 11943 | if (wakeup->tcp_connlost && |
| 11944 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST)) |
| 11945 | goto free_msg; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11946 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 11947 | if (wakeup->tcp_nomoretokens && |
| 11948 | nla_put_flag(msg, |
| 11949 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS)) |
| 11950 | goto free_msg; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11951 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 11952 | if (wakeup->packet) { |
| 11953 | u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211; |
| 11954 | u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN; |
| 11955 | |
| 11956 | if (!wakeup->packet_80211) { |
| 11957 | pkt_attr = |
| 11958 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023; |
| 11959 | len_attr = |
| 11960 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN; |
| 11961 | } |
| 11962 | |
| 11963 | if (wakeup->packet_len && |
| 11964 | nla_put_u32(msg, len_attr, wakeup->packet_len)) |
| 11965 | goto free_msg; |
| 11966 | |
| 11967 | if (nla_put(msg, pkt_attr, wakeup->packet_present_len, |
| 11968 | wakeup->packet)) |
| 11969 | goto free_msg; |
| 11970 | } |
| 11971 | |
| 11972 | nla_nest_end(msg, reasons); |
| 11973 | } |
| 11974 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 11975 | genlmsg_end(msg, hdr); |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 11976 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11977 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11978 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 11979 | return; |
| 11980 | |
| 11981 | free_msg: |
| 11982 | nlmsg_free(msg); |
| 11983 | } |
| 11984 | EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup); |
| 11985 | #endif |
| 11986 | |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 11987 | void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer, |
| 11988 | enum nl80211_tdls_operation oper, |
| 11989 | u16 reason_code, gfp_t gfp) |
| 11990 | { |
| 11991 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11992 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 11993 | struct sk_buff *msg; |
| 11994 | void *hdr; |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 11995 | |
| 11996 | trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper, |
| 11997 | reason_code); |
| 11998 | |
| 11999 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 12000 | if (!msg) |
| 12001 | return; |
| 12002 | |
| 12003 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER); |
| 12004 | if (!hdr) { |
| 12005 | nlmsg_free(msg); |
| 12006 | return; |
| 12007 | } |
| 12008 | |
| 12009 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 12010 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 12011 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) || |
| 12012 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) || |
| 12013 | (reason_code > 0 && |
| 12014 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) |
| 12015 | goto nla_put_failure; |
| 12016 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 12017 | genlmsg_end(msg, hdr); |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 12018 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12019 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12020 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 12021 | return; |
| 12022 | |
| 12023 | nla_put_failure: |
| 12024 | genlmsg_cancel(msg, hdr); |
| 12025 | nlmsg_free(msg); |
| 12026 | } |
| 12027 | EXPORT_SYMBOL(cfg80211_tdls_oper_request); |
| 12028 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12029 | static int nl80211_netlink_notify(struct notifier_block * nb, |
| 12030 | unsigned long state, |
| 12031 | void *_notify) |
| 12032 | { |
| 12033 | struct netlink_notify *notify = _notify; |
| 12034 | struct cfg80211_registered_device *rdev; |
| 12035 | struct wireless_dev *wdev; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 12036 | struct cfg80211_beacon_registration *reg, *tmp; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12037 | |
| 12038 | if (state != NETLINK_URELEASE) |
| 12039 | return NOTIFY_DONE; |
| 12040 | |
| 12041 | rcu_read_lock(); |
| 12042 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 12043 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 12044 | bool schedule_destroy_work = false; |
| 12045 | |
| 12046 | list_for_each_entry_rcu(wdev, &rdev->wdev_list, list) { |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 12047 | cfg80211_mlme_unregister_socket(wdev, notify->portid); |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 12048 | |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 12049 | if (wdev->owner_nlportid == notify->portid) |
| 12050 | schedule_destroy_work = true; |
| 12051 | } |
| 12052 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 12053 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 12054 | list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations, |
| 12055 | list) { |
| 12056 | if (reg->nlportid == notify->portid) { |
| 12057 | list_del(®->list); |
| 12058 | kfree(reg); |
| 12059 | break; |
| 12060 | } |
| 12061 | } |
| 12062 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 12063 | |
| 12064 | if (schedule_destroy_work) { |
| 12065 | struct cfg80211_iface_destroy *destroy; |
| 12066 | |
| 12067 | destroy = kzalloc(sizeof(*destroy), GFP_ATOMIC); |
| 12068 | if (destroy) { |
| 12069 | destroy->nlportid = notify->portid; |
| 12070 | spin_lock(&rdev->destroy_list_lock); |
| 12071 | list_add(&destroy->list, &rdev->destroy_list); |
| 12072 | spin_unlock(&rdev->destroy_list_lock); |
| 12073 | schedule_work(&rdev->destroy_work); |
| 12074 | } |
| 12075 | } |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 12076 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12077 | |
| 12078 | rcu_read_unlock(); |
| 12079 | |
Zhao, Gang | 6784c7d | 2014-04-21 12:53:04 +0800 | [diff] [blame] | 12080 | return NOTIFY_OK; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12081 | } |
| 12082 | |
| 12083 | static struct notifier_block nl80211_netlink_notifier = { |
| 12084 | .notifier_call = nl80211_netlink_notify, |
| 12085 | }; |
| 12086 | |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 12087 | void cfg80211_ft_event(struct net_device *netdev, |
| 12088 | struct cfg80211_ft_event_params *ft_event) |
| 12089 | { |
| 12090 | struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12091 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 12092 | struct sk_buff *msg; |
| 12093 | void *hdr; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 12094 | |
| 12095 | trace_cfg80211_ft_event(wiphy, netdev, ft_event); |
| 12096 | |
| 12097 | if (!ft_event->target_ap) |
| 12098 | return; |
| 12099 | |
| 12100 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 12101 | if (!msg) |
| 12102 | return; |
| 12103 | |
| 12104 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT); |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 12105 | if (!hdr) |
| 12106 | goto out; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 12107 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 12108 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 12109 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 12110 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap)) |
| 12111 | goto out; |
| 12112 | |
| 12113 | if (ft_event->ies && |
| 12114 | nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies)) |
| 12115 | goto out; |
| 12116 | if (ft_event->ric_ies && |
| 12117 | nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len, |
| 12118 | ft_event->ric_ies)) |
| 12119 | goto out; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 12120 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 12121 | genlmsg_end(msg, hdr); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 12122 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12123 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12124 | NL80211_MCGRP_MLME, GFP_KERNEL); |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 12125 | return; |
| 12126 | out: |
| 12127 | nlmsg_free(msg); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 12128 | } |
| 12129 | EXPORT_SYMBOL(cfg80211_ft_event); |
| 12130 | |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 12131 | void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp) |
| 12132 | { |
| 12133 | struct cfg80211_registered_device *rdev; |
| 12134 | struct sk_buff *msg; |
| 12135 | void *hdr; |
| 12136 | u32 nlportid; |
| 12137 | |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12138 | rdev = wiphy_to_rdev(wdev->wiphy); |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 12139 | if (!rdev->crit_proto_nlportid) |
| 12140 | return; |
| 12141 | |
| 12142 | nlportid = rdev->crit_proto_nlportid; |
| 12143 | rdev->crit_proto_nlportid = 0; |
| 12144 | |
| 12145 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 12146 | if (!msg) |
| 12147 | return; |
| 12148 | |
| 12149 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP); |
| 12150 | if (!hdr) |
| 12151 | goto nla_put_failure; |
| 12152 | |
| 12153 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 12154 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 12155 | goto nla_put_failure; |
| 12156 | |
| 12157 | genlmsg_end(msg, hdr); |
| 12158 | |
| 12159 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
| 12160 | return; |
| 12161 | |
| 12162 | nla_put_failure: |
| 12163 | if (hdr) |
| 12164 | genlmsg_cancel(msg, hdr); |
| 12165 | nlmsg_free(msg); |
| 12166 | |
| 12167 | } |
| 12168 | EXPORT_SYMBOL(cfg80211_crit_proto_stopped); |
| 12169 | |
Johannes Berg | 348baf0 | 2014-01-24 14:06:29 +0100 | [diff] [blame] | 12170 | void nl80211_send_ap_stopped(struct wireless_dev *wdev) |
| 12171 | { |
| 12172 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12173 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 348baf0 | 2014-01-24 14:06:29 +0100 | [diff] [blame] | 12174 | struct sk_buff *msg; |
| 12175 | void *hdr; |
| 12176 | |
| 12177 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 12178 | if (!msg) |
| 12179 | return; |
| 12180 | |
| 12181 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP); |
| 12182 | if (!hdr) |
| 12183 | goto out; |
| 12184 | |
| 12185 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 12186 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) || |
| 12187 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 12188 | goto out; |
| 12189 | |
| 12190 | genlmsg_end(msg, hdr); |
| 12191 | |
| 12192 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0, |
| 12193 | NL80211_MCGRP_MLME, GFP_KERNEL); |
| 12194 | return; |
| 12195 | out: |
| 12196 | nlmsg_free(msg); |
| 12197 | } |
| 12198 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 12199 | /* initialisation/exit functions */ |
| 12200 | |
| 12201 | int nl80211_init(void) |
| 12202 | { |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 12203 | int err; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 12204 | |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12205 | err = genl_register_family_with_ops_groups(&nl80211_fam, nl80211_ops, |
| 12206 | nl80211_mcgrps); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 12207 | if (err) |
| 12208 | return err; |
| 12209 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12210 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
| 12211 | if (err) |
| 12212 | goto err_out; |
| 12213 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 12214 | return 0; |
| 12215 | err_out: |
| 12216 | genl_unregister_family(&nl80211_fam); |
| 12217 | return err; |
| 12218 | } |
| 12219 | |
| 12220 | void nl80211_exit(void) |
| 12221 | { |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12222 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 12223 | genl_unregister_family(&nl80211_fam); |
| 12224 | } |