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 | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <linux/if.h> |
| 8 | #include <linux/module.h> |
| 9 | #include <linux/err.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 10 | #include <linux/slab.h> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11 | #include <linux/list.h> |
| 12 | #include <linux/if_ether.h> |
| 13 | #include <linux/ieee80211.h> |
| 14 | #include <linux/nl80211.h> |
| 15 | #include <linux/rtnetlink.h> |
| 16 | #include <linux/netlink.h> |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 17 | #include <linux/etherdevice.h> |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 18 | #include <net/net_namespace.h> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 19 | #include <net/genetlink.h> |
| 20 | #include <net/cfg80211.h> |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 21 | #include <net/sock.h> |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 22 | #include <net/inet_connection_sock.h> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 23 | #include "core.h" |
| 24 | #include "nl80211.h" |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 25 | #include "reg.h" |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 26 | #include "rdev-ops.h" |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 27 | |
Jouni Malinen | 5fb628e | 2011-08-10 23:54:35 +0300 | [diff] [blame] | 28 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 29 | struct genl_info *info, |
| 30 | struct cfg80211_crypto_settings *settings, |
| 31 | int cipher_limit); |
| 32 | |
Johannes Berg | f84f771 | 2013-11-14 17:14:45 +0100 | [diff] [blame] | 33 | 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] | 34 | struct genl_info *info); |
Johannes Berg | f84f771 | 2013-11-14 17:14:45 +0100 | [diff] [blame] | 35 | 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] | 36 | struct genl_info *info); |
| 37 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 38 | /* the netlink family */ |
| 39 | static struct genl_family nl80211_fam = { |
Marcel Holtmann | fb4e156 | 2013-04-28 16:22:06 -0700 | [diff] [blame] | 40 | .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */ |
| 41 | .name = NL80211_GENL_NAME, /* have users key off the name instead */ |
| 42 | .hdrsize = 0, /* no private header */ |
| 43 | .version = 1, /* no particular meaning now */ |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 44 | .maxattr = NL80211_ATTR_MAX, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 45 | .netnsok = true, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 46 | .pre_doit = nl80211_pre_doit, |
| 47 | .post_doit = nl80211_post_doit, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 48 | }; |
| 49 | |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 50 | /* multicast groups */ |
| 51 | enum nl80211_multicast_groups { |
| 52 | NL80211_MCGRP_CONFIG, |
| 53 | NL80211_MCGRP_SCAN, |
| 54 | NL80211_MCGRP_REGULATORY, |
| 55 | NL80211_MCGRP_MLME, |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 56 | NL80211_MCGRP_VENDOR, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 57 | NL80211_MCGRP_TESTMODE /* keep last - ifdef! */ |
| 58 | }; |
| 59 | |
| 60 | static const struct genl_multicast_group nl80211_mcgrps[] = { |
| 61 | [NL80211_MCGRP_CONFIG] = { .name = "config", }, |
| 62 | [NL80211_MCGRP_SCAN] = { .name = "scan", }, |
| 63 | [NL80211_MCGRP_REGULATORY] = { .name = "regulatory", }, |
| 64 | [NL80211_MCGRP_MLME] = { .name = "mlme", }, |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 65 | [NL80211_MCGRP_VENDOR] = { .name = "vendor", }, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 66 | #ifdef CONFIG_NL80211_TESTMODE |
| 67 | [NL80211_MCGRP_TESTMODE] = { .name = "testmode", } |
| 68 | #endif |
| 69 | }; |
| 70 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 71 | /* returns ERR_PTR values */ |
| 72 | static struct wireless_dev * |
| 73 | __cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 74 | { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 75 | struct cfg80211_registered_device *rdev; |
| 76 | struct wireless_dev *result = NULL; |
| 77 | bool have_ifidx = attrs[NL80211_ATTR_IFINDEX]; |
| 78 | bool have_wdev_id = attrs[NL80211_ATTR_WDEV]; |
| 79 | u64 wdev_id; |
| 80 | int wiphy_idx = -1; |
| 81 | int ifidx = -1; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 82 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 83 | ASSERT_RTNL(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 84 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 85 | if (!have_ifidx && !have_wdev_id) |
| 86 | return ERR_PTR(-EINVAL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 87 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 88 | if (have_ifidx) |
| 89 | ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); |
| 90 | if (have_wdev_id) { |
| 91 | wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); |
| 92 | wiphy_idx = wdev_id >> 32; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 93 | } |
| 94 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 95 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 96 | struct wireless_dev *wdev; |
| 97 | |
| 98 | if (wiphy_net(&rdev->wiphy) != netns) |
| 99 | continue; |
| 100 | |
| 101 | if (have_wdev_id && rdev->wiphy_idx != wiphy_idx) |
| 102 | continue; |
| 103 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 104 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
| 105 | if (have_ifidx && wdev->netdev && |
| 106 | wdev->netdev->ifindex == ifidx) { |
| 107 | result = wdev; |
| 108 | break; |
| 109 | } |
| 110 | if (have_wdev_id && wdev->identifier == (u32)wdev_id) { |
| 111 | result = wdev; |
| 112 | break; |
| 113 | } |
| 114 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 115 | |
| 116 | if (result) |
| 117 | break; |
| 118 | } |
| 119 | |
| 120 | if (result) |
| 121 | return result; |
| 122 | return ERR_PTR(-ENODEV); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 123 | } |
| 124 | |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 125 | static struct cfg80211_registered_device * |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 126 | __cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs) |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 127 | { |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 128 | struct cfg80211_registered_device *rdev = NULL, *tmp; |
| 129 | struct net_device *netdev; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 130 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 131 | ASSERT_RTNL(); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 132 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 133 | if (!attrs[NL80211_ATTR_WIPHY] && |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 134 | !attrs[NL80211_ATTR_IFINDEX] && |
| 135 | !attrs[NL80211_ATTR_WDEV]) |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 136 | return ERR_PTR(-EINVAL); |
| 137 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 138 | if (attrs[NL80211_ATTR_WIPHY]) |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 139 | rdev = cfg80211_rdev_by_wiphy_idx( |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 140 | nla_get_u32(attrs[NL80211_ATTR_WIPHY])); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 141 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 142 | if (attrs[NL80211_ATTR_WDEV]) { |
| 143 | u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); |
| 144 | struct wireless_dev *wdev; |
| 145 | bool found = false; |
| 146 | |
| 147 | tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32); |
| 148 | if (tmp) { |
| 149 | /* make sure wdev exists */ |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 150 | list_for_each_entry(wdev, &tmp->wdev_list, list) { |
| 151 | if (wdev->identifier != (u32)wdev_id) |
| 152 | continue; |
| 153 | found = true; |
| 154 | break; |
| 155 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 156 | |
| 157 | if (!found) |
| 158 | tmp = NULL; |
| 159 | |
| 160 | if (rdev && tmp != rdev) |
| 161 | return ERR_PTR(-EINVAL); |
| 162 | rdev = tmp; |
| 163 | } |
| 164 | } |
| 165 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 166 | if (attrs[NL80211_ATTR_IFINDEX]) { |
| 167 | int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 168 | netdev = __dev_get_by_index(netns, ifindex); |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 169 | if (netdev) { |
| 170 | if (netdev->ieee80211_ptr) |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 171 | tmp = wiphy_to_rdev( |
| 172 | netdev->ieee80211_ptr->wiphy); |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 173 | else |
| 174 | tmp = NULL; |
| 175 | |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 176 | /* not wireless device -- return error */ |
| 177 | if (!tmp) |
| 178 | return ERR_PTR(-EINVAL); |
| 179 | |
| 180 | /* mismatch -- return error */ |
| 181 | if (rdev && tmp != rdev) |
| 182 | return ERR_PTR(-EINVAL); |
| 183 | |
| 184 | rdev = tmp; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 185 | } |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 186 | } |
| 187 | |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 188 | if (!rdev) |
| 189 | return ERR_PTR(-ENODEV); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 190 | |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 191 | if (netns != wiphy_net(&rdev->wiphy)) |
| 192 | return ERR_PTR(-ENODEV); |
| 193 | |
| 194 | return rdev; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | /* |
| 198 | * This function returns a pointer to the driver |
| 199 | * that the genl_info item that is passed refers to. |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 200 | * |
| 201 | * The result of this can be a PTR_ERR and hence must |
| 202 | * be checked with IS_ERR() for errors. |
| 203 | */ |
| 204 | static struct cfg80211_registered_device * |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 205 | cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info) |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 206 | { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 207 | return __cfg80211_rdev_from_attrs(netns, info->attrs); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 208 | } |
| 209 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 210 | /* policy for the attributes */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 211 | static const struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] = { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 212 | [NL80211_ATTR_WIPHY] = { .type = NLA_U32 }, |
| 213 | [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING, |
David S. Miller | 079e24e | 2009-05-26 21:15:00 -0700 | [diff] [blame] | 214 | .len = 20-1 }, |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 215 | [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED }, |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 216 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 217 | [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 }, |
Sujith | 094d05d | 2008-12-12 11:57:43 +0530 | [diff] [blame] | 218 | [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 219 | [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 }, |
| 220 | [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 }, |
| 221 | [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 }, |
| 222 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 223 | [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 }, |
| 224 | [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 }, |
| 225 | [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 }, |
| 226 | [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 }, |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 227 | [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 228 | |
| 229 | [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 }, |
| 230 | [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 }, |
| 231 | [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 232 | |
Eliad Peller | e007b85 | 2011-11-24 18:13:56 +0200 | [diff] [blame] | 233 | [NL80211_ATTR_MAC] = { .len = ETH_ALEN }, |
| 234 | [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 235 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 236 | [NL80211_ATTR_KEY] = { .type = NLA_NESTED, }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 237 | [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY, |
| 238 | .len = WLAN_MAX_KEY_LEN }, |
| 239 | [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 }, |
| 240 | [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 }, |
| 241 | [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG }, |
Jouni Malinen | 8196226 | 2011-11-02 23:36:31 +0200 | [diff] [blame] | 242 | [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 243 | [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 244 | |
| 245 | [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 }, |
| 246 | [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 }, |
| 247 | [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY, |
| 248 | .len = IEEE80211_MAX_DATA_LEN }, |
| 249 | [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY, |
| 250 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 251 | [NL80211_ATTR_STA_AID] = { .type = NLA_U16 }, |
| 252 | [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED }, |
| 253 | [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 }, |
| 254 | [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY, |
| 255 | .len = NL80211_MAX_SUPP_RATES }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 256 | [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 257 | [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 }, |
Johannes Berg | 0a9542e | 2008-10-15 11:54:04 +0200 | [diff] [blame] | 258 | [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 259 | [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 260 | .len = IEEE80211_MAX_MESH_ID_LEN }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 261 | [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 262 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 263 | [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 }, |
| 264 | [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED }, |
| 265 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 266 | [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 }, |
| 267 | [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 }, |
| 268 | [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 }, |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 269 | [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY, |
| 270 | .len = NL80211_MAX_SUPP_RATES }, |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 271 | [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 }, |
Jouni Malinen | 36aedc90 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 272 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 273 | [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 274 | [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 275 | |
Johannes Berg | 6c73941 | 2011-11-03 09:27:01 +0100 | [diff] [blame] | 276 | [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 277 | |
| 278 | [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 }, |
| 279 | [NL80211_ATTR_IE] = { .type = NLA_BINARY, |
| 280 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 281 | [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED }, |
| 282 | [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 283 | |
| 284 | [NL80211_ATTR_SSID] = { .type = NLA_BINARY, |
| 285 | .len = IEEE80211_MAX_SSID_LEN }, |
| 286 | [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 }, |
| 287 | [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 288 | [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG }, |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 289 | [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG }, |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 290 | [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 }, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 291 | [NL80211_ATTR_STA_FLAGS2] = { |
| 292 | .len = sizeof(struct nl80211_sta_flag_update), |
| 293 | }, |
Jouni Malinen | 3f77316c | 2009-05-11 21:57:57 +0300 | [diff] [blame] | 294 | [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG }, |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 295 | [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 }, |
| 296 | [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG }, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 297 | [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG }, |
| 298 | [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 }, |
| 299 | [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 300 | [NL80211_ATTR_PID] = { .type = NLA_U32 }, |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 301 | [NL80211_ATTR_4ADDR] = { .type = NLA_U8 }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 302 | [NL80211_ATTR_PMKID] = { .type = NLA_BINARY, |
| 303 | .len = WLAN_PMKID_LEN }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 304 | [NL80211_ATTR_DURATION] = { .type = NLA_U32 }, |
| 305 | [NL80211_ATTR_COOKIE] = { .type = NLA_U64 }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 306 | [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 307 | [NL80211_ATTR_FRAME] = { .type = NLA_BINARY, |
| 308 | .len = IEEE80211_MAX_DATA_LEN }, |
| 309 | [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 310 | [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 311 | [NL80211_ATTR_CQM] = { .type = NLA_NESTED, }, |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 312 | [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG }, |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 313 | [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 }, |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 314 | [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 }, |
| 315 | [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 }, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 316 | [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 }, |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 317 | [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 }, |
| 318 | [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 }, |
Felix Fietkau | 885a46d | 2010-11-11 15:07:22 +0100 | [diff] [blame] | 319 | [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 }, |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 320 | [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 321 | [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 322 | [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED }, |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 323 | [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 }, |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 324 | [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 }, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 325 | [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED }, |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 326 | [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED }, |
Jouni Malinen | 32e9de8 | 2011-08-10 23:53:31 +0300 | [diff] [blame] | 327 | [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 }, |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 328 | [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY, |
| 329 | .len = IEEE80211_MAX_DATA_LEN }, |
| 330 | [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY, |
| 331 | .len = IEEE80211_MAX_DATA_LEN }, |
Vivek Natarajan | f4b34b5 | 2011-08-29 14:23:03 +0530 | [diff] [blame] | 332 | [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG }, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 333 | [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED }, |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 334 | [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 335 | [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 }, |
| 336 | [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 }, |
| 337 | [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 }, |
| 338 | [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG }, |
| 339 | [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG }, |
Arik Nemtsov | 31fa97c | 2014-06-11 17:18:21 +0300 | [diff] [blame] | 340 | [NL80211_ATTR_TDLS_INITIATOR] = { .type = NLA_FLAG }, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 341 | [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG }, |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 342 | [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY, |
| 343 | .len = IEEE80211_MAX_DATA_LEN }, |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 344 | [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 }, |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 345 | [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG }, |
| 346 | [NL80211_ATTR_HT_CAPABILITY_MASK] = { |
| 347 | .len = NL80211_HT_CAPABILITY_LEN |
| 348 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 349 | [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 }, |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 350 | [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 }, |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 351 | [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 }, |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 352 | [NL80211_ATTR_WDEV] = { .type = NLA_U64 }, |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 353 | [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 }, |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 354 | [NL80211_ATTR_SAE_DATA] = { .type = NLA_BINARY, }, |
Mahesh Palivela | f461be3e | 2012-10-11 08:04:52 +0000 | [diff] [blame] | 355 | [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN }, |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 356 | [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 }, |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 357 | [NL80211_ATTR_P2P_CTWINDOW] = { .type = NLA_U8 }, |
| 358 | [NL80211_ATTR_P2P_OPPPS] = { .type = NLA_U8 }, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 359 | [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 }, |
| 360 | [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED }, |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 361 | [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 }, |
| 362 | [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, }, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 363 | [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, }, |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 364 | [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG }, |
| 365 | [NL80211_ATTR_VHT_CAPABILITY_MASK] = { |
| 366 | .len = NL80211_VHT_CAPABILITY_LEN, |
| 367 | }, |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 368 | [NL80211_ATTR_MDID] = { .type = NLA_U16 }, |
| 369 | [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY, |
| 370 | .len = IEEE80211_MAX_DATA_LEN }, |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 371 | [NL80211_ATTR_PEER_AID] = { .type = NLA_U16 }, |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 372 | [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 }, |
| 373 | [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG }, |
| 374 | [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED }, |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 375 | [NL80211_ATTR_CSA_C_OFF_BEACON] = { .type = NLA_BINARY }, |
| 376 | [NL80211_ATTR_CSA_C_OFF_PRESP] = { .type = NLA_BINARY }, |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 377 | [NL80211_ATTR_STA_SUPPORTED_CHANNELS] = { .type = NLA_BINARY }, |
| 378 | [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES] = { .type = NLA_BINARY }, |
Simon Wunderlich | 5336fa8 | 2013-10-07 18:41:05 +0200 | [diff] [blame] | 379 | [NL80211_ATTR_HANDLE_DFS] = { .type = NLA_FLAG }, |
Marek Kwaczynski | 60f4a7b | 2013-12-03 10:04:59 +0100 | [diff] [blame] | 380 | [NL80211_ATTR_OPMODE_NOTIF] = { .type = NLA_U8 }, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 381 | [NL80211_ATTR_VENDOR_ID] = { .type = NLA_U32 }, |
| 382 | [NL80211_ATTR_VENDOR_SUBCMD] = { .type = NLA_U32 }, |
| 383 | [NL80211_ATTR_VENDOR_DATA] = { .type = NLA_BINARY }, |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 384 | [NL80211_ATTR_QOS_MAP] = { .type = NLA_BINARY, |
| 385 | .len = IEEE80211_QOS_MAP_LEN_MAX }, |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 386 | [NL80211_ATTR_MAC_HINT] = { .len = ETH_ALEN }, |
| 387 | [NL80211_ATTR_WIPHY_FREQ_HINT] = { .type = NLA_U32 }, |
Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 388 | [NL80211_ATTR_TDLS_PEER_CAPABILITY] = { .type = NLA_U32 }, |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 389 | [NL80211_ATTR_IFACE_SOCKET_OWNER] = { .type = NLA_FLAG }, |
Andrei Otcheretianski | 34d22ce | 2014-05-09 14:11:44 +0300 | [diff] [blame] | 390 | [NL80211_ATTR_CSA_C_OFFSETS_TX] = { .type = NLA_BINARY }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 391 | }; |
| 392 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 393 | /* policy for the key attributes */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 394 | static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 395 | [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 396 | [NL80211_KEY_IDX] = { .type = NLA_U8 }, |
| 397 | [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, |
Jouni Malinen | 8196226 | 2011-11-02 23:36:31 +0200 | [diff] [blame] | 398 | [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 399 | [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, |
| 400 | [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 401 | [NL80211_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 402 | [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
| 403 | }; |
| 404 | |
| 405 | /* policy for the key default flags */ |
| 406 | static const struct nla_policy |
| 407 | nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = { |
| 408 | [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG }, |
| 409 | [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 410 | }; |
| 411 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 412 | /* policy for WoWLAN attributes */ |
| 413 | static const struct nla_policy |
| 414 | nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = { |
| 415 | [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG }, |
| 416 | [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG }, |
| 417 | [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG }, |
| 418 | [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED }, |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 419 | [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG }, |
| 420 | [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG }, |
| 421 | [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG }, |
| 422 | [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG }, |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 423 | [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED }, |
| 424 | }; |
| 425 | |
| 426 | static const struct nla_policy |
| 427 | nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = { |
| 428 | [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 }, |
| 429 | [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 }, |
| 430 | [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN }, |
| 431 | [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 }, |
| 432 | [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 }, |
| 433 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 }, |
| 434 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = { |
| 435 | .len = sizeof(struct nl80211_wowlan_tcp_data_seq) |
| 436 | }, |
| 437 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = { |
| 438 | .len = sizeof(struct nl80211_wowlan_tcp_data_token) |
| 439 | }, |
| 440 | [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 }, |
| 441 | [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 }, |
| 442 | [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 443 | }; |
| 444 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 445 | /* policy for coalesce rule attributes */ |
| 446 | static const struct nla_policy |
| 447 | nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = { |
| 448 | [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 }, |
| 449 | [NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 }, |
| 450 | [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED }, |
| 451 | }; |
| 452 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 453 | /* policy for GTK rekey offload attributes */ |
| 454 | static const struct nla_policy |
| 455 | nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = { |
| 456 | [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN }, |
| 457 | [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN }, |
| 458 | [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN }, |
| 459 | }; |
| 460 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 461 | static const struct nla_policy |
| 462 | nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = { |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 463 | [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 464 | .len = IEEE80211_MAX_SSID_LEN }, |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 465 | [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 }, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 466 | }; |
| 467 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 468 | static int nl80211_prepare_wdev_dump(struct sk_buff *skb, |
| 469 | struct netlink_callback *cb, |
| 470 | struct cfg80211_registered_device **rdev, |
| 471 | struct wireless_dev **wdev) |
Holger Schurig | a043897 | 2009-11-11 11:30:02 +0100 | [diff] [blame] | 472 | { |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 473 | int err; |
| 474 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 475 | rtnl_lock(); |
| 476 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 477 | if (!cb->args[0]) { |
| 478 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 479 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 480 | nl80211_policy); |
| 481 | if (err) |
| 482 | goto out_unlock; |
| 483 | |
| 484 | *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk), |
| 485 | nl80211_fam.attrbuf); |
| 486 | if (IS_ERR(*wdev)) { |
| 487 | err = PTR_ERR(*wdev); |
| 488 | goto out_unlock; |
| 489 | } |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 490 | *rdev = wiphy_to_rdev((*wdev)->wiphy); |
Johannes Berg | c319d50 | 2013-07-30 22:34:28 +0200 | [diff] [blame] | 491 | /* 0 is the first index - add 1 to parse only once */ |
| 492 | cb->args[0] = (*rdev)->wiphy_idx + 1; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 493 | cb->args[1] = (*wdev)->identifier; |
| 494 | } else { |
Johannes Berg | c319d50 | 2013-07-30 22:34:28 +0200 | [diff] [blame] | 495 | /* subtract the 1 again here */ |
| 496 | struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1); |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 497 | struct wireless_dev *tmp; |
| 498 | |
| 499 | if (!wiphy) { |
| 500 | err = -ENODEV; |
| 501 | goto out_unlock; |
| 502 | } |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 503 | *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 504 | *wdev = NULL; |
| 505 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 506 | list_for_each_entry(tmp, &(*rdev)->wdev_list, list) { |
| 507 | if (tmp->identifier == cb->args[1]) { |
| 508 | *wdev = tmp; |
| 509 | break; |
| 510 | } |
| 511 | } |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 512 | |
| 513 | if (!*wdev) { |
| 514 | err = -ENODEV; |
| 515 | goto out_unlock; |
| 516 | } |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 517 | } |
| 518 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 519 | return 0; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 520 | out_unlock: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 521 | rtnl_unlock(); |
| 522 | return err; |
| 523 | } |
| 524 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 525 | static void nl80211_finish_wdev_dump(struct cfg80211_registered_device *rdev) |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 526 | { |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 527 | rtnl_unlock(); |
| 528 | } |
| 529 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 530 | /* IE validation */ |
| 531 | static bool is_valid_ie_attr(const struct nlattr *attr) |
| 532 | { |
| 533 | const u8 *pos; |
| 534 | int len; |
| 535 | |
| 536 | if (!attr) |
| 537 | return true; |
| 538 | |
| 539 | pos = nla_data(attr); |
| 540 | len = nla_len(attr); |
| 541 | |
| 542 | while (len) { |
| 543 | u8 elemlen; |
| 544 | |
| 545 | if (len < 2) |
| 546 | return false; |
| 547 | len -= 2; |
| 548 | |
| 549 | elemlen = pos[1]; |
| 550 | if (elemlen > len) |
| 551 | return false; |
| 552 | |
| 553 | len -= elemlen; |
| 554 | pos += 2 + elemlen; |
| 555 | } |
| 556 | |
| 557 | return true; |
| 558 | } |
| 559 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 560 | /* message building helper */ |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 561 | 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] | 562 | int flags, u8 cmd) |
| 563 | { |
| 564 | /* since there is no private header just add the generic one */ |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 565 | return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 566 | } |
| 567 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 568 | static int nl80211_msg_put_channel(struct sk_buff *msg, |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 569 | struct ieee80211_channel *chan, |
| 570 | bool large) |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 571 | { |
Rostislav Lisovy | ea077c1 | 2014-04-15 14:37:55 +0200 | [diff] [blame] | 572 | /* Some channels must be completely excluded from the |
| 573 | * list to protect old user-space tools from breaking |
| 574 | */ |
| 575 | if (!large && chan->flags & |
| 576 | (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ)) |
| 577 | return 0; |
| 578 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 579 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
| 580 | chan->center_freq)) |
| 581 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 582 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 583 | if ((chan->flags & IEEE80211_CHAN_DISABLED) && |
| 584 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED)) |
| 585 | goto nla_put_failure; |
Luis R. Rodriguez | 8fe02e1 | 2013-10-21 19:22:25 +0200 | [diff] [blame] | 586 | if (chan->flags & IEEE80211_CHAN_NO_IR) { |
| 587 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR)) |
| 588 | goto nla_put_failure; |
| 589 | if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS)) |
| 590 | goto nla_put_failure; |
| 591 | } |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 592 | if (chan->flags & IEEE80211_CHAN_RADAR) { |
| 593 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR)) |
| 594 | goto nla_put_failure; |
| 595 | if (large) { |
| 596 | u32 time; |
| 597 | |
| 598 | time = elapsed_jiffies_msecs(chan->dfs_state_entered); |
| 599 | |
| 600 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE, |
| 601 | chan->dfs_state)) |
| 602 | goto nla_put_failure; |
| 603 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME, |
| 604 | time)) |
| 605 | goto nla_put_failure; |
Janusz Dziedzic | 089027e | 2014-02-21 19:46:12 +0100 | [diff] [blame] | 606 | if (nla_put_u32(msg, |
| 607 | NL80211_FREQUENCY_ATTR_DFS_CAC_TIME, |
| 608 | chan->dfs_cac_ms)) |
| 609 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 610 | } |
| 611 | } |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 612 | |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 613 | if (large) { |
| 614 | if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) && |
| 615 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS)) |
| 616 | goto nla_put_failure; |
| 617 | if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) && |
| 618 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS)) |
| 619 | goto nla_put_failure; |
| 620 | if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) && |
| 621 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ)) |
| 622 | goto nla_put_failure; |
| 623 | if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) && |
| 624 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ)) |
| 625 | goto nla_put_failure; |
David Spinadel | 570dbde | 2014-02-23 09:12:59 +0200 | [diff] [blame] | 626 | if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) && |
| 627 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY)) |
| 628 | goto nla_put_failure; |
| 629 | if ((chan->flags & IEEE80211_CHAN_GO_CONCURRENT) && |
| 630 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_GO_CONCURRENT)) |
| 631 | goto nla_put_failure; |
Rostislav Lisovy | ea077c1 | 2014-04-15 14:37:55 +0200 | [diff] [blame] | 632 | if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) && |
| 633 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ)) |
| 634 | goto nla_put_failure; |
| 635 | if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) && |
| 636 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ)) |
| 637 | goto nla_put_failure; |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 638 | } |
| 639 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 640 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
| 641 | DBM_TO_MBM(chan->max_power))) |
| 642 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 643 | |
| 644 | return 0; |
| 645 | |
| 646 | nla_put_failure: |
| 647 | return -ENOBUFS; |
| 648 | } |
| 649 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 650 | /* netlink command implementations */ |
| 651 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 652 | struct key_parse { |
| 653 | struct key_params p; |
| 654 | int idx; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 655 | int type; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 656 | bool def, defmgmt; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 657 | bool def_uni, def_multi; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 658 | }; |
| 659 | |
| 660 | static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k) |
| 661 | { |
| 662 | struct nlattr *tb[NL80211_KEY_MAX + 1]; |
| 663 | int err = nla_parse_nested(tb, NL80211_KEY_MAX, key, |
| 664 | nl80211_key_policy); |
| 665 | if (err) |
| 666 | return err; |
| 667 | |
| 668 | k->def = !!tb[NL80211_KEY_DEFAULT]; |
| 669 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; |
| 670 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 671 | if (k->def) { |
| 672 | k->def_uni = true; |
| 673 | k->def_multi = true; |
| 674 | } |
| 675 | if (k->defmgmt) |
| 676 | k->def_multi = true; |
| 677 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 678 | if (tb[NL80211_KEY_IDX]) |
| 679 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); |
| 680 | |
| 681 | if (tb[NL80211_KEY_DATA]) { |
| 682 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); |
| 683 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); |
| 684 | } |
| 685 | |
| 686 | if (tb[NL80211_KEY_SEQ]) { |
| 687 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); |
| 688 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); |
| 689 | } |
| 690 | |
| 691 | if (tb[NL80211_KEY_CIPHER]) |
| 692 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); |
| 693 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 694 | if (tb[NL80211_KEY_TYPE]) { |
| 695 | k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); |
| 696 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 697 | return -EINVAL; |
| 698 | } |
| 699 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 700 | if (tb[NL80211_KEY_DEFAULT_TYPES]) { |
| 701 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
Johannes Berg | 2da8f41 | 2012-01-20 13:52:37 +0100 | [diff] [blame] | 702 | err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 703 | tb[NL80211_KEY_DEFAULT_TYPES], |
| 704 | nl80211_key_default_policy); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 705 | if (err) |
| 706 | return err; |
| 707 | |
| 708 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 709 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 710 | } |
| 711 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 712 | return 0; |
| 713 | } |
| 714 | |
| 715 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) |
| 716 | { |
| 717 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { |
| 718 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 719 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 720 | } |
| 721 | |
| 722 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { |
| 723 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 724 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 725 | } |
| 726 | |
| 727 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 728 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 729 | |
| 730 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) |
| 731 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); |
| 732 | |
| 733 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; |
| 734 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; |
| 735 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 736 | if (k->def) { |
| 737 | k->def_uni = true; |
| 738 | k->def_multi = true; |
| 739 | } |
| 740 | if (k->defmgmt) |
| 741 | k->def_multi = true; |
| 742 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 743 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 744 | k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 745 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 746 | return -EINVAL; |
| 747 | } |
| 748 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 749 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { |
| 750 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
| 751 | int err = nla_parse_nested( |
| 752 | kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 753 | info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], |
| 754 | nl80211_key_default_policy); |
| 755 | if (err) |
| 756 | return err; |
| 757 | |
| 758 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 759 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 760 | } |
| 761 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 762 | return 0; |
| 763 | } |
| 764 | |
| 765 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) |
| 766 | { |
| 767 | int err; |
| 768 | |
| 769 | memset(k, 0, sizeof(*k)); |
| 770 | k->idx = -1; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 771 | k->type = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 772 | |
| 773 | if (info->attrs[NL80211_ATTR_KEY]) |
| 774 | err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k); |
| 775 | else |
| 776 | err = nl80211_parse_key_old(info, k); |
| 777 | |
| 778 | if (err) |
| 779 | return err; |
| 780 | |
| 781 | if (k->def && k->defmgmt) |
| 782 | return -EINVAL; |
| 783 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 784 | if (k->defmgmt) { |
| 785 | if (k->def_uni || !k->def_multi) |
| 786 | return -EINVAL; |
| 787 | } |
| 788 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 789 | if (k->idx != -1) { |
| 790 | if (k->defmgmt) { |
| 791 | if (k->idx < 4 || k->idx > 5) |
| 792 | return -EINVAL; |
| 793 | } else if (k->def) { |
| 794 | if (k->idx < 0 || k->idx > 3) |
| 795 | return -EINVAL; |
| 796 | } else { |
| 797 | if (k->idx < 0 || k->idx > 5) |
| 798 | return -EINVAL; |
| 799 | } |
| 800 | } |
| 801 | |
| 802 | return 0; |
| 803 | } |
| 804 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 805 | static struct cfg80211_cached_keys * |
| 806 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 807 | struct nlattr *keys, bool *no_ht) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 808 | { |
| 809 | struct key_parse parse; |
| 810 | struct nlattr *key; |
| 811 | struct cfg80211_cached_keys *result; |
| 812 | int rem, err, def = 0; |
| 813 | |
| 814 | result = kzalloc(sizeof(*result), GFP_KERNEL); |
| 815 | if (!result) |
| 816 | return ERR_PTR(-ENOMEM); |
| 817 | |
| 818 | result->def = -1; |
| 819 | result->defmgmt = -1; |
| 820 | |
| 821 | nla_for_each_nested(key, keys, rem) { |
| 822 | memset(&parse, 0, sizeof(parse)); |
| 823 | parse.idx = -1; |
| 824 | |
| 825 | err = nl80211_parse_key_new(key, &parse); |
| 826 | if (err) |
| 827 | goto error; |
| 828 | err = -EINVAL; |
| 829 | if (!parse.p.key) |
| 830 | goto error; |
| 831 | if (parse.idx < 0 || parse.idx > 4) |
| 832 | goto error; |
| 833 | if (parse.def) { |
| 834 | if (def) |
| 835 | goto error; |
| 836 | def = 1; |
| 837 | result->def = parse.idx; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 838 | if (!parse.def_uni || !parse.def_multi) |
| 839 | goto error; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 840 | } else if (parse.defmgmt) |
| 841 | goto error; |
| 842 | err = cfg80211_validate_key_settings(rdev, &parse.p, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 843 | parse.idx, false, NULL); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 844 | if (err) |
| 845 | goto error; |
| 846 | result->params[parse.idx].cipher = parse.p.cipher; |
| 847 | result->params[parse.idx].key_len = parse.p.key_len; |
| 848 | result->params[parse.idx].key = result->data[parse.idx]; |
| 849 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 850 | |
| 851 | if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 || |
| 852 | parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) { |
| 853 | if (no_ht) |
| 854 | *no_ht = true; |
| 855 | } |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 856 | } |
| 857 | |
| 858 | return result; |
| 859 | error: |
| 860 | kfree(result); |
| 861 | return ERR_PTR(err); |
| 862 | } |
| 863 | |
| 864 | static int nl80211_key_allowed(struct wireless_dev *wdev) |
| 865 | { |
| 866 | ASSERT_WDEV_LOCK(wdev); |
| 867 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 868 | switch (wdev->iftype) { |
| 869 | case NL80211_IFTYPE_AP: |
| 870 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 871 | case NL80211_IFTYPE_P2P_GO: |
Thomas Pedersen | ff973af | 2011-05-03 16:57:12 -0700 | [diff] [blame] | 872 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 873 | break; |
| 874 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 875 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 876 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 877 | if (!wdev->current_bss) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 878 | return -ENOLINK; |
| 879 | break; |
| 880 | default: |
| 881 | return -EINVAL; |
| 882 | } |
| 883 | |
| 884 | return 0; |
| 885 | } |
| 886 | |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 887 | static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy, |
| 888 | struct nlattr *tb) |
| 889 | { |
| 890 | struct ieee80211_channel *chan; |
| 891 | |
| 892 | if (tb == NULL) |
| 893 | return NULL; |
| 894 | chan = ieee80211_get_channel(wiphy, nla_get_u32(tb)); |
| 895 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) |
| 896 | return NULL; |
| 897 | return chan; |
| 898 | } |
| 899 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 900 | static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) |
| 901 | { |
| 902 | struct nlattr *nl_modes = nla_nest_start(msg, attr); |
| 903 | int i; |
| 904 | |
| 905 | if (!nl_modes) |
| 906 | goto nla_put_failure; |
| 907 | |
| 908 | i = 0; |
| 909 | while (ifmodes) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 910 | if ((ifmodes & 1) && nla_put_flag(msg, i)) |
| 911 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 912 | ifmodes >>= 1; |
| 913 | i++; |
| 914 | } |
| 915 | |
| 916 | nla_nest_end(msg, nl_modes); |
| 917 | return 0; |
| 918 | |
| 919 | nla_put_failure: |
| 920 | return -ENOBUFS; |
| 921 | } |
| 922 | |
| 923 | static int nl80211_put_iface_combinations(struct wiphy *wiphy, |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 924 | struct sk_buff *msg, |
| 925 | bool large) |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 926 | { |
| 927 | struct nlattr *nl_combis; |
| 928 | int i, j; |
| 929 | |
| 930 | nl_combis = nla_nest_start(msg, |
| 931 | NL80211_ATTR_INTERFACE_COMBINATIONS); |
| 932 | if (!nl_combis) |
| 933 | goto nla_put_failure; |
| 934 | |
| 935 | for (i = 0; i < wiphy->n_iface_combinations; i++) { |
| 936 | const struct ieee80211_iface_combination *c; |
| 937 | struct nlattr *nl_combi, *nl_limits; |
| 938 | |
| 939 | c = &wiphy->iface_combinations[i]; |
| 940 | |
| 941 | nl_combi = nla_nest_start(msg, i + 1); |
| 942 | if (!nl_combi) |
| 943 | goto nla_put_failure; |
| 944 | |
| 945 | nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS); |
| 946 | if (!nl_limits) |
| 947 | goto nla_put_failure; |
| 948 | |
| 949 | for (j = 0; j < c->n_limits; j++) { |
| 950 | struct nlattr *nl_limit; |
| 951 | |
| 952 | nl_limit = nla_nest_start(msg, j + 1); |
| 953 | if (!nl_limit) |
| 954 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 955 | if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX, |
| 956 | c->limits[j].max)) |
| 957 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 958 | if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, |
| 959 | c->limits[j].types)) |
| 960 | goto nla_put_failure; |
| 961 | nla_nest_end(msg, nl_limit); |
| 962 | } |
| 963 | |
| 964 | nla_nest_end(msg, nl_limits); |
| 965 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 966 | if (c->beacon_int_infra_match && |
| 967 | nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH)) |
| 968 | goto nla_put_failure; |
| 969 | if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, |
| 970 | c->num_different_channels) || |
| 971 | nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM, |
| 972 | c->max_interfaces)) |
| 973 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 974 | if (large && |
Felix Fietkau | 8c48b50 | 2014-05-05 11:48:40 +0200 | [diff] [blame] | 975 | (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS, |
| 976 | c->radar_detect_widths) || |
| 977 | nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS, |
| 978 | c->radar_detect_regions))) |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 979 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 980 | |
| 981 | nla_nest_end(msg, nl_combi); |
| 982 | } |
| 983 | |
| 984 | nla_nest_end(msg, nl_combis); |
| 985 | |
| 986 | return 0; |
| 987 | nla_put_failure: |
| 988 | return -ENOBUFS; |
| 989 | } |
| 990 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 991 | #ifdef CONFIG_PM |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 992 | static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev, |
| 993 | struct sk_buff *msg) |
| 994 | { |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 995 | const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp; |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 996 | struct nlattr *nl_tcp; |
| 997 | |
| 998 | if (!tcp) |
| 999 | return 0; |
| 1000 | |
| 1001 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); |
| 1002 | if (!nl_tcp) |
| 1003 | return -ENOBUFS; |
| 1004 | |
| 1005 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 1006 | tcp->data_payload_max)) |
| 1007 | return -ENOBUFS; |
| 1008 | |
| 1009 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 1010 | tcp->data_payload_max)) |
| 1011 | return -ENOBUFS; |
| 1012 | |
| 1013 | if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ)) |
| 1014 | return -ENOBUFS; |
| 1015 | |
| 1016 | if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, |
| 1017 | sizeof(*tcp->tok), tcp->tok)) |
| 1018 | return -ENOBUFS; |
| 1019 | |
| 1020 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, |
| 1021 | tcp->data_interval_max)) |
| 1022 | return -ENOBUFS; |
| 1023 | |
| 1024 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, |
| 1025 | tcp->wake_payload_max)) |
| 1026 | return -ENOBUFS; |
| 1027 | |
| 1028 | nla_nest_end(msg, nl_tcp); |
| 1029 | return 0; |
| 1030 | } |
| 1031 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1032 | static int nl80211_send_wowlan(struct sk_buff *msg, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1033 | struct cfg80211_registered_device *rdev, |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1034 | bool large) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1035 | { |
| 1036 | struct nlattr *nl_wowlan; |
| 1037 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1038 | if (!rdev->wiphy.wowlan) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1039 | return 0; |
| 1040 | |
| 1041 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); |
| 1042 | if (!nl_wowlan) |
| 1043 | return -ENOBUFS; |
| 1044 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1045 | if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1046 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1047 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1048 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1049 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1050 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1051 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1052 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1053 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1054 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1055 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1056 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1057 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1058 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1059 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1060 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 1061 | return -ENOBUFS; |
| 1062 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1063 | if (rdev->wiphy.wowlan->n_patterns) { |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 1064 | struct nl80211_pattern_support pat = { |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1065 | .max_patterns = rdev->wiphy.wowlan->n_patterns, |
| 1066 | .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len, |
| 1067 | .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len, |
| 1068 | .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1069 | }; |
| 1070 | |
| 1071 | if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 1072 | sizeof(pat), &pat)) |
| 1073 | return -ENOBUFS; |
| 1074 | } |
| 1075 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1076 | if (large && nl80211_send_wowlan_tcp_caps(rdev, msg)) |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1077 | return -ENOBUFS; |
| 1078 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1079 | nla_nest_end(msg, nl_wowlan); |
| 1080 | |
| 1081 | return 0; |
| 1082 | } |
| 1083 | #endif |
| 1084 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1085 | static int nl80211_send_coalesce(struct sk_buff *msg, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1086 | struct cfg80211_registered_device *rdev) |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1087 | { |
| 1088 | struct nl80211_coalesce_rule_support rule; |
| 1089 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1090 | if (!rdev->wiphy.coalesce) |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1091 | return 0; |
| 1092 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1093 | rule.max_rules = rdev->wiphy.coalesce->n_rules; |
| 1094 | rule.max_delay = rdev->wiphy.coalesce->max_delay; |
| 1095 | rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns; |
| 1096 | rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len; |
| 1097 | rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len; |
| 1098 | rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset; |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1099 | |
| 1100 | if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule)) |
| 1101 | return -ENOBUFS; |
| 1102 | |
| 1103 | return 0; |
| 1104 | } |
| 1105 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1106 | static int nl80211_send_band_rateinfo(struct sk_buff *msg, |
| 1107 | struct ieee80211_supported_band *sband) |
| 1108 | { |
| 1109 | struct nlattr *nl_rates, *nl_rate; |
| 1110 | struct ieee80211_rate *rate; |
| 1111 | int i; |
| 1112 | |
| 1113 | /* add HT info */ |
| 1114 | if (sband->ht_cap.ht_supported && |
| 1115 | (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET, |
| 1116 | sizeof(sband->ht_cap.mcs), |
| 1117 | &sband->ht_cap.mcs) || |
| 1118 | nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA, |
| 1119 | sband->ht_cap.cap) || |
| 1120 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, |
| 1121 | sband->ht_cap.ampdu_factor) || |
| 1122 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, |
| 1123 | sband->ht_cap.ampdu_density))) |
| 1124 | return -ENOBUFS; |
| 1125 | |
| 1126 | /* add VHT info */ |
| 1127 | if (sband->vht_cap.vht_supported && |
| 1128 | (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET, |
| 1129 | sizeof(sband->vht_cap.vht_mcs), |
| 1130 | &sband->vht_cap.vht_mcs) || |
| 1131 | nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA, |
| 1132 | sband->vht_cap.cap))) |
| 1133 | return -ENOBUFS; |
| 1134 | |
| 1135 | /* add bitrates */ |
| 1136 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); |
| 1137 | if (!nl_rates) |
| 1138 | return -ENOBUFS; |
| 1139 | |
| 1140 | for (i = 0; i < sband->n_bitrates; i++) { |
| 1141 | nl_rate = nla_nest_start(msg, i); |
| 1142 | if (!nl_rate) |
| 1143 | return -ENOBUFS; |
| 1144 | |
| 1145 | rate = &sband->bitrates[i]; |
| 1146 | if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE, |
| 1147 | rate->bitrate)) |
| 1148 | return -ENOBUFS; |
| 1149 | if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) && |
| 1150 | nla_put_flag(msg, |
| 1151 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE)) |
| 1152 | return -ENOBUFS; |
| 1153 | |
| 1154 | nla_nest_end(msg, nl_rate); |
| 1155 | } |
| 1156 | |
| 1157 | nla_nest_end(msg, nl_rates); |
| 1158 | |
| 1159 | return 0; |
| 1160 | } |
| 1161 | |
| 1162 | static int |
| 1163 | nl80211_send_mgmt_stypes(struct sk_buff *msg, |
| 1164 | const struct ieee80211_txrx_stypes *mgmt_stypes) |
| 1165 | { |
| 1166 | u16 stypes; |
| 1167 | struct nlattr *nl_ftypes, *nl_ifs; |
| 1168 | enum nl80211_iftype ift; |
| 1169 | int i; |
| 1170 | |
| 1171 | if (!mgmt_stypes) |
| 1172 | return 0; |
| 1173 | |
| 1174 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES); |
| 1175 | if (!nl_ifs) |
| 1176 | return -ENOBUFS; |
| 1177 | |
| 1178 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 1179 | nl_ftypes = nla_nest_start(msg, ift); |
| 1180 | if (!nl_ftypes) |
| 1181 | return -ENOBUFS; |
| 1182 | i = 0; |
| 1183 | stypes = mgmt_stypes[ift].tx; |
| 1184 | while (stypes) { |
| 1185 | if ((stypes & 1) && |
| 1186 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1187 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1188 | return -ENOBUFS; |
| 1189 | stypes >>= 1; |
| 1190 | i++; |
| 1191 | } |
| 1192 | nla_nest_end(msg, nl_ftypes); |
| 1193 | } |
| 1194 | |
| 1195 | nla_nest_end(msg, nl_ifs); |
| 1196 | |
| 1197 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES); |
| 1198 | if (!nl_ifs) |
| 1199 | return -ENOBUFS; |
| 1200 | |
| 1201 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 1202 | nl_ftypes = nla_nest_start(msg, ift); |
| 1203 | if (!nl_ftypes) |
| 1204 | return -ENOBUFS; |
| 1205 | i = 0; |
| 1206 | stypes = mgmt_stypes[ift].rx; |
| 1207 | while (stypes) { |
| 1208 | if ((stypes & 1) && |
| 1209 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1210 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1211 | return -ENOBUFS; |
| 1212 | stypes >>= 1; |
| 1213 | i++; |
| 1214 | } |
| 1215 | nla_nest_end(msg, nl_ftypes); |
| 1216 | } |
| 1217 | nla_nest_end(msg, nl_ifs); |
| 1218 | |
| 1219 | return 0; |
| 1220 | } |
| 1221 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1222 | struct nl80211_dump_wiphy_state { |
| 1223 | s64 filter_wiphy; |
| 1224 | long start; |
| 1225 | long split_start, band_start, chan_start; |
| 1226 | bool split; |
| 1227 | }; |
| 1228 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1229 | static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev, |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1230 | enum nl80211_commands cmd, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1231 | struct sk_buff *msg, u32 portid, u32 seq, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1232 | int flags, struct nl80211_dump_wiphy_state *state) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1233 | { |
| 1234 | void *hdr; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1235 | struct nlattr *nl_bands, *nl_band; |
| 1236 | struct nlattr *nl_freqs, *nl_freq; |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1237 | struct nlattr *nl_cmds; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1238 | enum ieee80211_band band; |
| 1239 | struct ieee80211_channel *chan; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1240 | int i; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1241 | const struct ieee80211_txrx_stypes *mgmt_stypes = |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1242 | rdev->wiphy.mgmt_stypes; |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1243 | u32 features; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1244 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1245 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1246 | if (!hdr) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1247 | return -ENOBUFS; |
| 1248 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1249 | if (WARN_ON(!state)) |
| 1250 | return -EINVAL; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1251 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1252 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1253 | nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1254 | wiphy_name(&rdev->wiphy)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1255 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1256 | cfg80211_rdev_list_generation)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1257 | goto nla_put_failure; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1258 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1259 | if (cmd != NL80211_CMD_NEW_WIPHY) |
| 1260 | goto finish; |
| 1261 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1262 | switch (state->split_start) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1263 | case 0: |
| 1264 | if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1265 | rdev->wiphy.retry_short) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1266 | nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1267 | rdev->wiphy.retry_long) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1268 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1269 | rdev->wiphy.frag_threshold) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1270 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1271 | rdev->wiphy.rts_threshold) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1272 | nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1273 | rdev->wiphy.coverage_class) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1274 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1275 | rdev->wiphy.max_scan_ssids) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1276 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1277 | rdev->wiphy.max_sched_scan_ssids) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1278 | nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1279 | rdev->wiphy.max_scan_ie_len) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1280 | nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1281 | rdev->wiphy.max_sched_scan_ie_len) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1282 | nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1283 | rdev->wiphy.max_match_sets)) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1284 | goto nla_put_failure; |
| 1285 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1286 | if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1287 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN)) |
| 1288 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1289 | if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1290 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH)) |
| 1291 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1292 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1293 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD)) |
| 1294 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1295 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1296 | nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT)) |
| 1297 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1298 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1299 | nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT)) |
| 1300 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1301 | if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1302 | nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1303 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1304 | state->split_start++; |
| 1305 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1306 | break; |
| 1307 | case 1: |
| 1308 | if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1309 | sizeof(u32) * rdev->wiphy.n_cipher_suites, |
| 1310 | rdev->wiphy.cipher_suites)) |
Mahesh Palivela | bf0c111e | 2012-06-22 07:27:46 +0000 | [diff] [blame] | 1311 | goto nla_put_failure; |
| 1312 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1313 | if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1314 | rdev->wiphy.max_num_pmkids)) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1315 | goto nla_put_failure; |
| 1316 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1317 | if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1318 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE)) |
| 1319 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1320 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1321 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1322 | rdev->wiphy.available_antennas_tx) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1323 | nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1324 | rdev->wiphy.available_antennas_rx)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1325 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1326 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1327 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1328 | nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1329 | rdev->wiphy.probe_resp_offload)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1330 | goto nla_put_failure; |
Jouni Malinen | e2f367f26 | 2008-11-21 19:01:30 +0200 | [diff] [blame] | 1331 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1332 | if ((rdev->wiphy.available_antennas_tx || |
| 1333 | rdev->wiphy.available_antennas_rx) && |
| 1334 | rdev->ops->get_antenna) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1335 | u32 tx_ant = 0, rx_ant = 0; |
| 1336 | int res; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1337 | res = rdev_get_antenna(rdev, &tx_ant, &rx_ant); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1338 | if (!res) { |
| 1339 | if (nla_put_u32(msg, |
| 1340 | NL80211_ATTR_WIPHY_ANTENNA_TX, |
| 1341 | tx_ant) || |
| 1342 | nla_put_u32(msg, |
| 1343 | NL80211_ATTR_WIPHY_ANTENNA_RX, |
| 1344 | rx_ant)) |
| 1345 | goto nla_put_failure; |
| 1346 | } |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1347 | } |
| 1348 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1349 | state->split_start++; |
| 1350 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1351 | break; |
| 1352 | case 2: |
| 1353 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1354 | rdev->wiphy.interface_modes)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1355 | goto nla_put_failure; |
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 3: |
| 1360 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); |
| 1361 | if (!nl_bands) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1362 | goto nla_put_failure; |
| 1363 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1364 | for (band = state->band_start; |
| 1365 | band < IEEE80211_NUM_BANDS; band++) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1366 | struct ieee80211_supported_band *sband; |
| 1367 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1368 | sband = rdev->wiphy.bands[band]; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1369 | |
| 1370 | if (!sband) |
| 1371 | continue; |
| 1372 | |
| 1373 | nl_band = nla_nest_start(msg, band); |
| 1374 | if (!nl_band) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1375 | goto nla_put_failure; |
| 1376 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1377 | switch (state->chan_start) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1378 | case 0: |
| 1379 | if (nl80211_send_band_rateinfo(msg, sband)) |
| 1380 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1381 | state->chan_start++; |
| 1382 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1383 | break; |
| 1384 | default: |
| 1385 | /* add frequencies */ |
| 1386 | nl_freqs = nla_nest_start( |
| 1387 | msg, NL80211_BAND_ATTR_FREQS); |
| 1388 | if (!nl_freqs) |
| 1389 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1390 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1391 | for (i = state->chan_start - 1; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1392 | i < sband->n_channels; |
| 1393 | i++) { |
| 1394 | nl_freq = nla_nest_start(msg, i); |
| 1395 | if (!nl_freq) |
| 1396 | goto nla_put_failure; |
| 1397 | |
| 1398 | chan = &sband->channels[i]; |
| 1399 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1400 | if (nl80211_msg_put_channel( |
| 1401 | msg, chan, |
| 1402 | state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1403 | goto nla_put_failure; |
| 1404 | |
| 1405 | nla_nest_end(msg, nl_freq); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1406 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1407 | break; |
| 1408 | } |
| 1409 | if (i < sband->n_channels) |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1410 | state->chan_start = i + 2; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1411 | else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1412 | state->chan_start = 0; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1413 | nla_nest_end(msg, nl_freqs); |
| 1414 | } |
| 1415 | |
| 1416 | nla_nest_end(msg, nl_band); |
| 1417 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1418 | if (state->split) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1419 | /* start again here */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1420 | if (state->chan_start) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1421 | band--; |
| 1422 | break; |
| 1423 | } |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1424 | } |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1425 | nla_nest_end(msg, nl_bands); |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1426 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1427 | if (band < IEEE80211_NUM_BANDS) |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1428 | state->band_start = band + 1; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1429 | else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1430 | state->band_start = 0; |
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 | /* if bands & channels are done, continue outside */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1433 | if (state->band_start == 0 && state->chan_start == 0) |
| 1434 | state->split_start++; |
| 1435 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1436 | break; |
| 1437 | case 4: |
| 1438 | nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); |
| 1439 | if (!nl_cmds) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1440 | goto nla_put_failure; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1441 | |
| 1442 | i = 0; |
| 1443 | #define CMD(op, n) \ |
| 1444 | do { \ |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1445 | if (rdev->ops->op) { \ |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1446 | i++; \ |
| 1447 | if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \ |
| 1448 | goto nla_put_failure; \ |
| 1449 | } \ |
| 1450 | } while (0) |
| 1451 | |
| 1452 | CMD(add_virtual_intf, NEW_INTERFACE); |
| 1453 | CMD(change_virtual_intf, SET_INTERFACE); |
| 1454 | CMD(add_key, NEW_KEY); |
| 1455 | CMD(start_ap, START_AP); |
| 1456 | CMD(add_station, NEW_STATION); |
| 1457 | CMD(add_mpath, NEW_MPATH); |
| 1458 | CMD(update_mesh_config, SET_MESH_CONFIG); |
| 1459 | CMD(change_bss, SET_BSS); |
| 1460 | CMD(auth, AUTHENTICATE); |
| 1461 | CMD(assoc, ASSOCIATE); |
| 1462 | CMD(deauth, DEAUTHENTICATE); |
| 1463 | CMD(disassoc, DISASSOCIATE); |
| 1464 | CMD(join_ibss, JOIN_IBSS); |
| 1465 | CMD(join_mesh, JOIN_MESH); |
| 1466 | CMD(set_pmksa, SET_PMKSA); |
| 1467 | CMD(del_pmksa, DEL_PMKSA); |
| 1468 | CMD(flush_pmksa, FLUSH_PMKSA); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1469 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1470 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); |
| 1471 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); |
| 1472 | CMD(mgmt_tx, FRAME); |
| 1473 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1474 | if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1475 | i++; |
| 1476 | if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS)) |
| 1477 | goto nla_put_failure; |
| 1478 | } |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1479 | if (rdev->ops->set_monitor_channel || rdev->ops->start_ap || |
| 1480 | rdev->ops->join_mesh) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1481 | i++; |
| 1482 | if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL)) |
| 1483 | goto nla_put_failure; |
| 1484 | } |
| 1485 | CMD(set_wds_peer, SET_WDS_PEER); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1486 | if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1487 | CMD(tdls_mgmt, TDLS_MGMT); |
| 1488 | CMD(tdls_oper, TDLS_OPER); |
| 1489 | } |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1490 | if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1491 | CMD(sched_scan_start, START_SCHED_SCAN); |
| 1492 | CMD(probe_client, PROBE_CLIENT); |
| 1493 | CMD(set_noack_map, SET_NOACK_MAP); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1494 | if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1495 | i++; |
| 1496 | if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS)) |
| 1497 | goto nla_put_failure; |
| 1498 | } |
| 1499 | CMD(start_p2p_device, START_P2P_DEVICE); |
| 1500 | CMD(set_mcast_rate, SET_MCAST_RATE); |
Johannes Berg | 02df00e | 2014-06-10 14:06:25 +0200 | [diff] [blame] | 1501 | #ifdef CONFIG_NL80211_TESTMODE |
| 1502 | CMD(testmode_cmd, TESTMODE); |
| 1503 | #endif |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1504 | if (state->split) { |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 1505 | CMD(crit_proto_start, CRIT_PROTOCOL_START); |
| 1506 | CMD(crit_proto_stop, CRIT_PROTOCOL_STOP); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1507 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 1508 | CMD(channel_switch, CHANNEL_SWITCH); |
Johannes Berg | 02df00e | 2014-06-10 14:06:25 +0200 | [diff] [blame] | 1509 | CMD(set_qos_map, SET_QOS_MAP); |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 1510 | } |
Johannes Berg | 02df00e | 2014-06-10 14:06:25 +0200 | [diff] [blame] | 1511 | /* add into the if now */ |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1512 | #undef CMD |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1513 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1514 | if (rdev->ops->connect || rdev->ops->auth) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1515 | i++; |
| 1516 | if (nla_put_u32(msg, i, NL80211_CMD_CONNECT)) |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1517 | goto nla_put_failure; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1518 | } |
| 1519 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1520 | if (rdev->ops->disconnect || rdev->ops->deauth) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1521 | i++; |
| 1522 | if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT)) |
| 1523 | goto nla_put_failure; |
| 1524 | } |
Johannes Berg | 74b70a4 | 2010-08-24 12:15:53 +0200 | [diff] [blame] | 1525 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1526 | nla_nest_end(msg, nl_cmds); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1527 | state->split_start++; |
| 1528 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1529 | break; |
| 1530 | case 5: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1531 | if (rdev->ops->remain_on_channel && |
| 1532 | (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1533 | nla_put_u32(msg, |
| 1534 | NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1535 | rdev->wiphy.max_remain_on_channel_duration)) |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1536 | goto nla_put_failure; |
| 1537 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1538 | if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1539 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) |
| 1540 | goto nla_put_failure; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1541 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1542 | if (nl80211_send_mgmt_stypes(msg, mgmt_stypes)) |
| 1543 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1544 | state->split_start++; |
| 1545 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1546 | break; |
| 1547 | case 6: |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 1548 | #ifdef CONFIG_PM |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1549 | if (nl80211_send_wowlan(msg, rdev, state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1550 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1551 | state->split_start++; |
| 1552 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1553 | break; |
| 1554 | #else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1555 | state->split_start++; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1556 | #endif |
| 1557 | case 7: |
| 1558 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1559 | rdev->wiphy.software_iftypes)) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1560 | goto nla_put_failure; |
| 1561 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1562 | if (nl80211_put_iface_combinations(&rdev->wiphy, msg, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1563 | state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1564 | goto nla_put_failure; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1565 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1566 | state->split_start++; |
| 1567 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1568 | break; |
| 1569 | case 8: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1570 | if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1571 | nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1572 | rdev->wiphy.ap_sme_capa)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1573 | goto nla_put_failure; |
| 1574 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1575 | features = rdev->wiphy.features; |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1576 | /* |
| 1577 | * We can only add the per-channel limit information if the |
| 1578 | * dump is split, otherwise it makes it too big. Therefore |
| 1579 | * only advertise it in that case. |
| 1580 | */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1581 | if (state->split) |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1582 | features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS; |
| 1583 | if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1584 | goto nla_put_failure; |
| 1585 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1586 | if (rdev->wiphy.ht_capa_mod_mask && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1587 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1588 | sizeof(*rdev->wiphy.ht_capa_mod_mask), |
| 1589 | rdev->wiphy.ht_capa_mod_mask)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1590 | goto nla_put_failure; |
| 1591 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1592 | if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME && |
| 1593 | rdev->wiphy.max_acl_mac_addrs && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1594 | nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1595 | rdev->wiphy.max_acl_mac_addrs)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1596 | goto nla_put_failure; |
| 1597 | |
| 1598 | /* |
| 1599 | * Any information below this point is only available to |
| 1600 | * applications that can deal with it being split. This |
| 1601 | * helps ensure that newly added capabilities don't break |
| 1602 | * older tools by overrunning their buffers. |
| 1603 | * |
| 1604 | * We still increment split_start so that in the split |
| 1605 | * case we'll continue with more data in the next round, |
| 1606 | * but break unconditionally so unsplit data stops here. |
| 1607 | */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1608 | state->split_start++; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1609 | break; |
| 1610 | case 9: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1611 | if (rdev->wiphy.extended_capabilities && |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1612 | (nla_put(msg, NL80211_ATTR_EXT_CAPA, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1613 | rdev->wiphy.extended_capabilities_len, |
| 1614 | rdev->wiphy.extended_capabilities) || |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1615 | nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1616 | rdev->wiphy.extended_capabilities_len, |
| 1617 | rdev->wiphy.extended_capabilities_mask))) |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1618 | goto nla_put_failure; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1619 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1620 | if (rdev->wiphy.vht_capa_mod_mask && |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 1621 | nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1622 | sizeof(*rdev->wiphy.vht_capa_mod_mask), |
| 1623 | rdev->wiphy.vht_capa_mod_mask)) |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 1624 | goto nla_put_failure; |
| 1625 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1626 | state->split_start++; |
| 1627 | break; |
| 1628 | case 10: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1629 | if (nl80211_send_coalesce(msg, rdev)) |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1630 | goto nla_put_failure; |
| 1631 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1632 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) && |
Felix Fietkau | 01e0daa | 2013-11-09 14:57:54 +0100 | [diff] [blame] | 1633 | (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) || |
| 1634 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ))) |
| 1635 | goto nla_put_failure; |
Jouni Malinen | b43504c | 2014-01-15 00:01:08 +0200 | [diff] [blame] | 1636 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1637 | if (rdev->wiphy.max_ap_assoc_sta && |
Jouni Malinen | b43504c | 2014-01-15 00:01:08 +0200 | [diff] [blame] | 1638 | nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1639 | rdev->wiphy.max_ap_assoc_sta)) |
Jouni Malinen | b43504c | 2014-01-15 00:01:08 +0200 | [diff] [blame] | 1640 | goto nla_put_failure; |
| 1641 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 1642 | state->split_start++; |
| 1643 | break; |
| 1644 | case 11: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1645 | if (rdev->wiphy.n_vendor_commands) { |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1646 | const struct nl80211_vendor_cmd_info *info; |
| 1647 | struct nlattr *nested; |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 1648 | |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1649 | nested = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); |
| 1650 | if (!nested) |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 1651 | goto nla_put_failure; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1652 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1653 | for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { |
| 1654 | info = &rdev->wiphy.vendor_commands[i].info; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1655 | if (nla_put(msg, i + 1, sizeof(*info), info)) |
| 1656 | goto nla_put_failure; |
| 1657 | } |
| 1658 | nla_nest_end(msg, nested); |
| 1659 | } |
| 1660 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1661 | if (rdev->wiphy.n_vendor_events) { |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1662 | const struct nl80211_vendor_cmd_info *info; |
| 1663 | struct nlattr *nested; |
| 1664 | |
| 1665 | nested = nla_nest_start(msg, |
| 1666 | NL80211_ATTR_VENDOR_EVENTS); |
| 1667 | if (!nested) |
| 1668 | goto nla_put_failure; |
| 1669 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1670 | for (i = 0; i < rdev->wiphy.n_vendor_events; i++) { |
| 1671 | info = &rdev->wiphy.vendor_events[i]; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1672 | if (nla_put(msg, i + 1, sizeof(*info), info)) |
| 1673 | goto nla_put_failure; |
| 1674 | } |
| 1675 | nla_nest_end(msg, nested); |
| 1676 | } |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 1677 | state->split_start++; |
| 1678 | break; |
| 1679 | case 12: |
| 1680 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH && |
| 1681 | nla_put_u8(msg, NL80211_ATTR_MAX_CSA_COUNTERS, |
| 1682 | rdev->wiphy.max_num_csa_counters)) |
| 1683 | goto nla_put_failure; |
Felix Fietkau | 01e0daa | 2013-11-09 14:57:54 +0100 | [diff] [blame] | 1684 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1685 | /* done */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1686 | state->split_start = 0; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1687 | break; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1688 | } |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1689 | finish: |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1690 | return genlmsg_end(msg, hdr); |
| 1691 | |
| 1692 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 1693 | genlmsg_cancel(msg, hdr); |
| 1694 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1695 | } |
| 1696 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1697 | static int nl80211_dump_wiphy_parse(struct sk_buff *skb, |
| 1698 | struct netlink_callback *cb, |
| 1699 | struct nl80211_dump_wiphy_state *state) |
| 1700 | { |
| 1701 | struct nlattr **tb = nl80211_fam.attrbuf; |
| 1702 | int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 1703 | tb, nl80211_fam.maxattr, nl80211_policy); |
| 1704 | /* ignore parse errors for backward compatibility */ |
| 1705 | if (ret) |
| 1706 | return 0; |
| 1707 | |
| 1708 | state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP]; |
| 1709 | if (tb[NL80211_ATTR_WIPHY]) |
| 1710 | state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]); |
| 1711 | if (tb[NL80211_ATTR_WDEV]) |
| 1712 | state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32; |
| 1713 | if (tb[NL80211_ATTR_IFINDEX]) { |
| 1714 | struct net_device *netdev; |
| 1715 | struct cfg80211_registered_device *rdev; |
| 1716 | int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); |
| 1717 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 1718 | netdev = __dev_get_by_index(sock_net(skb->sk), ifidx); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1719 | if (!netdev) |
| 1720 | return -ENODEV; |
| 1721 | if (netdev->ieee80211_ptr) { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 1722 | rdev = wiphy_to_rdev( |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1723 | netdev->ieee80211_ptr->wiphy); |
| 1724 | state->filter_wiphy = rdev->wiphy_idx; |
| 1725 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1726 | } |
| 1727 | |
| 1728 | return 0; |
| 1729 | } |
| 1730 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1731 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) |
| 1732 | { |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1733 | int idx = 0, ret; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1734 | struct nl80211_dump_wiphy_state *state = (void *)cb->args[0]; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1735 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 3a5a423 | 2013-06-19 10:09:57 +0200 | [diff] [blame] | 1736 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1737 | rtnl_lock(); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1738 | if (!state) { |
| 1739 | state = kzalloc(sizeof(*state), GFP_KERNEL); |
John W. Linville | 57ed5cd | 2013-06-28 13:18:21 -0400 | [diff] [blame] | 1740 | if (!state) { |
| 1741 | rtnl_unlock(); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1742 | return -ENOMEM; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1743 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1744 | state->filter_wiphy = -1; |
| 1745 | ret = nl80211_dump_wiphy_parse(skb, cb, state); |
| 1746 | if (ret) { |
| 1747 | kfree(state); |
| 1748 | rtnl_unlock(); |
| 1749 | return ret; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1750 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1751 | cb->args[0] = (long)state; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1752 | } |
| 1753 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1754 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 1755 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1756 | continue; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1757 | if (++idx <= state->start) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1758 | continue; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1759 | if (state->filter_wiphy != -1 && |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1760 | state->filter_wiphy != rdev->wiphy_idx) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1761 | continue; |
| 1762 | /* attempt to fit multiple wiphy data chunks into the skb */ |
| 1763 | do { |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1764 | ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, |
| 1765 | skb, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1766 | NETLINK_CB(cb->skb).portid, |
| 1767 | cb->nlh->nlmsg_seq, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1768 | NLM_F_MULTI, state); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1769 | if (ret < 0) { |
| 1770 | /* |
| 1771 | * If sending the wiphy data didn't fit (ENOBUFS |
| 1772 | * or EMSGSIZE returned), this SKB is still |
| 1773 | * empty (so it's not too big because another |
| 1774 | * wiphy dataset is already in the skb) and |
| 1775 | * we've not tried to adjust the dump allocation |
| 1776 | * yet ... then adjust the alloc size to be |
| 1777 | * bigger, and return 1 but with the empty skb. |
| 1778 | * This results in an empty message being RX'ed |
| 1779 | * in userspace, but that is ignored. |
| 1780 | * |
| 1781 | * We can then retry with the larger buffer. |
| 1782 | */ |
| 1783 | if ((ret == -ENOBUFS || ret == -EMSGSIZE) && |
Pontus Fuchs | f12cb28 | 2014-01-16 15:00:40 +0100 | [diff] [blame] | 1784 | !skb->len && !state->split && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1785 | cb->min_dump_alloc < 4096) { |
| 1786 | cb->min_dump_alloc = 4096; |
Pontus Fuchs | f12cb28 | 2014-01-16 15:00:40 +0100 | [diff] [blame] | 1787 | state->split_start = 0; |
David S. Miller | d98cae64e | 2013-06-19 16:49:39 -0700 | [diff] [blame] | 1788 | rtnl_unlock(); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1789 | return 1; |
| 1790 | } |
| 1791 | idx--; |
| 1792 | break; |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1793 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1794 | } while (state->split_start > 0); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1795 | break; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1796 | } |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1797 | rtnl_unlock(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1798 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1799 | state->start = idx; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1800 | |
| 1801 | return skb->len; |
| 1802 | } |
| 1803 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1804 | static int nl80211_dump_wiphy_done(struct netlink_callback *cb) |
| 1805 | { |
| 1806 | kfree((void *)cb->args[0]); |
| 1807 | return 0; |
| 1808 | } |
| 1809 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1810 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1811 | { |
| 1812 | struct sk_buff *msg; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1813 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1814 | struct nl80211_dump_wiphy_state state = {}; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1815 | |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1816 | msg = nlmsg_new(4096, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1817 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1818 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1819 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1820 | if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg, |
| 1821 | info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1822 | &state) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1823 | nlmsg_free(msg); |
| 1824 | return -ENOBUFS; |
| 1825 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1826 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 1827 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1828 | } |
| 1829 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1830 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
| 1831 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, |
| 1832 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, |
| 1833 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, |
| 1834 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, |
| 1835 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, |
| 1836 | }; |
| 1837 | |
| 1838 | static int parse_txq_params(struct nlattr *tb[], |
| 1839 | struct ieee80211_txq_params *txq_params) |
| 1840 | { |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1841 | if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] || |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1842 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
| 1843 | !tb[NL80211_TXQ_ATTR_AIFS]) |
| 1844 | return -EINVAL; |
| 1845 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1846 | txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1847 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
| 1848 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); |
| 1849 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); |
| 1850 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); |
| 1851 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1852 | if (txq_params->ac >= NL80211_NUM_ACS) |
| 1853 | return -EINVAL; |
| 1854 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1855 | return 0; |
| 1856 | } |
| 1857 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1858 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
| 1859 | { |
| 1860 | /* |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1861 | * You can only set the channel explicitly for WDS interfaces, |
| 1862 | * all others have their channel managed via their respective |
| 1863 | * "establish a connection" command (connect, join, ...) |
| 1864 | * |
| 1865 | * For AP/GO and mesh mode, the channel can be set with the |
| 1866 | * channel userspace API, but is only stored and passed to the |
| 1867 | * low-level driver when the AP starts or the mesh is joined. |
| 1868 | * This is for backward compatibility, userspace can also give |
| 1869 | * the channel in the start-ap or join-mesh commands instead. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1870 | * |
| 1871 | * Monitors are special as they are normally slaved to |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1872 | * whatever else is going on, so they have their own special |
| 1873 | * operation to set the monitor channel if possible. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1874 | */ |
| 1875 | return !wdev || |
| 1876 | wdev->iftype == NL80211_IFTYPE_AP || |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1877 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 1878 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
| 1879 | wdev->iftype == NL80211_IFTYPE_P2P_GO; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1880 | } |
| 1881 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1882 | static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev, |
| 1883 | struct genl_info *info, |
| 1884 | struct cfg80211_chan_def *chandef) |
| 1885 | { |
Mahesh Palivela | dbeca2e | 2012-11-29 14:11:07 +0530 | [diff] [blame] | 1886 | u32 control_freq; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1887 | |
| 1888 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 1889 | return -EINVAL; |
| 1890 | |
| 1891 | control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 1892 | |
| 1893 | chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1894 | chandef->width = NL80211_CHAN_WIDTH_20_NOHT; |
| 1895 | chandef->center_freq1 = control_freq; |
| 1896 | chandef->center_freq2 = 0; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1897 | |
| 1898 | /* Primary channel not allowed */ |
| 1899 | if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) |
| 1900 | return -EINVAL; |
| 1901 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1902 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 1903 | enum nl80211_channel_type chantype; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1904 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1905 | chantype = nla_get_u32( |
| 1906 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 1907 | |
| 1908 | switch (chantype) { |
| 1909 | case NL80211_CHAN_NO_HT: |
| 1910 | case NL80211_CHAN_HT20: |
| 1911 | case NL80211_CHAN_HT40PLUS: |
| 1912 | case NL80211_CHAN_HT40MINUS: |
| 1913 | cfg80211_chandef_create(chandef, chandef->chan, |
| 1914 | chantype); |
| 1915 | break; |
| 1916 | default: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1917 | return -EINVAL; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1918 | } |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1919 | } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) { |
| 1920 | chandef->width = |
| 1921 | nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]); |
| 1922 | if (info->attrs[NL80211_ATTR_CENTER_FREQ1]) |
| 1923 | chandef->center_freq1 = |
| 1924 | nla_get_u32( |
| 1925 | info->attrs[NL80211_ATTR_CENTER_FREQ1]); |
| 1926 | if (info->attrs[NL80211_ATTR_CENTER_FREQ2]) |
| 1927 | chandef->center_freq2 = |
| 1928 | nla_get_u32( |
| 1929 | info->attrs[NL80211_ATTR_CENTER_FREQ2]); |
| 1930 | } |
| 1931 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 1932 | if (!cfg80211_chandef_valid(chandef)) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1933 | return -EINVAL; |
| 1934 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 1935 | if (!cfg80211_chandef_usable(&rdev->wiphy, chandef, |
| 1936 | IEEE80211_CHAN_DISABLED)) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1937 | return -EINVAL; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1938 | |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 1939 | if ((chandef->width == NL80211_CHAN_WIDTH_5 || |
| 1940 | chandef->width == NL80211_CHAN_WIDTH_10) && |
| 1941 | !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ)) |
| 1942 | return -EINVAL; |
| 1943 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1944 | return 0; |
| 1945 | } |
| 1946 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1947 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 1948 | struct net_device *dev, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1949 | struct genl_info *info) |
| 1950 | { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1951 | struct cfg80211_chan_def chandef; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1952 | int result; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1953 | enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR; |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 1954 | struct wireless_dev *wdev = NULL; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1955 | |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 1956 | if (dev) |
| 1957 | wdev = dev->ieee80211_ptr; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1958 | if (!nl80211_can_set_dev_channel(wdev)) |
| 1959 | return -EOPNOTSUPP; |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 1960 | if (wdev) |
| 1961 | iftype = wdev->iftype; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1962 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1963 | result = nl80211_parse_chandef(rdev, info, &chandef); |
| 1964 | if (result) |
| 1965 | return result; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1966 | |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1967 | switch (iftype) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1968 | case NL80211_IFTYPE_AP: |
| 1969 | case NL80211_IFTYPE_P2P_GO: |
Ilan Peer | 174e0cd | 2014-02-23 09:13:01 +0200 | [diff] [blame] | 1970 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef, iftype)) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1971 | result = -EINVAL; |
| 1972 | break; |
| 1973 | } |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 1974 | if (wdev->beacon_interval) { |
| 1975 | if (!dev || !rdev->ops->set_ap_chanwidth || |
| 1976 | !(rdev->wiphy.features & |
| 1977 | NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) { |
| 1978 | result = -EBUSY; |
| 1979 | break; |
| 1980 | } |
| 1981 | |
| 1982 | /* Only allow dynamic channel width changes */ |
| 1983 | if (chandef.chan != wdev->preset_chandef.chan) { |
| 1984 | result = -EBUSY; |
| 1985 | break; |
| 1986 | } |
| 1987 | result = rdev_set_ap_chanwidth(rdev, dev, &chandef); |
| 1988 | if (result) |
| 1989 | break; |
| 1990 | } |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1991 | wdev->preset_chandef = chandef; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1992 | result = 0; |
| 1993 | break; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1994 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1995 | result = cfg80211_set_mesh_channel(rdev, wdev, &chandef); |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1996 | break; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1997 | case NL80211_IFTYPE_MONITOR: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1998 | result = cfg80211_set_monitor_channel(rdev, &chandef); |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1999 | break; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2000 | default: |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2001 | result = -EINVAL; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2002 | } |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2003 | |
| 2004 | return result; |
| 2005 | } |
| 2006 | |
| 2007 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) |
| 2008 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2009 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2010 | struct net_device *netdev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2011 | |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2012 | return __nl80211_set_channel(rdev, netdev, info); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2013 | } |
| 2014 | |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2015 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
| 2016 | { |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 2017 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2018 | struct net_device *dev = info->user_ptr[1]; |
| 2019 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 388ac77 | 2010-10-07 13:11:09 +0200 | [diff] [blame] | 2020 | const u8 *bssid; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2021 | |
| 2022 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2023 | return -EINVAL; |
| 2024 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 2025 | if (netif_running(dev)) |
| 2026 | return -EBUSY; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2027 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 2028 | if (!rdev->ops->set_wds_peer) |
| 2029 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2030 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 2031 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
| 2032 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2033 | |
| 2034 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2035 | return rdev_set_wds_peer(rdev, dev, bssid); |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2036 | } |
| 2037 | |
| 2038 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2039 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 2040 | { |
| 2041 | struct cfg80211_registered_device *rdev; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2042 | struct net_device *netdev = NULL; |
| 2043 | struct wireless_dev *wdev; |
Bill Jordan | a1e567c | 2010-09-10 11:22:32 -0400 | [diff] [blame] | 2044 | int result = 0, rem_txq_params = 0; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2045 | struct nlattr *nl_txq_params; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2046 | u32 changed; |
| 2047 | u8 retry_short = 0, retry_long = 0; |
| 2048 | u32 frag_threshold = 0, rts_threshold = 0; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2049 | u8 coverage_class = 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2050 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2051 | ASSERT_RTNL(); |
| 2052 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2053 | /* |
| 2054 | * Try to find the wiphy and netdev. Normally this |
| 2055 | * function shouldn't need the netdev, but this is |
| 2056 | * done for backward compatibility -- previously |
| 2057 | * setting the channel was done per wiphy, but now |
| 2058 | * it is per netdev. Previous userland like hostapd |
| 2059 | * also passed a netdev to set_wiphy, so that it is |
| 2060 | * possible to let that go to the right netdev! |
| 2061 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2062 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2063 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
| 2064 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); |
| 2065 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2066 | netdev = __dev_get_by_index(genl_info_net(info), ifindex); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2067 | if (netdev && netdev->ieee80211_ptr) |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 2068 | rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2069 | else |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2070 | netdev = NULL; |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2071 | } |
| 2072 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2073 | if (!netdev) { |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 2074 | rdev = __cfg80211_rdev_from_attrs(genl_info_net(info), |
| 2075 | info->attrs); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2076 | if (IS_ERR(rdev)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2077 | return PTR_ERR(rdev); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2078 | wdev = NULL; |
| 2079 | netdev = NULL; |
| 2080 | result = 0; |
Johannes Berg | 71fe96b | 2012-10-24 10:04:58 +0200 | [diff] [blame] | 2081 | } else |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2082 | wdev = netdev->ieee80211_ptr; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2083 | |
| 2084 | /* |
| 2085 | * end workaround code, by now the rdev is available |
| 2086 | * and locked, and wdev may or may not be NULL. |
| 2087 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2088 | |
| 2089 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2090 | result = cfg80211_dev_rename( |
| 2091 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2092 | |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2093 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2094 | return result; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2095 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2096 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { |
| 2097 | struct ieee80211_txq_params txq_params; |
| 2098 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; |
| 2099 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2100 | if (!rdev->ops->set_txq_params) |
| 2101 | return -EOPNOTSUPP; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2102 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2103 | if (!netdev) |
| 2104 | return -EINVAL; |
Eliad Peller | f70f01c | 2011-09-25 20:06:53 +0300 | [diff] [blame] | 2105 | |
Johannes Berg | 133a3ff | 2011-11-03 14:50:13 +0100 | [diff] [blame] | 2106 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2107 | netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2108 | return -EINVAL; |
Johannes Berg | 133a3ff | 2011-11-03 14:50:13 +0100 | [diff] [blame] | 2109 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2110 | if (!netif_running(netdev)) |
| 2111 | return -ENETDOWN; |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 2112 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2113 | nla_for_each_nested(nl_txq_params, |
| 2114 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], |
| 2115 | rem_txq_params) { |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 2116 | result = nla_parse(tb, NL80211_TXQ_ATTR_MAX, |
| 2117 | nla_data(nl_txq_params), |
| 2118 | nla_len(nl_txq_params), |
| 2119 | txq_params_policy); |
| 2120 | if (result) |
| 2121 | return result; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2122 | result = parse_txq_params(tb, &txq_params); |
| 2123 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2124 | return result; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2125 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2126 | result = rdev_set_txq_params(rdev, netdev, |
| 2127 | &txq_params); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2128 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2129 | return result; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2130 | } |
| 2131 | } |
| 2132 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2133 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2134 | result = __nl80211_set_channel( |
| 2135 | rdev, |
| 2136 | nl80211_can_set_dev_channel(wdev) ? netdev : NULL, |
| 2137 | info); |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2138 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2139 | return result; |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2140 | } |
| 2141 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2142 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2143 | struct wireless_dev *txp_wdev = wdev; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2144 | enum nl80211_tx_power_setting type; |
| 2145 | int idx, mbm = 0; |
| 2146 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2147 | if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER)) |
| 2148 | txp_wdev = NULL; |
| 2149 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2150 | if (!rdev->ops->set_tx_power) |
| 2151 | return -EOPNOTSUPP; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2152 | |
| 2153 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; |
| 2154 | type = nla_get_u32(info->attrs[idx]); |
| 2155 | |
| 2156 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2157 | (type != NL80211_TX_POWER_AUTOMATIC)) |
| 2158 | return -EINVAL; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2159 | |
| 2160 | if (type != NL80211_TX_POWER_AUTOMATIC) { |
| 2161 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; |
| 2162 | mbm = nla_get_u32(info->attrs[idx]); |
| 2163 | } |
| 2164 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2165 | result = rdev_set_tx_power(rdev, txp_wdev, type, mbm); |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2166 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2167 | return result; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2168 | } |
| 2169 | |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2170 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
| 2171 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { |
| 2172 | u32 tx_ant, rx_ant; |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2173 | if ((!rdev->wiphy.available_antennas_tx && |
| 2174 | !rdev->wiphy.available_antennas_rx) || |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2175 | !rdev->ops->set_antenna) |
| 2176 | return -EOPNOTSUPP; |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2177 | |
| 2178 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); |
| 2179 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); |
| 2180 | |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2181 | /* reject antenna configurations which don't match the |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2182 | * available antenna masks, except for the "all" mask */ |
| 2183 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2184 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) |
| 2185 | return -EINVAL; |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2186 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2187 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
| 2188 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2189 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2190 | result = rdev_set_antenna(rdev, tx_ant, rx_ant); |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2191 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2192 | return result; |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2193 | } |
| 2194 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2195 | changed = 0; |
| 2196 | |
| 2197 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { |
| 2198 | retry_short = nla_get_u8( |
| 2199 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2200 | if (retry_short == 0) |
| 2201 | return -EINVAL; |
| 2202 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2203 | changed |= WIPHY_PARAM_RETRY_SHORT; |
| 2204 | } |
| 2205 | |
| 2206 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { |
| 2207 | retry_long = nla_get_u8( |
| 2208 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2209 | if (retry_long == 0) |
| 2210 | return -EINVAL; |
| 2211 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2212 | changed |= WIPHY_PARAM_RETRY_LONG; |
| 2213 | } |
| 2214 | |
| 2215 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { |
| 2216 | frag_threshold = nla_get_u32( |
| 2217 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2218 | if (frag_threshold < 256) |
| 2219 | return -EINVAL; |
| 2220 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2221 | if (frag_threshold != (u32) -1) { |
| 2222 | /* |
| 2223 | * Fragments (apart from the last one) are required to |
| 2224 | * have even length. Make the fragmentation code |
| 2225 | * simpler by stripping LSB should someone try to use |
| 2226 | * odd threshold value. |
| 2227 | */ |
| 2228 | frag_threshold &= ~0x1; |
| 2229 | } |
| 2230 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; |
| 2231 | } |
| 2232 | |
| 2233 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { |
| 2234 | rts_threshold = nla_get_u32( |
| 2235 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); |
| 2236 | changed |= WIPHY_PARAM_RTS_THRESHOLD; |
| 2237 | } |
| 2238 | |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2239 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
| 2240 | coverage_class = nla_get_u8( |
| 2241 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); |
| 2242 | changed |= WIPHY_PARAM_COVERAGE_CLASS; |
| 2243 | } |
| 2244 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2245 | if (changed) { |
| 2246 | u8 old_retry_short, old_retry_long; |
| 2247 | u32 old_frag_threshold, old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2248 | u8 old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2249 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2250 | if (!rdev->ops->set_wiphy_params) |
| 2251 | return -EOPNOTSUPP; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2252 | |
| 2253 | old_retry_short = rdev->wiphy.retry_short; |
| 2254 | old_retry_long = rdev->wiphy.retry_long; |
| 2255 | old_frag_threshold = rdev->wiphy.frag_threshold; |
| 2256 | old_rts_threshold = rdev->wiphy.rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2257 | old_coverage_class = rdev->wiphy.coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2258 | |
| 2259 | if (changed & WIPHY_PARAM_RETRY_SHORT) |
| 2260 | rdev->wiphy.retry_short = retry_short; |
| 2261 | if (changed & WIPHY_PARAM_RETRY_LONG) |
| 2262 | rdev->wiphy.retry_long = retry_long; |
| 2263 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) |
| 2264 | rdev->wiphy.frag_threshold = frag_threshold; |
| 2265 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) |
| 2266 | rdev->wiphy.rts_threshold = rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2267 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
| 2268 | rdev->wiphy.coverage_class = coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2269 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2270 | result = rdev_set_wiphy_params(rdev, changed); |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2271 | if (result) { |
| 2272 | rdev->wiphy.retry_short = old_retry_short; |
| 2273 | rdev->wiphy.retry_long = old_retry_long; |
| 2274 | rdev->wiphy.frag_threshold = old_frag_threshold; |
| 2275 | rdev->wiphy.rts_threshold = old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2276 | rdev->wiphy.coverage_class = old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2277 | } |
| 2278 | } |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2279 | return 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2280 | } |
| 2281 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 2282 | static inline u64 wdev_id(struct wireless_dev *wdev) |
| 2283 | { |
| 2284 | return (u64)wdev->identifier | |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 2285 | ((u64)wiphy_to_rdev(wdev->wiphy)->wiphy_idx << 32); |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 2286 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2287 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2288 | static int nl80211_send_chandef(struct sk_buff *msg, |
Janusz Dziedzic | d2859df | 2013-11-06 13:55:51 +0100 | [diff] [blame] | 2289 | const struct cfg80211_chan_def *chandef) |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2290 | { |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 2291 | WARN_ON(!cfg80211_chandef_valid(chandef)); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2292 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2293 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
| 2294 | chandef->chan->center_freq)) |
| 2295 | return -ENOBUFS; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2296 | switch (chandef->width) { |
| 2297 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 2298 | case NL80211_CHAN_WIDTH_20: |
| 2299 | case NL80211_CHAN_WIDTH_40: |
| 2300 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 2301 | cfg80211_get_chandef_type(chandef))) |
| 2302 | return -ENOBUFS; |
| 2303 | break; |
| 2304 | default: |
| 2305 | break; |
| 2306 | } |
| 2307 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width)) |
| 2308 | return -ENOBUFS; |
| 2309 | if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1)) |
| 2310 | return -ENOBUFS; |
| 2311 | if (chandef->center_freq2 && |
| 2312 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2)) |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2313 | return -ENOBUFS; |
| 2314 | return 0; |
| 2315 | } |
| 2316 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2317 | 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] | 2318 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2319 | struct wireless_dev *wdev) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2320 | { |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2321 | struct net_device *dev = wdev->netdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2322 | void *hdr; |
| 2323 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2324 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_INTERFACE); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2325 | if (!hdr) |
| 2326 | return -1; |
| 2327 | |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2328 | if (dev && |
| 2329 | (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2330 | nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name))) |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2331 | goto nla_put_failure; |
| 2332 | |
| 2333 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 2334 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 2335 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2336 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2337 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
| 2338 | rdev->devlist_generation ^ |
| 2339 | (cfg80211_rdev_list_generation << 2))) |
| 2340 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2341 | |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 2342 | if (rdev->ops->get_channel) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2343 | int ret; |
| 2344 | struct cfg80211_chan_def chandef; |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 2345 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2346 | ret = rdev_get_channel(rdev, wdev, &chandef); |
| 2347 | if (ret == 0) { |
| 2348 | if (nl80211_send_chandef(msg, &chandef)) |
| 2349 | goto nla_put_failure; |
| 2350 | } |
Pontus Fuchs | d91df0e | 2012-04-03 16:39:58 +0200 | [diff] [blame] | 2351 | } |
| 2352 | |
Antonio Quartulli | b84e7a0 | 2012-11-07 12:52:20 +0100 | [diff] [blame] | 2353 | if (wdev->ssid_len) { |
| 2354 | if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid)) |
| 2355 | goto nla_put_failure; |
| 2356 | } |
| 2357 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2358 | return genlmsg_end(msg, hdr); |
| 2359 | |
| 2360 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 2361 | genlmsg_cancel(msg, hdr); |
| 2362 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2363 | } |
| 2364 | |
| 2365 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) |
| 2366 | { |
| 2367 | int wp_idx = 0; |
| 2368 | int if_idx = 0; |
| 2369 | int wp_start = cb->args[0]; |
| 2370 | int if_start = cb->args[1]; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2371 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2372 | struct wireless_dev *wdev; |
| 2373 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2374 | rtnl_lock(); |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2375 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 2376 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2377 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2378 | if (wp_idx < wp_start) { |
| 2379 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2380 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2381 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2382 | if_idx = 0; |
| 2383 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 2384 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2385 | if (if_idx < if_start) { |
| 2386 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2387 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2388 | } |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2389 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2390 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2391 | rdev, wdev) < 0) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2392 | goto out; |
| 2393 | } |
| 2394 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2395 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2396 | |
| 2397 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2398 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2399 | out: |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2400 | rtnl_unlock(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2401 | |
| 2402 | cb->args[0] = wp_idx; |
| 2403 | cb->args[1] = if_idx; |
| 2404 | |
| 2405 | return skb->len; |
| 2406 | } |
| 2407 | |
| 2408 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) |
| 2409 | { |
| 2410 | struct sk_buff *msg; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2411 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2412 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2413 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2414 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2415 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2416 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2417 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2418 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2419 | rdev, wdev) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2420 | nlmsg_free(msg); |
| 2421 | return -ENOBUFS; |
| 2422 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2423 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 2424 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2425 | } |
| 2426 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2427 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
| 2428 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, |
| 2429 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, |
| 2430 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, |
| 2431 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, |
| 2432 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2433 | [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG }, |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2434 | }; |
| 2435 | |
| 2436 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) |
| 2437 | { |
| 2438 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; |
| 2439 | int flag; |
| 2440 | |
| 2441 | *mntrflags = 0; |
| 2442 | |
| 2443 | if (!nla) |
| 2444 | return -EINVAL; |
| 2445 | |
| 2446 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, |
| 2447 | nla, mntr_flags_policy)) |
| 2448 | return -EINVAL; |
| 2449 | |
| 2450 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) |
| 2451 | if (flags[flag]) |
| 2452 | *mntrflags |= (1<<flag); |
| 2453 | |
| 2454 | return 0; |
| 2455 | } |
| 2456 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2457 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2458 | struct net_device *netdev, u8 use_4addr, |
| 2459 | enum nl80211_iftype iftype) |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2460 | { |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2461 | if (!use_4addr) { |
Jiri Pirko | f350a0a8 | 2010-06-15 06:50:45 +0000 | [diff] [blame] | 2462 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2463 | return -EBUSY; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2464 | return 0; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2465 | } |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2466 | |
| 2467 | switch (iftype) { |
| 2468 | case NL80211_IFTYPE_AP_VLAN: |
| 2469 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) |
| 2470 | return 0; |
| 2471 | break; |
| 2472 | case NL80211_IFTYPE_STATION: |
| 2473 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) |
| 2474 | return 0; |
| 2475 | break; |
| 2476 | default: |
| 2477 | break; |
| 2478 | } |
| 2479 | |
| 2480 | return -EOPNOTSUPP; |
| 2481 | } |
| 2482 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2483 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
| 2484 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2485 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2486 | struct vif_params params; |
Johannes Berg | e36d56b | 2009-06-09 21:04:43 +0200 | [diff] [blame] | 2487 | int err; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2488 | enum nl80211_iftype otype, ntype; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2489 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2490 | u32 _flags, *flags = NULL; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2491 | bool change = false; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2492 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2493 | memset(¶ms, 0, sizeof(params)); |
| 2494 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2495 | otype = ntype = dev->ieee80211_ptr->iftype; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2496 | |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 2497 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2498 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2499 | if (otype != ntype) |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2500 | change = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2501 | if (ntype > NL80211_IFTYPE_MAX) |
| 2502 | return -EINVAL; |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 2503 | } |
| 2504 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2505 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2506 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2507 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2508 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
| 2509 | return -EINVAL; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2510 | if (netif_running(dev)) |
| 2511 | return -EBUSY; |
| 2512 | |
| 2513 | wdev_lock(wdev); |
| 2514 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 2515 | IEEE80211_MAX_MESH_ID_LEN); |
| 2516 | wdev->mesh_id_up_len = |
| 2517 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 2518 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 2519 | wdev->mesh_id_up_len); |
| 2520 | wdev_unlock(wdev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2521 | } |
| 2522 | |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2523 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
| 2524 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
| 2525 | change = true; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2526 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2527 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2528 | return err; |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2529 | } else { |
| 2530 | params.use_4addr = -1; |
| 2531 | } |
| 2532 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2533 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2534 | if (ntype != NL80211_IFTYPE_MONITOR) |
| 2535 | return -EINVAL; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2536 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
| 2537 | &_flags); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2538 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2539 | return err; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2540 | |
| 2541 | flags = &_flags; |
| 2542 | change = true; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2543 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2544 | |
Luciano Coelho | 1800329 | 2013-08-29 13:26:57 +0300 | [diff] [blame] | 2545 | if (flags && (*flags & MONITOR_FLAG_ACTIVE) && |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2546 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
| 2547 | return -EOPNOTSUPP; |
| 2548 | |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2549 | if (change) |
Johannes Berg | 3d54d25 | 2009-08-21 14:51:05 +0200 | [diff] [blame] | 2550 | err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2551 | else |
| 2552 | err = 0; |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 2553 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2554 | if (!err && params.use_4addr != -1) |
| 2555 | dev->ieee80211_ptr->use_4addr = params.use_4addr; |
| 2556 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2557 | return err; |
| 2558 | } |
| 2559 | |
| 2560 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) |
| 2561 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2562 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2563 | struct vif_params params; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2564 | struct wireless_dev *wdev; |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2565 | struct sk_buff *msg; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2566 | int err; |
| 2567 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2568 | u32 flags; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2569 | |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 2570 | /* to avoid failing a new interface creation due to pending removal */ |
| 2571 | cfg80211_destroy_ifaces(rdev); |
| 2572 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2573 | memset(¶ms, 0, sizeof(params)); |
| 2574 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2575 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
| 2576 | return -EINVAL; |
| 2577 | |
| 2578 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
| 2579 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
| 2580 | if (type > NL80211_IFTYPE_MAX) |
| 2581 | return -EINVAL; |
| 2582 | } |
| 2583 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2584 | if (!rdev->ops->add_virtual_intf || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2585 | !(rdev->wiphy.interface_modes & (1 << type))) |
| 2586 | return -EOPNOTSUPP; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2587 | |
Arend van Spriel | 1c18f14 | 2013-01-08 10:17:27 +0100 | [diff] [blame] | 2588 | if (type == NL80211_IFTYPE_P2P_DEVICE && info->attrs[NL80211_ATTR_MAC]) { |
| 2589 | nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC], |
| 2590 | ETH_ALEN); |
| 2591 | if (!is_valid_ether_addr(params.macaddr)) |
| 2592 | return -EADDRNOTAVAIL; |
| 2593 | } |
| 2594 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2595 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2596 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2597 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2598 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2599 | return err; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2600 | } |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2601 | |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2602 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 2603 | if (!msg) |
| 2604 | return -ENOMEM; |
| 2605 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2606 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
| 2607 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, |
| 2608 | &flags); |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2609 | |
Luciano Coelho | 1800329 | 2013-08-29 13:26:57 +0300 | [diff] [blame] | 2610 | if (!err && (flags & MONITOR_FLAG_ACTIVE) && |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2611 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
| 2612 | return -EOPNOTSUPP; |
| 2613 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2614 | wdev = rdev_add_virtual_intf(rdev, |
| 2615 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), |
| 2616 | type, err ? NULL : &flags, ¶ms); |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2617 | if (IS_ERR(wdev)) { |
| 2618 | nlmsg_free(msg); |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2619 | return PTR_ERR(wdev); |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2620 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2621 | |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 2622 | if (info->attrs[NL80211_ATTR_IFACE_SOCKET_OWNER]) |
| 2623 | wdev->owner_nlportid = info->snd_portid; |
| 2624 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2625 | switch (type) { |
| 2626 | case NL80211_IFTYPE_MESH_POINT: |
| 2627 | if (!info->attrs[NL80211_ATTR_MESH_ID]) |
| 2628 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2629 | wdev_lock(wdev); |
| 2630 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 2631 | IEEE80211_MAX_MESH_ID_LEN); |
| 2632 | wdev->mesh_id_up_len = |
| 2633 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 2634 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 2635 | wdev->mesh_id_up_len); |
| 2636 | wdev_unlock(wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2637 | break; |
| 2638 | case NL80211_IFTYPE_P2P_DEVICE: |
| 2639 | /* |
| 2640 | * P2P Device doesn't have a netdev, so doesn't go |
| 2641 | * through the netdev notifier and must be added here |
| 2642 | */ |
| 2643 | mutex_init(&wdev->mtx); |
| 2644 | INIT_LIST_HEAD(&wdev->event_list); |
| 2645 | spin_lock_init(&wdev->event_lock); |
| 2646 | INIT_LIST_HEAD(&wdev->mgmt_registrations); |
| 2647 | spin_lock_init(&wdev->mgmt_registrations_lock); |
| 2648 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2649 | wdev->identifier = ++rdev->wdev_id; |
| 2650 | list_add_rcu(&wdev->list, &rdev->wdev_list); |
| 2651 | rdev->devlist_generation++; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2652 | break; |
| 2653 | default: |
| 2654 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2655 | } |
| 2656 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2657 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2658 | rdev, wdev) < 0) { |
| 2659 | nlmsg_free(msg); |
| 2660 | return -ENOBUFS; |
| 2661 | } |
| 2662 | |
| 2663 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2664 | } |
| 2665 | |
| 2666 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) |
| 2667 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2668 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2669 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2670 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2671 | if (!rdev->ops->del_virtual_intf) |
| 2672 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2673 | |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2674 | /* |
| 2675 | * If we remove a wireless device without a netdev then clear |
| 2676 | * user_ptr[1] so that nl80211_post_doit won't dereference it |
| 2677 | * to check if it needs to do dev_put(). Otherwise it crashes |
| 2678 | * since the wdev has been freed, unlike with a netdev where |
| 2679 | * we need the dev_put() for the netdev to really be freed. |
| 2680 | */ |
| 2681 | if (!wdev->netdev) |
| 2682 | info->user_ptr[1] = NULL; |
| 2683 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2684 | return rdev_del_virtual_intf(rdev, wdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2685 | } |
| 2686 | |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 2687 | static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info) |
| 2688 | { |
| 2689 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2690 | struct net_device *dev = info->user_ptr[1]; |
| 2691 | u16 noack_map; |
| 2692 | |
| 2693 | if (!info->attrs[NL80211_ATTR_NOACK_MAP]) |
| 2694 | return -EINVAL; |
| 2695 | |
| 2696 | if (!rdev->ops->set_noack_map) |
| 2697 | return -EOPNOTSUPP; |
| 2698 | |
| 2699 | noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]); |
| 2700 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2701 | return rdev_set_noack_map(rdev, dev, noack_map); |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 2702 | } |
| 2703 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2704 | struct get_key_cookie { |
| 2705 | struct sk_buff *msg; |
| 2706 | int error; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2707 | int idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2708 | }; |
| 2709 | |
| 2710 | static void get_key_callback(void *c, struct key_params *params) |
| 2711 | { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2712 | struct nlattr *key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2713 | struct get_key_cookie *cookie = c; |
| 2714 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2715 | if ((params->key && |
| 2716 | nla_put(cookie->msg, NL80211_ATTR_KEY_DATA, |
| 2717 | params->key_len, params->key)) || |
| 2718 | (params->seq && |
| 2719 | nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ, |
| 2720 | params->seq_len, params->seq)) || |
| 2721 | (params->cipher && |
| 2722 | nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER, |
| 2723 | params->cipher))) |
| 2724 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2725 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2726 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
| 2727 | if (!key) |
| 2728 | goto nla_put_failure; |
| 2729 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2730 | if ((params->key && |
| 2731 | nla_put(cookie->msg, NL80211_KEY_DATA, |
| 2732 | params->key_len, params->key)) || |
| 2733 | (params->seq && |
| 2734 | nla_put(cookie->msg, NL80211_KEY_SEQ, |
| 2735 | params->seq_len, params->seq)) || |
| 2736 | (params->cipher && |
| 2737 | nla_put_u32(cookie->msg, NL80211_KEY_CIPHER, |
| 2738 | params->cipher))) |
| 2739 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2740 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2741 | if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx)) |
| 2742 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2743 | |
| 2744 | nla_nest_end(cookie->msg, key); |
| 2745 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2746 | return; |
| 2747 | nla_put_failure: |
| 2748 | cookie->error = 1; |
| 2749 | } |
| 2750 | |
| 2751 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) |
| 2752 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2753 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2754 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2755 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2756 | u8 key_idx = 0; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2757 | const u8 *mac_addr = NULL; |
| 2758 | bool pairwise; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2759 | struct get_key_cookie cookie = { |
| 2760 | .error = 0, |
| 2761 | }; |
| 2762 | void *hdr; |
| 2763 | struct sk_buff *msg; |
| 2764 | |
| 2765 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 2766 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 2767 | |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 2768 | if (key_idx > 5) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2769 | return -EINVAL; |
| 2770 | |
| 2771 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2772 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2773 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2774 | pairwise = !!mac_addr; |
| 2775 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 2776 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 2777 | if (kt >= NUM_NL80211_KEYTYPES) |
| 2778 | return -EINVAL; |
| 2779 | if (kt != NL80211_KEYTYPE_GROUP && |
| 2780 | kt != NL80211_KEYTYPE_PAIRWISE) |
| 2781 | return -EINVAL; |
| 2782 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; |
| 2783 | } |
| 2784 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2785 | if (!rdev->ops->get_key) |
| 2786 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2787 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2788 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2789 | if (!msg) |
| 2790 | return -ENOMEM; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2791 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2792 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2793 | NL80211_CMD_NEW_KEY); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 2794 | if (!hdr) |
Johannes Berg | 9fe271a | 2013-10-25 11:15:12 +0200 | [diff] [blame] | 2795 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2796 | |
| 2797 | cookie.msg = msg; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2798 | cookie.idx = key_idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2799 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2800 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 2801 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) |
| 2802 | goto nla_put_failure; |
| 2803 | if (mac_addr && |
| 2804 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 2805 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2806 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2807 | if (pairwise && mac_addr && |
| 2808 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 2809 | return -ENOENT; |
| 2810 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2811 | err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie, |
| 2812 | get_key_callback); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2813 | |
| 2814 | if (err) |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 2815 | goto free_msg; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2816 | |
| 2817 | if (cookie.error) |
| 2818 | goto nla_put_failure; |
| 2819 | |
| 2820 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2821 | return genlmsg_reply(msg, info); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2822 | |
| 2823 | nla_put_failure: |
| 2824 | err = -ENOBUFS; |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 2825 | free_msg: |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2826 | nlmsg_free(msg); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2827 | return err; |
| 2828 | } |
| 2829 | |
| 2830 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) |
| 2831 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2832 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2833 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2834 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2835 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2836 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2837 | err = nl80211_parse_key(info, &key); |
| 2838 | if (err) |
| 2839 | return err; |
| 2840 | |
| 2841 | if (key.idx < 0) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2842 | return -EINVAL; |
| 2843 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2844 | /* only support setting default key */ |
| 2845 | if (!key.def && !key.defmgmt) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2846 | return -EINVAL; |
| 2847 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2848 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2849 | |
| 2850 | if (key.def) { |
| 2851 | if (!rdev->ops->set_default_key) { |
| 2852 | err = -EOPNOTSUPP; |
| 2853 | goto out; |
| 2854 | } |
| 2855 | |
| 2856 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2857 | if (err) |
| 2858 | goto out; |
| 2859 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2860 | err = rdev_set_default_key(rdev, dev, key.idx, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2861 | key.def_uni, key.def_multi); |
| 2862 | |
| 2863 | if (err) |
| 2864 | goto out; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2865 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 2866 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2867 | dev->ieee80211_ptr->wext.default_key = key.idx; |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2868 | #endif |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2869 | } else { |
| 2870 | if (key.def_uni || !key.def_multi) { |
| 2871 | err = -EINVAL; |
| 2872 | goto out; |
| 2873 | } |
| 2874 | |
| 2875 | if (!rdev->ops->set_default_mgmt_key) { |
| 2876 | err = -EOPNOTSUPP; |
| 2877 | goto out; |
| 2878 | } |
| 2879 | |
| 2880 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2881 | if (err) |
| 2882 | goto out; |
| 2883 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2884 | err = rdev_set_default_mgmt_key(rdev, dev, key.idx); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2885 | if (err) |
| 2886 | goto out; |
| 2887 | |
| 2888 | #ifdef CONFIG_CFG80211_WEXT |
| 2889 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; |
| 2890 | #endif |
| 2891 | } |
| 2892 | |
| 2893 | out: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2894 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2895 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2896 | return err; |
| 2897 | } |
| 2898 | |
| 2899 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) |
| 2900 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2901 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2902 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2903 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2904 | struct key_parse key; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2905 | const u8 *mac_addr = NULL; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2906 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2907 | err = nl80211_parse_key(info, &key); |
| 2908 | if (err) |
| 2909 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2910 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2911 | if (!key.p.key) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2912 | return -EINVAL; |
| 2913 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2914 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2915 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2916 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2917 | if (key.type == -1) { |
| 2918 | if (mac_addr) |
| 2919 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 2920 | else |
| 2921 | key.type = NL80211_KEYTYPE_GROUP; |
| 2922 | } |
| 2923 | |
| 2924 | /* for now */ |
| 2925 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 2926 | key.type != NL80211_KEYTYPE_GROUP) |
| 2927 | return -EINVAL; |
| 2928 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2929 | if (!rdev->ops->add_key) |
| 2930 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2931 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2932 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
| 2933 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2934 | mac_addr)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2935 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2936 | |
| 2937 | wdev_lock(dev->ieee80211_ptr); |
| 2938 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2939 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2940 | err = rdev_add_key(rdev, dev, key.idx, |
| 2941 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2942 | mac_addr, &key.p); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2943 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2944 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2945 | return err; |
| 2946 | } |
| 2947 | |
| 2948 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) |
| 2949 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2950 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2951 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2952 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2953 | u8 *mac_addr = NULL; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2954 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2955 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2956 | err = nl80211_parse_key(info, &key); |
| 2957 | if (err) |
| 2958 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2959 | |
| 2960 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2961 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2962 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2963 | if (key.type == -1) { |
| 2964 | if (mac_addr) |
| 2965 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 2966 | else |
| 2967 | key.type = NL80211_KEYTYPE_GROUP; |
| 2968 | } |
| 2969 | |
| 2970 | /* for now */ |
| 2971 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 2972 | key.type != NL80211_KEYTYPE_GROUP) |
| 2973 | return -EINVAL; |
| 2974 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2975 | if (!rdev->ops->del_key) |
| 2976 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2977 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2978 | wdev_lock(dev->ieee80211_ptr); |
| 2979 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2980 | |
| 2981 | if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr && |
| 2982 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 2983 | err = -ENOENT; |
| 2984 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2985 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2986 | err = rdev_del_key(rdev, dev, key.idx, |
| 2987 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2988 | mac_addr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2989 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 2990 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2991 | if (!err) { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2992 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2993 | dev->ieee80211_ptr->wext.default_key = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2994 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2995 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
| 2996 | } |
| 2997 | #endif |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2998 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2999 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3000 | return err; |
| 3001 | } |
| 3002 | |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 3003 | /* This function returns an error or the number of nested attributes */ |
| 3004 | static int validate_acl_mac_addrs(struct nlattr *nl_attr) |
| 3005 | { |
| 3006 | struct nlattr *attr; |
| 3007 | int n_entries = 0, tmp; |
| 3008 | |
| 3009 | nla_for_each_nested(attr, nl_attr, tmp) { |
| 3010 | if (nla_len(attr) != ETH_ALEN) |
| 3011 | return -EINVAL; |
| 3012 | |
| 3013 | n_entries++; |
| 3014 | } |
| 3015 | |
| 3016 | return n_entries; |
| 3017 | } |
| 3018 | |
| 3019 | /* |
| 3020 | * This function parses ACL information and allocates memory for ACL data. |
| 3021 | * On successful return, the calling function is responsible to free the |
| 3022 | * ACL buffer returned by this function. |
| 3023 | */ |
| 3024 | static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy, |
| 3025 | struct genl_info *info) |
| 3026 | { |
| 3027 | enum nl80211_acl_policy acl_policy; |
| 3028 | struct nlattr *attr; |
| 3029 | struct cfg80211_acl_data *acl; |
| 3030 | int i = 0, n_entries, tmp; |
| 3031 | |
| 3032 | if (!wiphy->max_acl_mac_addrs) |
| 3033 | return ERR_PTR(-EOPNOTSUPP); |
| 3034 | |
| 3035 | if (!info->attrs[NL80211_ATTR_ACL_POLICY]) |
| 3036 | return ERR_PTR(-EINVAL); |
| 3037 | |
| 3038 | acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]); |
| 3039 | if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED && |
| 3040 | acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED) |
| 3041 | return ERR_PTR(-EINVAL); |
| 3042 | |
| 3043 | if (!info->attrs[NL80211_ATTR_MAC_ADDRS]) |
| 3044 | return ERR_PTR(-EINVAL); |
| 3045 | |
| 3046 | n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]); |
| 3047 | if (n_entries < 0) |
| 3048 | return ERR_PTR(n_entries); |
| 3049 | |
| 3050 | if (n_entries > wiphy->max_acl_mac_addrs) |
| 3051 | return ERR_PTR(-ENOTSUPP); |
| 3052 | |
| 3053 | acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries), |
| 3054 | GFP_KERNEL); |
| 3055 | if (!acl) |
| 3056 | return ERR_PTR(-ENOMEM); |
| 3057 | |
| 3058 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) { |
| 3059 | memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN); |
| 3060 | i++; |
| 3061 | } |
| 3062 | |
| 3063 | acl->n_acl_entries = n_entries; |
| 3064 | acl->acl_policy = acl_policy; |
| 3065 | |
| 3066 | return acl; |
| 3067 | } |
| 3068 | |
| 3069 | static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info) |
| 3070 | { |
| 3071 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3072 | struct net_device *dev = info->user_ptr[1]; |
| 3073 | struct cfg80211_acl_data *acl; |
| 3074 | int err; |
| 3075 | |
| 3076 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3077 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3078 | return -EOPNOTSUPP; |
| 3079 | |
| 3080 | if (!dev->ieee80211_ptr->beacon_interval) |
| 3081 | return -EINVAL; |
| 3082 | |
| 3083 | acl = parse_acl_data(&rdev->wiphy, info); |
| 3084 | if (IS_ERR(acl)) |
| 3085 | return PTR_ERR(acl); |
| 3086 | |
| 3087 | err = rdev_set_mac_acl(rdev, dev, acl); |
| 3088 | |
| 3089 | kfree(acl); |
| 3090 | |
| 3091 | return err; |
| 3092 | } |
| 3093 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3094 | static int nl80211_parse_beacon(struct nlattr *attrs[], |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3095 | struct cfg80211_beacon_data *bcn) |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3096 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3097 | bool haveinfo = false; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3098 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3099 | if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) || |
| 3100 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) || |
| 3101 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) || |
| 3102 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP])) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 3103 | return -EINVAL; |
| 3104 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3105 | memset(bcn, 0, sizeof(*bcn)); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3106 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3107 | if (attrs[NL80211_ATTR_BEACON_HEAD]) { |
| 3108 | bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]); |
| 3109 | bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3110 | if (!bcn->head_len) |
| 3111 | return -EINVAL; |
| 3112 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3113 | } |
| 3114 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3115 | if (attrs[NL80211_ATTR_BEACON_TAIL]) { |
| 3116 | bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]); |
| 3117 | bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3118 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3119 | } |
| 3120 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3121 | if (!haveinfo) |
| 3122 | return -EINVAL; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3123 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3124 | if (attrs[NL80211_ATTR_IE]) { |
| 3125 | bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]); |
| 3126 | bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 3127 | } |
| 3128 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3129 | if (attrs[NL80211_ATTR_IE_PROBE_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3130 | bcn->proberesp_ies = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3131 | nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3132 | bcn->proberesp_ies_len = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3133 | nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 3134 | } |
| 3135 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3136 | if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3137 | bcn->assocresp_ies = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3138 | nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3139 | bcn->assocresp_ies_len = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3140 | nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 3141 | } |
| 3142 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3143 | if (attrs[NL80211_ATTR_PROBE_RESP]) { |
| 3144 | bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]); |
| 3145 | bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]); |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 3146 | } |
| 3147 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3148 | return 0; |
| 3149 | } |
| 3150 | |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3151 | static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev, |
| 3152 | struct cfg80211_ap_settings *params) |
| 3153 | { |
| 3154 | struct wireless_dev *wdev; |
| 3155 | bool ret = false; |
| 3156 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 3157 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3158 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 3159 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 3160 | continue; |
| 3161 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3162 | if (!wdev->preset_chandef.chan) |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3163 | continue; |
| 3164 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3165 | params->chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3166 | ret = true; |
| 3167 | break; |
| 3168 | } |
| 3169 | |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3170 | return ret; |
| 3171 | } |
| 3172 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 3173 | static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev, |
| 3174 | enum nl80211_auth_type auth_type, |
| 3175 | enum nl80211_commands cmd) |
| 3176 | { |
| 3177 | if (auth_type > NL80211_AUTHTYPE_MAX) |
| 3178 | return false; |
| 3179 | |
| 3180 | switch (cmd) { |
| 3181 | case NL80211_CMD_AUTHENTICATE: |
| 3182 | if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && |
| 3183 | auth_type == NL80211_AUTHTYPE_SAE) |
| 3184 | return false; |
| 3185 | return true; |
| 3186 | case NL80211_CMD_CONNECT: |
| 3187 | case NL80211_CMD_START_AP: |
| 3188 | /* SAE not supported yet */ |
| 3189 | if (auth_type == NL80211_AUTHTYPE_SAE) |
| 3190 | return false; |
| 3191 | return true; |
| 3192 | default: |
| 3193 | return false; |
| 3194 | } |
| 3195 | } |
| 3196 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3197 | static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) |
| 3198 | { |
| 3199 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3200 | struct net_device *dev = info->user_ptr[1]; |
| 3201 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3202 | struct cfg80211_ap_settings params; |
| 3203 | int err; |
| 3204 | |
| 3205 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3206 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3207 | return -EOPNOTSUPP; |
| 3208 | |
| 3209 | if (!rdev->ops->start_ap) |
| 3210 | return -EOPNOTSUPP; |
| 3211 | |
| 3212 | if (wdev->beacon_interval) |
| 3213 | return -EALREADY; |
| 3214 | |
| 3215 | memset(¶ms, 0, sizeof(params)); |
| 3216 | |
| 3217 | /* these are required for START_AP */ |
| 3218 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || |
| 3219 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || |
| 3220 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) |
| 3221 | return -EINVAL; |
| 3222 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3223 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3224 | if (err) |
| 3225 | return err; |
| 3226 | |
| 3227 | params.beacon_interval = |
| 3228 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 3229 | params.dtim_period = |
| 3230 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 3231 | |
| 3232 | err = cfg80211_validate_beacon_int(rdev, params.beacon_interval); |
| 3233 | if (err) |
| 3234 | return err; |
| 3235 | |
| 3236 | /* |
| 3237 | * In theory, some of these attributes should be required here |
| 3238 | * but since they were not used when the command was originally |
| 3239 | * added, keep them optional for old user space programs to let |
| 3240 | * them continue to work with drivers that do not need the |
| 3241 | * additional information -- drivers must check! |
| 3242 | */ |
| 3243 | if (info->attrs[NL80211_ATTR_SSID]) { |
| 3244 | params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 3245 | params.ssid_len = |
| 3246 | nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 3247 | if (params.ssid_len == 0 || |
| 3248 | params.ssid_len > IEEE80211_MAX_SSID_LEN) |
| 3249 | return -EINVAL; |
| 3250 | } |
| 3251 | |
| 3252 | if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) { |
| 3253 | params.hidden_ssid = nla_get_u32( |
| 3254 | info->attrs[NL80211_ATTR_HIDDEN_SSID]); |
| 3255 | if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE && |
| 3256 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN && |
| 3257 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS) |
| 3258 | return -EINVAL; |
| 3259 | } |
| 3260 | |
| 3261 | params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
| 3262 | |
| 3263 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 3264 | params.auth_type = nla_get_u32( |
| 3265 | info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 3266 | if (!nl80211_valid_auth_type(rdev, params.auth_type, |
| 3267 | NL80211_CMD_START_AP)) |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3268 | return -EINVAL; |
| 3269 | } else |
| 3270 | params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 3271 | |
| 3272 | err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, |
| 3273 | NL80211_MAX_NR_CIPHER_SUITES); |
| 3274 | if (err) |
| 3275 | return err; |
| 3276 | |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 3277 | if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) { |
| 3278 | if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER)) |
| 3279 | return -EOPNOTSUPP; |
| 3280 | params.inactivity_timeout = nla_get_u16( |
| 3281 | info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]); |
| 3282 | } |
| 3283 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 3284 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 3285 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3286 | return -EINVAL; |
| 3287 | params.p2p_ctwindow = |
| 3288 | nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
| 3289 | if (params.p2p_ctwindow > 127) |
| 3290 | return -EINVAL; |
| 3291 | if (params.p2p_ctwindow != 0 && |
| 3292 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 3293 | return -EINVAL; |
| 3294 | } |
| 3295 | |
| 3296 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 3297 | u8 tmp; |
| 3298 | |
| 3299 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3300 | return -EINVAL; |
| 3301 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
| 3302 | if (tmp > 1) |
| 3303 | return -EINVAL; |
| 3304 | params.p2p_opp_ps = tmp; |
| 3305 | if (params.p2p_opp_ps != 0 && |
| 3306 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 3307 | return -EINVAL; |
| 3308 | } |
| 3309 | |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3310 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3311 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
| 3312 | if (err) |
| 3313 | return err; |
| 3314 | } else if (wdev->preset_chandef.chan) { |
| 3315 | params.chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3316 | } else if (!nl80211_get_ap_channel(rdev, ¶ms)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3317 | return -EINVAL; |
| 3318 | |
Ilan Peer | 174e0cd | 2014-02-23 09:13:01 +0200 | [diff] [blame] | 3319 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, ¶ms.chandef, |
| 3320 | wdev->iftype)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3321 | return -EINVAL; |
| 3322 | |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 3323 | if (info->attrs[NL80211_ATTR_ACL_POLICY]) { |
| 3324 | params.acl = parse_acl_data(&rdev->wiphy, info); |
| 3325 | if (IS_ERR(params.acl)) |
| 3326 | return PTR_ERR(params.acl); |
| 3327 | } |
| 3328 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 3329 | wdev_lock(wdev); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3330 | err = rdev_start_ap(rdev, dev, ¶ms); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3331 | if (!err) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3332 | wdev->preset_chandef = params.chandef; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3333 | wdev->beacon_interval = params.beacon_interval; |
Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 3334 | wdev->chandef = params.chandef; |
Antonio Quartulli | 06e191e | 2012-11-07 12:52:19 +0100 | [diff] [blame] | 3335 | wdev->ssid_len = params.ssid_len; |
| 3336 | memcpy(wdev->ssid, params.ssid, wdev->ssid_len); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3337 | } |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 3338 | wdev_unlock(wdev); |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 3339 | |
| 3340 | kfree(params.acl); |
| 3341 | |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 3342 | return err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3343 | } |
| 3344 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3345 | static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info) |
| 3346 | { |
| 3347 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3348 | struct net_device *dev = info->user_ptr[1]; |
| 3349 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3350 | struct cfg80211_beacon_data params; |
| 3351 | int err; |
| 3352 | |
| 3353 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3354 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3355 | return -EOPNOTSUPP; |
| 3356 | |
| 3357 | if (!rdev->ops->change_beacon) |
| 3358 | return -EOPNOTSUPP; |
| 3359 | |
| 3360 | if (!wdev->beacon_interval) |
| 3361 | return -EINVAL; |
| 3362 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3363 | err = nl80211_parse_beacon(info->attrs, ¶ms); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3364 | if (err) |
| 3365 | return err; |
| 3366 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 3367 | wdev_lock(wdev); |
| 3368 | err = rdev_change_beacon(rdev, dev, ¶ms); |
| 3369 | wdev_unlock(wdev); |
| 3370 | |
| 3371 | return err; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3372 | } |
| 3373 | |
| 3374 | 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] | 3375 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3376 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3377 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3378 | |
Ilan Peer | 7c8d5e0 | 2014-02-25 15:33:38 +0200 | [diff] [blame] | 3379 | return cfg80211_stop_ap(rdev, dev, false); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3380 | } |
| 3381 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3382 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
| 3383 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, |
| 3384 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, |
| 3385 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, |
Jouni Malinen | 0e46724 | 2009-05-11 21:57:55 +0300 | [diff] [blame] | 3386 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 3387 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
Johannes Berg | d83023d | 2011-12-14 09:29:15 +0100 | [diff] [blame] | 3388 | [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3389 | }; |
| 3390 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3391 | static int parse_station_flags(struct genl_info *info, |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3392 | enum nl80211_iftype iftype, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3393 | struct station_parameters *params) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3394 | { |
| 3395 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3396 | struct nlattr *nla; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3397 | int flag; |
| 3398 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3399 | /* |
| 3400 | * Try parsing the new attribute first so userspace |
| 3401 | * can specify both for older kernels. |
| 3402 | */ |
| 3403 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; |
| 3404 | if (nla) { |
| 3405 | struct nl80211_sta_flag_update *sta_flags; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3406 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3407 | sta_flags = nla_data(nla); |
| 3408 | params->sta_flags_mask = sta_flags->mask; |
| 3409 | params->sta_flags_set = sta_flags->set; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3410 | params->sta_flags_set &= params->sta_flags_mask; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3411 | if ((params->sta_flags_mask | |
| 3412 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) |
| 3413 | return -EINVAL; |
| 3414 | return 0; |
| 3415 | } |
| 3416 | |
| 3417 | /* if present, parse the old attribute */ |
| 3418 | |
| 3419 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3420 | if (!nla) |
| 3421 | return 0; |
| 3422 | |
| 3423 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, |
| 3424 | nla, sta_flags_policy)) |
| 3425 | return -EINVAL; |
| 3426 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3427 | /* |
| 3428 | * Only allow certain flags for interface types so that |
| 3429 | * other attributes are silently ignored. Remember that |
| 3430 | * this is backward compatibility code with old userspace |
| 3431 | * and shouldn't be hit in other cases anyway. |
| 3432 | */ |
| 3433 | switch (iftype) { |
| 3434 | case NL80211_IFTYPE_AP: |
| 3435 | case NL80211_IFTYPE_AP_VLAN: |
| 3436 | case NL80211_IFTYPE_P2P_GO: |
| 3437 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3438 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 3439 | BIT(NL80211_STA_FLAG_WME) | |
| 3440 | BIT(NL80211_STA_FLAG_MFP); |
| 3441 | break; |
| 3442 | case NL80211_IFTYPE_P2P_CLIENT: |
| 3443 | case NL80211_IFTYPE_STATION: |
| 3444 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3445 | BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3446 | break; |
| 3447 | case NL80211_IFTYPE_MESH_POINT: |
| 3448 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3449 | BIT(NL80211_STA_FLAG_MFP) | |
| 3450 | BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 3451 | default: |
| 3452 | return -EINVAL; |
| 3453 | } |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3454 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 3455 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) { |
| 3456 | if (flags[flag]) { |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3457 | params->sta_flags_set |= (1<<flag); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3458 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 3459 | /* no longer support new API additions in old API */ |
| 3460 | if (flag > NL80211_STA_FLAG_MAX_OLD_API) |
| 3461 | return -EINVAL; |
| 3462 | } |
| 3463 | } |
| 3464 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3465 | return 0; |
| 3466 | } |
| 3467 | |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3468 | static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, |
| 3469 | int attr) |
| 3470 | { |
| 3471 | struct nlattr *rate; |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 3472 | u32 bitrate; |
| 3473 | u16 bitrate_compat; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3474 | |
| 3475 | rate = nla_nest_start(msg, attr); |
| 3476 | if (!rate) |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 3477 | return false; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3478 | |
| 3479 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ |
| 3480 | bitrate = cfg80211_calculate_bitrate(info); |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 3481 | /* report 16-bit bitrate only if we can */ |
| 3482 | bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 3483 | if (bitrate > 0 && |
| 3484 | nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate)) |
| 3485 | return false; |
| 3486 | if (bitrate_compat > 0 && |
| 3487 | nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat)) |
| 3488 | return false; |
| 3489 | |
| 3490 | if (info->flags & RATE_INFO_FLAGS_MCS) { |
| 3491 | if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) |
| 3492 | return false; |
| 3493 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && |
| 3494 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) |
| 3495 | return false; |
| 3496 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 3497 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 3498 | return false; |
| 3499 | } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) { |
| 3500 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs)) |
| 3501 | return false; |
| 3502 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss)) |
| 3503 | return false; |
| 3504 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && |
| 3505 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) |
| 3506 | return false; |
| 3507 | if (info->flags & RATE_INFO_FLAGS_80_MHZ_WIDTH && |
| 3508 | nla_put_flag(msg, NL80211_RATE_INFO_80_MHZ_WIDTH)) |
| 3509 | return false; |
| 3510 | if (info->flags & RATE_INFO_FLAGS_80P80_MHZ_WIDTH && |
| 3511 | nla_put_flag(msg, NL80211_RATE_INFO_80P80_MHZ_WIDTH)) |
| 3512 | return false; |
| 3513 | if (info->flags & RATE_INFO_FLAGS_160_MHZ_WIDTH && |
| 3514 | nla_put_flag(msg, NL80211_RATE_INFO_160_MHZ_WIDTH)) |
| 3515 | return false; |
| 3516 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 3517 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 3518 | return false; |
| 3519 | } |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3520 | |
| 3521 | nla_nest_end(msg, rate); |
| 3522 | return true; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3523 | } |
| 3524 | |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 3525 | static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal, |
| 3526 | int id) |
| 3527 | { |
| 3528 | void *attr; |
| 3529 | int i = 0; |
| 3530 | |
| 3531 | if (!mask) |
| 3532 | return true; |
| 3533 | |
| 3534 | attr = nla_nest_start(msg, id); |
| 3535 | if (!attr) |
| 3536 | return false; |
| 3537 | |
| 3538 | for (i = 0; i < IEEE80211_MAX_CHAINS; i++) { |
| 3539 | if (!(mask & BIT(i))) |
| 3540 | continue; |
| 3541 | |
| 3542 | if (nla_put_u8(msg, i, signal[i])) |
| 3543 | return false; |
| 3544 | } |
| 3545 | |
| 3546 | nla_nest_end(msg, attr); |
| 3547 | |
| 3548 | return true; |
| 3549 | } |
| 3550 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3551 | 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] | 3552 | int flags, |
| 3553 | struct cfg80211_registered_device *rdev, |
| 3554 | struct net_device *dev, |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 3555 | const u8 *mac_addr, struct station_info *sinfo) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3556 | { |
| 3557 | void *hdr; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3558 | struct nlattr *sinfoattr, *bss_param; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3559 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3560 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3561 | if (!hdr) |
| 3562 | return -1; |
| 3563 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3564 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 3565 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 3566 | nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation)) |
| 3567 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 3568 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3569 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
| 3570 | if (!sinfoattr) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3571 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3572 | if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) && |
| 3573 | nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME, |
| 3574 | sinfo->connected_time)) |
| 3575 | goto nla_put_failure; |
| 3576 | if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) && |
| 3577 | nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME, |
| 3578 | sinfo->inactive_time)) |
| 3579 | goto nla_put_failure; |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3580 | if ((sinfo->filled & (STATION_INFO_RX_BYTES | |
| 3581 | STATION_INFO_RX_BYTES64)) && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3582 | nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES, |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3583 | (u32)sinfo->rx_bytes)) |
| 3584 | goto nla_put_failure; |
| 3585 | if ((sinfo->filled & (STATION_INFO_TX_BYTES | |
Felix Fietkau | 4325d72 | 2013-05-23 15:05:59 +0200 | [diff] [blame] | 3586 | STATION_INFO_TX_BYTES64)) && |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3587 | nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES, |
| 3588 | (u32)sinfo->tx_bytes)) |
| 3589 | goto nla_put_failure; |
| 3590 | if ((sinfo->filled & STATION_INFO_RX_BYTES64) && |
| 3591 | nla_put_u64(msg, NL80211_STA_INFO_RX_BYTES64, |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3592 | sinfo->rx_bytes)) |
| 3593 | goto nla_put_failure; |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3594 | if ((sinfo->filled & STATION_INFO_TX_BYTES64) && |
| 3595 | nla_put_u64(msg, NL80211_STA_INFO_TX_BYTES64, |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3596 | sinfo->tx_bytes)) |
| 3597 | goto nla_put_failure; |
| 3598 | if ((sinfo->filled & STATION_INFO_LLID) && |
| 3599 | nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid)) |
| 3600 | goto nla_put_failure; |
| 3601 | if ((sinfo->filled & STATION_INFO_PLID) && |
| 3602 | nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid)) |
| 3603 | goto nla_put_failure; |
| 3604 | if ((sinfo->filled & STATION_INFO_PLINK_STATE) && |
| 3605 | nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE, |
| 3606 | sinfo->plink_state)) |
| 3607 | goto nla_put_failure; |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3608 | switch (rdev->wiphy.signal_type) { |
| 3609 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3610 | if ((sinfo->filled & STATION_INFO_SIGNAL) && |
| 3611 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL, |
| 3612 | sinfo->signal)) |
| 3613 | goto nla_put_failure; |
| 3614 | if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) && |
| 3615 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG, |
| 3616 | sinfo->signal_avg)) |
| 3617 | goto nla_put_failure; |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3618 | break; |
| 3619 | default: |
| 3620 | break; |
| 3621 | } |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 3622 | if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL) { |
| 3623 | if (!nl80211_put_signal(msg, sinfo->chains, |
| 3624 | sinfo->chain_signal, |
| 3625 | NL80211_STA_INFO_CHAIN_SIGNAL)) |
| 3626 | goto nla_put_failure; |
| 3627 | } |
| 3628 | if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL_AVG) { |
| 3629 | if (!nl80211_put_signal(msg, sinfo->chains, |
| 3630 | sinfo->chain_signal_avg, |
| 3631 | NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) |
| 3632 | goto nla_put_failure; |
| 3633 | } |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3634 | if (sinfo->filled & STATION_INFO_TX_BITRATE) { |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3635 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
| 3636 | NL80211_STA_INFO_TX_BITRATE)) |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3637 | goto nla_put_failure; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3638 | } |
| 3639 | if (sinfo->filled & STATION_INFO_RX_BITRATE) { |
| 3640 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, |
| 3641 | NL80211_STA_INFO_RX_BITRATE)) |
| 3642 | goto nla_put_failure; |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3643 | } |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3644 | if ((sinfo->filled & STATION_INFO_RX_PACKETS) && |
| 3645 | nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS, |
| 3646 | sinfo->rx_packets)) |
| 3647 | goto nla_put_failure; |
| 3648 | if ((sinfo->filled & STATION_INFO_TX_PACKETS) && |
| 3649 | nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS, |
| 3650 | sinfo->tx_packets)) |
| 3651 | goto nla_put_failure; |
| 3652 | if ((sinfo->filled & STATION_INFO_TX_RETRIES) && |
| 3653 | nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES, |
| 3654 | sinfo->tx_retries)) |
| 3655 | goto nla_put_failure; |
| 3656 | if ((sinfo->filled & STATION_INFO_TX_FAILED) && |
| 3657 | nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED, |
| 3658 | sinfo->tx_failed)) |
| 3659 | goto nla_put_failure; |
Antonio Quartulli | 867d849 | 2014-05-19 21:53:19 +0200 | [diff] [blame] | 3660 | if ((sinfo->filled & STATION_INFO_EXPECTED_THROUGHPUT) && |
| 3661 | nla_put_u32(msg, NL80211_STA_INFO_EXPECTED_THROUGHPUT, |
| 3662 | sinfo->expected_throughput)) |
| 3663 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3664 | if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) && |
| 3665 | nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS, |
| 3666 | sinfo->beacon_loss_count)) |
| 3667 | goto nla_put_failure; |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 3668 | if ((sinfo->filled & STATION_INFO_LOCAL_PM) && |
| 3669 | nla_put_u32(msg, NL80211_STA_INFO_LOCAL_PM, |
| 3670 | sinfo->local_pm)) |
| 3671 | goto nla_put_failure; |
| 3672 | if ((sinfo->filled & STATION_INFO_PEER_PM) && |
| 3673 | nla_put_u32(msg, NL80211_STA_INFO_PEER_PM, |
| 3674 | sinfo->peer_pm)) |
| 3675 | goto nla_put_failure; |
| 3676 | if ((sinfo->filled & STATION_INFO_NONPEER_PM) && |
| 3677 | nla_put_u32(msg, NL80211_STA_INFO_NONPEER_PM, |
| 3678 | sinfo->nonpeer_pm)) |
| 3679 | goto nla_put_failure; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3680 | if (sinfo->filled & STATION_INFO_BSS_PARAM) { |
| 3681 | bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); |
| 3682 | if (!bss_param) |
| 3683 | goto nla_put_failure; |
| 3684 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3685 | if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) && |
| 3686 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) || |
| 3687 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) && |
| 3688 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) || |
| 3689 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) && |
| 3690 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) || |
| 3691 | nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, |
| 3692 | sinfo->bss_param.dtim_period) || |
| 3693 | nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, |
| 3694 | sinfo->bss_param.beacon_interval)) |
| 3695 | goto nla_put_failure; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3696 | |
| 3697 | nla_nest_end(msg, bss_param); |
| 3698 | } |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3699 | if ((sinfo->filled & STATION_INFO_STA_FLAGS) && |
| 3700 | nla_put(msg, NL80211_STA_INFO_STA_FLAGS, |
| 3701 | sizeof(struct nl80211_sta_flag_update), |
| 3702 | &sinfo->sta_flags)) |
| 3703 | goto nla_put_failure; |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 3704 | if ((sinfo->filled & STATION_INFO_T_OFFSET) && |
| 3705 | nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET, |
| 3706 | sinfo->t_offset)) |
| 3707 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3708 | nla_nest_end(msg, sinfoattr); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3709 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3710 | if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) && |
| 3711 | nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, |
| 3712 | sinfo->assoc_req_ies)) |
| 3713 | goto nla_put_failure; |
Jouni Malinen | 50d3dfb | 2011-08-08 12:11:52 +0300 | [diff] [blame] | 3714 | |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3715 | return genlmsg_end(msg, hdr); |
| 3716 | |
| 3717 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 3718 | genlmsg_cancel(msg, hdr); |
| 3719 | return -EMSGSIZE; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3720 | } |
| 3721 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3722 | static int nl80211_dump_station(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3723 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3724 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3725 | struct station_info sinfo; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 3726 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3727 | struct wireless_dev *wdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3728 | u8 mac_addr[ETH_ALEN]; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3729 | int sta_idx = cb->args[2]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3730 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3731 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 3732 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3733 | if (err) |
| 3734 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3735 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3736 | if (!wdev->netdev) { |
| 3737 | err = -EINVAL; |
| 3738 | goto out_err; |
| 3739 | } |
| 3740 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 3741 | if (!rdev->ops->dump_station) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3742 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3743 | goto out_err; |
| 3744 | } |
| 3745 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3746 | while (1) { |
Jouni Malinen | f612ced | 2011-08-11 11:46:22 +0300 | [diff] [blame] | 3747 | memset(&sinfo, 0, sizeof(sinfo)); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 3748 | err = rdev_dump_station(rdev, wdev->netdev, sta_idx, |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3749 | mac_addr, &sinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3750 | if (err == -ENOENT) |
| 3751 | break; |
| 3752 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3753 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3754 | |
| 3755 | if (nl80211_send_station(skb, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3756 | NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3757 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 3758 | rdev, wdev->netdev, mac_addr, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3759 | &sinfo) < 0) |
| 3760 | goto out; |
| 3761 | |
| 3762 | sta_idx++; |
| 3763 | } |
| 3764 | |
| 3765 | |
| 3766 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3767 | cb->args[2] = sta_idx; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3768 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3769 | out_err: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 3770 | nl80211_finish_wdev_dump(rdev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3771 | |
| 3772 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3773 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3774 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3775 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
| 3776 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3777 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3778 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3779 | struct station_info sinfo; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3780 | struct sk_buff *msg; |
| 3781 | u8 *mac_addr = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3782 | int err; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3783 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3784 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3785 | |
| 3786 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3787 | return -EINVAL; |
| 3788 | |
| 3789 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3790 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3791 | if (!rdev->ops->get_station) |
| 3792 | return -EOPNOTSUPP; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3793 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3794 | err = rdev_get_station(rdev, dev, mac_addr, &sinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3795 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3796 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3797 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3798 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3799 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3800 | return -ENOMEM; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3801 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3802 | 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] | 3803 | rdev, dev, mac_addr, &sinfo) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3804 | nlmsg_free(msg); |
| 3805 | return -ENOBUFS; |
| 3806 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3807 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3808 | return genlmsg_reply(msg, info); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3809 | } |
| 3810 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3811 | int cfg80211_check_station_change(struct wiphy *wiphy, |
| 3812 | struct station_parameters *params, |
| 3813 | enum cfg80211_station_type statype) |
| 3814 | { |
| 3815 | if (params->listen_interval != -1) |
| 3816 | return -EINVAL; |
Arik Nemtsov | c72e114 | 2014-07-17 17:14:29 +0300 | [diff] [blame] | 3817 | if (params->aid && |
| 3818 | !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3819 | return -EINVAL; |
| 3820 | |
| 3821 | /* When you run into this, adjust the code below for the new flag */ |
| 3822 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); |
| 3823 | |
| 3824 | switch (statype) { |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 3825 | case CFG80211_STA_MESH_PEER_KERNEL: |
| 3826 | case CFG80211_STA_MESH_PEER_USER: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3827 | /* |
| 3828 | * No ignoring the TDLS flag here -- the userspace mesh |
| 3829 | * code doesn't have the bug of including TDLS in the |
| 3830 | * mask everywhere. |
| 3831 | */ |
| 3832 | if (params->sta_flags_mask & |
| 3833 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3834 | BIT(NL80211_STA_FLAG_MFP) | |
| 3835 | BIT(NL80211_STA_FLAG_AUTHORIZED))) |
| 3836 | return -EINVAL; |
| 3837 | break; |
| 3838 | case CFG80211_STA_TDLS_PEER_SETUP: |
| 3839 | case CFG80211_STA_TDLS_PEER_ACTIVE: |
| 3840 | if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 3841 | return -EINVAL; |
| 3842 | /* ignore since it can't change */ |
| 3843 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3844 | break; |
| 3845 | default: |
| 3846 | /* disallow mesh-specific things */ |
| 3847 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) |
| 3848 | return -EINVAL; |
| 3849 | if (params->local_pm) |
| 3850 | return -EINVAL; |
| 3851 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
| 3852 | return -EINVAL; |
| 3853 | } |
| 3854 | |
| 3855 | if (statype != CFG80211_STA_TDLS_PEER_SETUP && |
| 3856 | statype != CFG80211_STA_TDLS_PEER_ACTIVE) { |
| 3857 | /* TDLS can't be set, ... */ |
| 3858 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
| 3859 | return -EINVAL; |
| 3860 | /* |
| 3861 | * ... but don't bother the driver with it. This works around |
| 3862 | * a hostapd/wpa_supplicant issue -- it always includes the |
| 3863 | * TLDS_PEER flag in the mask even for AP mode. |
| 3864 | */ |
| 3865 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3866 | } |
| 3867 | |
| 3868 | if (statype != CFG80211_STA_TDLS_PEER_SETUP) { |
| 3869 | /* reject other things that can't change */ |
| 3870 | if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) |
| 3871 | return -EINVAL; |
| 3872 | if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY) |
| 3873 | return -EINVAL; |
| 3874 | if (params->supported_rates) |
| 3875 | return -EINVAL; |
| 3876 | if (params->ext_capab || params->ht_capa || params->vht_capa) |
| 3877 | return -EINVAL; |
| 3878 | } |
| 3879 | |
| 3880 | if (statype != CFG80211_STA_AP_CLIENT) { |
| 3881 | if (params->vlan) |
| 3882 | return -EINVAL; |
| 3883 | } |
| 3884 | |
| 3885 | switch (statype) { |
| 3886 | case CFG80211_STA_AP_MLME_CLIENT: |
| 3887 | /* Use this only for authorizing/unauthorizing a station */ |
| 3888 | if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))) |
| 3889 | return -EOPNOTSUPP; |
| 3890 | break; |
| 3891 | case CFG80211_STA_AP_CLIENT: |
| 3892 | /* accept only the listed bits */ |
| 3893 | if (params->sta_flags_mask & |
| 3894 | ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3895 | BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3896 | BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 3897 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 3898 | BIT(NL80211_STA_FLAG_WME) | |
| 3899 | BIT(NL80211_STA_FLAG_MFP))) |
| 3900 | return -EINVAL; |
| 3901 | |
| 3902 | /* but authenticated/associated only if driver handles it */ |
| 3903 | if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
| 3904 | params->sta_flags_mask & |
| 3905 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3906 | BIT(NL80211_STA_FLAG_ASSOCIATED))) |
| 3907 | return -EINVAL; |
| 3908 | break; |
| 3909 | case CFG80211_STA_IBSS: |
| 3910 | case CFG80211_STA_AP_STA: |
| 3911 | /* reject any changes other than AUTHORIZED */ |
| 3912 | if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) |
| 3913 | return -EINVAL; |
| 3914 | break; |
| 3915 | case CFG80211_STA_TDLS_PEER_SETUP: |
| 3916 | /* reject any changes other than AUTHORIZED or WME */ |
| 3917 | if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3918 | BIT(NL80211_STA_FLAG_WME))) |
| 3919 | return -EINVAL; |
| 3920 | /* force (at least) rates when authorizing */ |
| 3921 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) && |
| 3922 | !params->supported_rates) |
| 3923 | return -EINVAL; |
| 3924 | break; |
| 3925 | case CFG80211_STA_TDLS_PEER_ACTIVE: |
| 3926 | /* reject any changes */ |
| 3927 | return -EINVAL; |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 3928 | case CFG80211_STA_MESH_PEER_KERNEL: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3929 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
| 3930 | return -EINVAL; |
| 3931 | break; |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 3932 | case CFG80211_STA_MESH_PEER_USER: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3933 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) |
| 3934 | return -EINVAL; |
| 3935 | break; |
| 3936 | } |
| 3937 | |
| 3938 | return 0; |
| 3939 | } |
| 3940 | EXPORT_SYMBOL(cfg80211_check_station_change); |
| 3941 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3942 | /* |
Felix Fietkau | c258d2d | 2009-11-11 17:23:31 +0100 | [diff] [blame] | 3943 | * 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] | 3944 | */ |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3945 | static struct net_device *get_vlan(struct genl_info *info, |
| 3946 | struct cfg80211_registered_device *rdev) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3947 | { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3948 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3949 | struct net_device *v; |
| 3950 | int ret; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3951 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3952 | if (!vlanattr) |
| 3953 | return NULL; |
| 3954 | |
| 3955 | v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); |
| 3956 | if (!v) |
| 3957 | return ERR_PTR(-ENODEV); |
| 3958 | |
| 3959 | if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { |
| 3960 | ret = -EINVAL; |
| 3961 | goto error; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3962 | } |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3963 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3964 | if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
| 3965 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3966 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { |
| 3967 | ret = -EINVAL; |
| 3968 | goto error; |
| 3969 | } |
| 3970 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3971 | if (!netif_running(v)) { |
| 3972 | ret = -ENETDOWN; |
| 3973 | goto error; |
| 3974 | } |
| 3975 | |
| 3976 | return v; |
| 3977 | error: |
| 3978 | dev_put(v); |
| 3979 | return ERR_PTR(ret); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3980 | } |
| 3981 | |
Johannes Berg | 94e860f | 2014-01-20 23:58:15 +0100 | [diff] [blame] | 3982 | static const struct nla_policy |
| 3983 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = { |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3984 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, |
| 3985 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, |
| 3986 | }; |
| 3987 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 3988 | static int nl80211_parse_sta_wme(struct genl_info *info, |
| 3989 | struct station_parameters *params) |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3990 | { |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3991 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; |
| 3992 | struct nlattr *nla; |
| 3993 | int err; |
| 3994 | |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3995 | /* parse WME attributes if present */ |
| 3996 | if (!info->attrs[NL80211_ATTR_STA_WME]) |
| 3997 | return 0; |
| 3998 | |
| 3999 | nla = info->attrs[NL80211_ATTR_STA_WME]; |
| 4000 | err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla, |
| 4001 | nl80211_sta_wme_policy); |
| 4002 | if (err) |
| 4003 | return err; |
| 4004 | |
| 4005 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) |
| 4006 | params->uapsd_queues = nla_get_u8( |
| 4007 | tb[NL80211_STA_WME_UAPSD_QUEUES]); |
| 4008 | if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) |
| 4009 | return -EINVAL; |
| 4010 | |
| 4011 | if (tb[NL80211_STA_WME_MAX_SP]) |
| 4012 | params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); |
| 4013 | |
| 4014 | if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) |
| 4015 | return -EINVAL; |
| 4016 | |
| 4017 | params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; |
| 4018 | |
| 4019 | return 0; |
| 4020 | } |
| 4021 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 4022 | static int nl80211_parse_sta_channel_info(struct genl_info *info, |
| 4023 | struct station_parameters *params) |
| 4024 | { |
| 4025 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) { |
| 4026 | params->supported_channels = |
| 4027 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); |
| 4028 | params->supported_channels_len = |
| 4029 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); |
| 4030 | /* |
| 4031 | * Need to include at least one (first channel, number of |
| 4032 | * channels) tuple for each subband, and must have proper |
| 4033 | * tuples for the rest of the data as well. |
| 4034 | */ |
| 4035 | if (params->supported_channels_len < 2) |
| 4036 | return -EINVAL; |
| 4037 | if (params->supported_channels_len % 2) |
| 4038 | return -EINVAL; |
| 4039 | } |
| 4040 | |
| 4041 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) { |
| 4042 | params->supported_oper_classes = |
| 4043 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); |
| 4044 | params->supported_oper_classes_len = |
| 4045 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); |
| 4046 | /* |
| 4047 | * The value of the Length field of the Supported Operating |
| 4048 | * Classes element is between 2 and 253. |
| 4049 | */ |
| 4050 | if (params->supported_oper_classes_len < 2 || |
| 4051 | params->supported_oper_classes_len > 253) |
| 4052 | return -EINVAL; |
| 4053 | } |
| 4054 | return 0; |
| 4055 | } |
| 4056 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4057 | static int nl80211_set_station_tdls(struct genl_info *info, |
| 4058 | struct station_parameters *params) |
| 4059 | { |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 4060 | int err; |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4061 | /* Dummy STA entry gets updated once the peer capabilities are known */ |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 4062 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
| 4063 | params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4064 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 4065 | params->ht_capa = |
| 4066 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
| 4067 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 4068 | params->vht_capa = |
| 4069 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 4070 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 4071 | err = nl80211_parse_sta_channel_info(info, params); |
| 4072 | if (err) |
| 4073 | return err; |
| 4074 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4075 | return nl80211_parse_sta_wme(info, params); |
| 4076 | } |
| 4077 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4078 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
| 4079 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4080 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4081 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4082 | struct station_parameters params; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4083 | u8 *mac_addr; |
| 4084 | int err; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4085 | |
| 4086 | memset(¶ms, 0, sizeof(params)); |
| 4087 | |
| 4088 | params.listen_interval = -1; |
| 4089 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4090 | if (!rdev->ops->change_station) |
| 4091 | return -EOPNOTSUPP; |
| 4092 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4093 | if (info->attrs[NL80211_ATTR_STA_AID]) |
| 4094 | return -EINVAL; |
| 4095 | |
| 4096 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4097 | return -EINVAL; |
| 4098 | |
| 4099 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4100 | |
| 4101 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { |
| 4102 | params.supported_rates = |
| 4103 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4104 | params.supported_rates_len = |
| 4105 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4106 | } |
| 4107 | |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 4108 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
| 4109 | params.capability = |
| 4110 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); |
| 4111 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; |
| 4112 | } |
| 4113 | |
| 4114 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { |
| 4115 | params.ext_capab = |
| 4116 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4117 | params.ext_capab_len = |
| 4118 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4119 | } |
| 4120 | |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 4121 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
Johannes Berg | ba23d20 | 2012-12-27 17:32:09 +0100 | [diff] [blame] | 4122 | return -EINVAL; |
Jouni Malinen | 36aedc90 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 4123 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 4124 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4125 | return -EINVAL; |
| 4126 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4127 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4128 | params.plink_action = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4129 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 4130 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) |
| 4131 | return -EINVAL; |
| 4132 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4133 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4134 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) { |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 4135 | params.plink_state = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4136 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
| 4137 | if (params.plink_state >= NUM_NL80211_PLINK_STATES) |
| 4138 | return -EINVAL; |
| 4139 | params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE; |
| 4140 | } |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 4141 | |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4142 | if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) { |
| 4143 | enum nl80211_mesh_power_mode pm = nla_get_u32( |
| 4144 | info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]); |
| 4145 | |
| 4146 | if (pm <= NL80211_MESH_POWER_UNKNOWN || |
| 4147 | pm > NL80211_MESH_POWER_MAX) |
| 4148 | return -EINVAL; |
| 4149 | |
| 4150 | params.local_pm = pm; |
| 4151 | } |
| 4152 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4153 | /* Include parameters for TDLS peer (will check later) */ |
| 4154 | err = nl80211_set_station_tdls(info, ¶ms); |
| 4155 | if (err) |
| 4156 | return err; |
| 4157 | |
| 4158 | params.vlan = get_vlan(info, rdev); |
| 4159 | if (IS_ERR(params.vlan)) |
| 4160 | return PTR_ERR(params.vlan); |
| 4161 | |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4162 | switch (dev->ieee80211_ptr->iftype) { |
| 4163 | case NL80211_IFTYPE_AP: |
| 4164 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4165 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4166 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4167 | case NL80211_IFTYPE_STATION: |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 4168 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4169 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4170 | break; |
| 4171 | default: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4172 | err = -EOPNOTSUPP; |
| 4173 | goto out_put_vlan; |
Johannes Berg | 034d655 | 2009-05-27 10:35:29 +0200 | [diff] [blame] | 4174 | } |
| 4175 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4176 | /* driver will call cfg80211_check_station_change() */ |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4177 | err = rdev_change_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4178 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4179 | out_put_vlan: |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4180 | if (params.vlan) |
| 4181 | dev_put(params.vlan); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4182 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4183 | return err; |
| 4184 | } |
| 4185 | |
| 4186 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) |
| 4187 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4188 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4189 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4190 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4191 | struct station_parameters params; |
| 4192 | u8 *mac_addr = NULL; |
| 4193 | |
| 4194 | memset(¶ms, 0, sizeof(params)); |
| 4195 | |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4196 | if (!rdev->ops->add_station) |
| 4197 | return -EOPNOTSUPP; |
| 4198 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4199 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4200 | return -EINVAL; |
| 4201 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4202 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 4203 | return -EINVAL; |
| 4204 | |
| 4205 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) |
| 4206 | return -EINVAL; |
| 4207 | |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 4208 | if (!info->attrs[NL80211_ATTR_STA_AID] && |
| 4209 | !info->attrs[NL80211_ATTR_PEER_AID]) |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 4210 | return -EINVAL; |
| 4211 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4212 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4213 | params.supported_rates = |
| 4214 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4215 | params.supported_rates_len = |
| 4216 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4217 | params.listen_interval = |
| 4218 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 4219 | |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4220 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 4221 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4222 | else |
| 4223 | 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] | 4224 | if (!params.aid || params.aid > IEEE80211_MAX_AID) |
| 4225 | return -EINVAL; |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 4226 | |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 4227 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
| 4228 | params.capability = |
| 4229 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); |
| 4230 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; |
| 4231 | } |
| 4232 | |
| 4233 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { |
| 4234 | params.ext_capab = |
| 4235 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4236 | params.ext_capab_len = |
| 4237 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4238 | } |
| 4239 | |
Jouni Malinen | 36aedc90 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 4240 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 4241 | params.ht_capa = |
| 4242 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4243 | |
Mahesh Palivela | f461be3e | 2012-10-11 08:04:52 +0000 | [diff] [blame] | 4244 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 4245 | params.vht_capa = |
| 4246 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 4247 | |
Marek Kwaczynski | 60f4a7b | 2013-12-03 10:04:59 +0100 | [diff] [blame] | 4248 | if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) { |
| 4249 | params.opmode_notif_used = true; |
| 4250 | params.opmode_notif = |
| 4251 | nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]); |
| 4252 | } |
| 4253 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4254 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 4255 | params.plink_action = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4256 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 4257 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) |
| 4258 | return -EINVAL; |
| 4259 | } |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 4260 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 4261 | err = nl80211_parse_sta_channel_info(info, ¶ms); |
| 4262 | if (err) |
| 4263 | return err; |
| 4264 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4265 | err = nl80211_parse_sta_wme(info, ¶ms); |
| 4266 | if (err) |
| 4267 | return err; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4268 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 4269 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4270 | return -EINVAL; |
| 4271 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4272 | /* When you run into this, adjust the code below for the new flag */ |
| 4273 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); |
| 4274 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4275 | switch (dev->ieee80211_ptr->iftype) { |
| 4276 | case NL80211_IFTYPE_AP: |
| 4277 | case NL80211_IFTYPE_AP_VLAN: |
| 4278 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4279 | /* ignore WME attributes if iface/sta is not capable */ |
| 4280 | if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) || |
| 4281 | !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) |
| 4282 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4283 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4284 | /* TDLS peers cannot be added */ |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4285 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
| 4286 | info->attrs[NL80211_ATTR_PEER_AID]) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 4287 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4288 | /* but don't bother the driver with it */ |
| 4289 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4290 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4291 | /* allow authenticated/associated only if driver handles it */ |
| 4292 | if (!(rdev->wiphy.features & |
| 4293 | NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
| 4294 | params.sta_flags_mask & |
| 4295 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 4296 | BIT(NL80211_STA_FLAG_ASSOCIATED))) |
| 4297 | return -EINVAL; |
| 4298 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4299 | /* must be last in here for error handling */ |
| 4300 | params.vlan = get_vlan(info, rdev); |
| 4301 | if (IS_ERR(params.vlan)) |
| 4302 | return PTR_ERR(params.vlan); |
| 4303 | break; |
| 4304 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4305 | /* ignore uAPSD data */ |
| 4306 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
| 4307 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4308 | /* associated is disallowed */ |
| 4309 | if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) |
| 4310 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4311 | /* TDLS peers cannot be added */ |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4312 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
| 4313 | info->attrs[NL80211_ATTR_PEER_AID]) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 4314 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4315 | break; |
| 4316 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 93d08f0 | 2013-03-04 09:29:46 +0100 | [diff] [blame] | 4317 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4318 | /* ignore uAPSD data */ |
| 4319 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
| 4320 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4321 | /* these are disallowed */ |
| 4322 | if (params.sta_flags_mask & |
| 4323 | (BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 4324 | BIT(NL80211_STA_FLAG_AUTHENTICATED))) |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4325 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4326 | /* Only TDLS peers can be added */ |
| 4327 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 4328 | return -EINVAL; |
| 4329 | /* Can only add if TDLS ... */ |
| 4330 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) |
| 4331 | return -EOPNOTSUPP; |
| 4332 | /* ... with external setup is supported */ |
| 4333 | if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) |
| 4334 | return -EOPNOTSUPP; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4335 | /* |
| 4336 | * Older wpa_supplicant versions always mark the TDLS peer |
| 4337 | * as authorized, but it shouldn't yet be. |
| 4338 | */ |
| 4339 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED); |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4340 | break; |
| 4341 | default: |
| 4342 | return -EOPNOTSUPP; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4343 | } |
| 4344 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4345 | /* be aware of params.vlan when changing code here */ |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4346 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4347 | err = rdev_add_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4348 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4349 | if (params.vlan) |
| 4350 | dev_put(params.vlan); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4351 | return err; |
| 4352 | } |
| 4353 | |
| 4354 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) |
| 4355 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4356 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4357 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4358 | u8 *mac_addr = NULL; |
| 4359 | |
| 4360 | if (info->attrs[NL80211_ATTR_MAC]) |
| 4361 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4362 | |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 4363 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Marco Porsch | d5d9de0 | 2010-03-30 10:00:16 +0200 | [diff] [blame] | 4364 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4365 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4366 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4367 | return -EINVAL; |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 4368 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4369 | if (!rdev->ops->del_station) |
| 4370 | return -EOPNOTSUPP; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4371 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4372 | return rdev_del_station(rdev, dev, mac_addr); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4373 | } |
| 4374 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4375 | 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] | 4376 | int flags, struct net_device *dev, |
| 4377 | u8 *dst, u8 *next_hop, |
| 4378 | struct mpath_info *pinfo) |
| 4379 | { |
| 4380 | void *hdr; |
| 4381 | struct nlattr *pinfoattr; |
| 4382 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4383 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4384 | if (!hdr) |
| 4385 | return -1; |
| 4386 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4387 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 4388 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || |
| 4389 | nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) || |
| 4390 | nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation)) |
| 4391 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 4392 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4393 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
| 4394 | if (!pinfoattr) |
| 4395 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4396 | if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) && |
| 4397 | nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN, |
| 4398 | pinfo->frame_qlen)) |
| 4399 | goto nla_put_failure; |
| 4400 | if (((pinfo->filled & MPATH_INFO_SN) && |
| 4401 | nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) || |
| 4402 | ((pinfo->filled & MPATH_INFO_METRIC) && |
| 4403 | nla_put_u32(msg, NL80211_MPATH_INFO_METRIC, |
| 4404 | pinfo->metric)) || |
| 4405 | ((pinfo->filled & MPATH_INFO_EXPTIME) && |
| 4406 | nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME, |
| 4407 | pinfo->exptime)) || |
| 4408 | ((pinfo->filled & MPATH_INFO_FLAGS) && |
| 4409 | nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS, |
| 4410 | pinfo->flags)) || |
| 4411 | ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) && |
| 4412 | nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, |
| 4413 | pinfo->discovery_timeout)) || |
| 4414 | ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) && |
| 4415 | nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, |
| 4416 | pinfo->discovery_retries))) |
| 4417 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4418 | |
| 4419 | nla_nest_end(msg, pinfoattr); |
| 4420 | |
| 4421 | return genlmsg_end(msg, hdr); |
| 4422 | |
| 4423 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 4424 | genlmsg_cancel(msg, hdr); |
| 4425 | return -EMSGSIZE; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4426 | } |
| 4427 | |
| 4428 | static int nl80211_dump_mpath(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4429 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4430 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4431 | struct mpath_info pinfo; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4432 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4433 | struct wireless_dev *wdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4434 | u8 dst[ETH_ALEN]; |
| 4435 | u8 next_hop[ETH_ALEN]; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4436 | int path_idx = cb->args[2]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4437 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4438 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4439 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4440 | if (err) |
| 4441 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4442 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4443 | if (!rdev->ops->dump_mpath) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4444 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4445 | goto out_err; |
| 4446 | } |
| 4447 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4448 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4449 | err = -EOPNOTSUPP; |
Roel Kluin | 0448b5f | 2009-08-22 21:15:49 +0200 | [diff] [blame] | 4450 | goto out_err; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4451 | } |
| 4452 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4453 | while (1) { |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4454 | err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4455 | next_hop, &pinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4456 | if (err == -ENOENT) |
| 4457 | break; |
| 4458 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4459 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4460 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4461 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4462 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4463 | wdev->netdev, dst, next_hop, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4464 | &pinfo) < 0) |
| 4465 | goto out; |
| 4466 | |
| 4467 | path_idx++; |
| 4468 | } |
| 4469 | |
| 4470 | |
| 4471 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4472 | cb->args[2] = path_idx; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4473 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4474 | out_err: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4475 | nl80211_finish_wdev_dump(rdev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4476 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4477 | } |
| 4478 | |
| 4479 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4480 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4481 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4482 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4483 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4484 | struct mpath_info pinfo; |
| 4485 | struct sk_buff *msg; |
| 4486 | u8 *dst = NULL; |
| 4487 | u8 next_hop[ETH_ALEN]; |
| 4488 | |
| 4489 | memset(&pinfo, 0, sizeof(pinfo)); |
| 4490 | |
| 4491 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4492 | return -EINVAL; |
| 4493 | |
| 4494 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4495 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4496 | if (!rdev->ops->get_mpath) |
| 4497 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4498 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4499 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4500 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4501 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4502 | err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4503 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4504 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4505 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4506 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4507 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4508 | return -ENOMEM; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4509 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4510 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4511 | dev, dst, next_hop, &pinfo) < 0) { |
| 4512 | nlmsg_free(msg); |
| 4513 | return -ENOBUFS; |
| 4514 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4515 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4516 | return genlmsg_reply(msg, info); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4517 | } |
| 4518 | |
| 4519 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4520 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4521 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4522 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4523 | u8 *dst = NULL; |
| 4524 | u8 *next_hop = NULL; |
| 4525 | |
| 4526 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4527 | return -EINVAL; |
| 4528 | |
| 4529 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 4530 | return -EINVAL; |
| 4531 | |
| 4532 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4533 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 4534 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4535 | if (!rdev->ops->change_mpath) |
| 4536 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4537 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4538 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4539 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4540 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4541 | return rdev_change_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4542 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4543 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4544 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4545 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4546 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4547 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4548 | u8 *dst = NULL; |
| 4549 | u8 *next_hop = NULL; |
| 4550 | |
| 4551 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4552 | return -EINVAL; |
| 4553 | |
| 4554 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 4555 | return -EINVAL; |
| 4556 | |
| 4557 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4558 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 4559 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4560 | if (!rdev->ops->add_mpath) |
| 4561 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4562 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4563 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4564 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4565 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4566 | return rdev_add_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4567 | } |
| 4568 | |
| 4569 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4570 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4571 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4572 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4573 | u8 *dst = NULL; |
| 4574 | |
| 4575 | if (info->attrs[NL80211_ATTR_MAC]) |
| 4576 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4577 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4578 | if (!rdev->ops->del_mpath) |
| 4579 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4580 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4581 | return rdev_del_mpath(rdev, dev, dst); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4582 | } |
| 4583 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4584 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
| 4585 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4586 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4587 | struct net_device *dev = info->user_ptr[1]; |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 4588 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4589 | struct bss_parameters params; |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 4590 | int err; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4591 | |
| 4592 | memset(¶ms, 0, sizeof(params)); |
| 4593 | /* default to not changing parameters */ |
| 4594 | params.use_cts_prot = -1; |
| 4595 | params.use_short_preamble = -1; |
| 4596 | params.use_short_slot_time = -1; |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 4597 | params.ap_isolate = -1; |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 4598 | params.ht_opmode = -1; |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 4599 | params.p2p_ctwindow = -1; |
| 4600 | params.p2p_opp_ps = -1; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4601 | |
| 4602 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) |
| 4603 | params.use_cts_prot = |
| 4604 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); |
| 4605 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) |
| 4606 | params.use_short_preamble = |
| 4607 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); |
| 4608 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) |
| 4609 | params.use_short_slot_time = |
| 4610 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 4611 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 4612 | params.basic_rates = |
| 4613 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 4614 | params.basic_rates_len = |
| 4615 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 4616 | } |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 4617 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
| 4618 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 4619 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
| 4620 | params.ht_opmode = |
| 4621 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4622 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 4623 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 4624 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4625 | return -EINVAL; |
| 4626 | params.p2p_ctwindow = |
| 4627 | nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
| 4628 | if (params.p2p_ctwindow < 0) |
| 4629 | return -EINVAL; |
| 4630 | if (params.p2p_ctwindow != 0 && |
| 4631 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 4632 | return -EINVAL; |
| 4633 | } |
| 4634 | |
| 4635 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 4636 | u8 tmp; |
| 4637 | |
| 4638 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4639 | return -EINVAL; |
| 4640 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
| 4641 | if (tmp > 1) |
| 4642 | return -EINVAL; |
| 4643 | params.p2p_opp_ps = tmp; |
| 4644 | if (params.p2p_opp_ps && |
| 4645 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 4646 | return -EINVAL; |
| 4647 | } |
| 4648 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4649 | if (!rdev->ops->change_bss) |
| 4650 | return -EOPNOTSUPP; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4651 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4652 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4653 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4654 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4655 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 4656 | wdev_lock(wdev); |
| 4657 | err = rdev_change_bss(rdev, dev, ¶ms); |
| 4658 | wdev_unlock(wdev); |
| 4659 | |
| 4660 | return err; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4661 | } |
| 4662 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 4663 | 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] | 4664 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
| 4665 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, |
| 4666 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, |
| 4667 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, |
| 4668 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, |
| 4669 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, |
Janusz Dziedzic | 089027e | 2014-02-21 19:46:12 +0100 | [diff] [blame] | 4670 | [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 }, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4671 | }; |
| 4672 | |
| 4673 | static int parse_reg_rule(struct nlattr *tb[], |
| 4674 | struct ieee80211_reg_rule *reg_rule) |
| 4675 | { |
| 4676 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; |
| 4677 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; |
| 4678 | |
| 4679 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) |
| 4680 | return -EINVAL; |
| 4681 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) |
| 4682 | return -EINVAL; |
| 4683 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) |
| 4684 | return -EINVAL; |
Janusz Dziedzic | b0dfd2e | 2014-02-20 13:52:16 +0100 | [diff] [blame] | 4685 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) |
| 4686 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4687 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) |
| 4688 | return -EINVAL; |
| 4689 | |
| 4690 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); |
| 4691 | |
| 4692 | freq_range->start_freq_khz = |
| 4693 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); |
| 4694 | freq_range->end_freq_khz = |
| 4695 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); |
Janusz Dziedzic | b0dfd2e | 2014-02-20 13:52:16 +0100 | [diff] [blame] | 4696 | freq_range->max_bandwidth_khz = |
| 4697 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4698 | |
| 4699 | power_rule->max_eirp = |
| 4700 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); |
| 4701 | |
| 4702 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) |
| 4703 | power_rule->max_antenna_gain = |
| 4704 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); |
| 4705 | |
Janusz Dziedzic | 089027e | 2014-02-21 19:46:12 +0100 | [diff] [blame] | 4706 | if (tb[NL80211_ATTR_DFS_CAC_TIME]) |
| 4707 | reg_rule->dfs_cac_ms = |
| 4708 | nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]); |
| 4709 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4710 | return 0; |
| 4711 | } |
| 4712 | |
| 4713 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 4714 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4715 | char *data = NULL; |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4716 | enum nl80211_user_reg_hint_type user_reg_hint_type; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4717 | |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 4718 | /* |
| 4719 | * You should only get this when cfg80211 hasn't yet initialized |
| 4720 | * completely when built-in to the kernel right between the time |
| 4721 | * window between nl80211_init() and regulatory_init(), if that is |
| 4722 | * even possible. |
| 4723 | */ |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4724 | if (unlikely(!rcu_access_pointer(cfg80211_regdomain))) |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 4725 | return -EINPROGRESS; |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 4726 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4727 | if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]) |
| 4728 | user_reg_hint_type = |
| 4729 | nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]); |
| 4730 | else |
| 4731 | user_reg_hint_type = NL80211_USER_REG_HINT_USER; |
| 4732 | |
| 4733 | switch (user_reg_hint_type) { |
| 4734 | case NL80211_USER_REG_HINT_USER: |
| 4735 | case NL80211_USER_REG_HINT_CELL_BASE: |
Ilan Peer | 52616f2 | 2014-02-25 16:26:00 +0200 | [diff] [blame] | 4736 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 4737 | return -EINVAL; |
| 4738 | |
| 4739 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 4740 | return regulatory_hint_user(data, user_reg_hint_type); |
| 4741 | case NL80211_USER_REG_HINT_INDOOR: |
| 4742 | return regulatory_hint_indoor_user(); |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4743 | default: |
| 4744 | return -EINVAL; |
| 4745 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4746 | } |
| 4747 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4748 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4749 | struct genl_info *info) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4750 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4751 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4752 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4753 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 4754 | struct mesh_config cur_params; |
| 4755 | int err = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4756 | void *hdr; |
| 4757 | struct nlattr *pinfoattr; |
| 4758 | struct sk_buff *msg; |
| 4759 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4760 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4761 | return -EOPNOTSUPP; |
| 4762 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4763 | if (!rdev->ops->get_mesh_config) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4764 | return -EOPNOTSUPP; |
Jouni Malinen | f3f9258 | 2009-03-20 17:57:36 +0200 | [diff] [blame] | 4765 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4766 | wdev_lock(wdev); |
| 4767 | /* If not connected, get default parameters */ |
| 4768 | if (!wdev->mesh_id_len) |
| 4769 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); |
| 4770 | else |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4771 | err = rdev_get_mesh_config(rdev, dev, &cur_params); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4772 | wdev_unlock(wdev); |
| 4773 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4774 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4775 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4776 | |
| 4777 | /* Draw up a netlink message to send back */ |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4778 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4779 | if (!msg) |
| 4780 | return -ENOMEM; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4781 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4782 | NL80211_CMD_GET_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4783 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4784 | goto out; |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4785 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4786 | if (!pinfoattr) |
| 4787 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4788 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 4789 | nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 4790 | cur_params.dot11MeshRetryTimeout) || |
| 4791 | nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 4792 | cur_params.dot11MeshConfirmTimeout) || |
| 4793 | nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 4794 | cur_params.dot11MeshHoldingTimeout) || |
| 4795 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 4796 | cur_params.dot11MeshMaxPeerLinks) || |
| 4797 | nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES, |
| 4798 | cur_params.dot11MeshMaxRetries) || |
| 4799 | nla_put_u8(msg, NL80211_MESHCONF_TTL, |
| 4800 | cur_params.dot11MeshTTL) || |
| 4801 | nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL, |
| 4802 | cur_params.element_ttl) || |
| 4803 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 4804 | cur_params.auto_open_plinks) || |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 4805 | nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 4806 | cur_params.dot11MeshNbrOffsetMaxNeighbor) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4807 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 4808 | cur_params.dot11MeshHWMPmaxPREQretries) || |
| 4809 | nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 4810 | cur_params.path_refresh_time) || |
| 4811 | nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 4812 | cur_params.min_discovery_timeout) || |
| 4813 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 4814 | cur_params.dot11MeshHWMPactivePathTimeout) || |
| 4815 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 4816 | cur_params.dot11MeshHWMPpreqMinInterval) || |
| 4817 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
| 4818 | cur_params.dot11MeshHWMPperrMinInterval) || |
| 4819 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 4820 | cur_params.dot11MeshHWMPnetDiameterTraversalTime) || |
| 4821 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 4822 | cur_params.dot11MeshHWMPRootMode) || |
| 4823 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
| 4824 | cur_params.dot11MeshHWMPRannInterval) || |
| 4825 | nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
| 4826 | cur_params.dot11MeshGateAnnouncementProtocol) || |
| 4827 | nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, |
| 4828 | cur_params.dot11MeshForwarding) || |
| 4829 | nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, |
Ashok Nagarajan | 70c33ea | 2012-04-30 14:20:32 -0700 | [diff] [blame] | 4830 | cur_params.rssi_threshold) || |
| 4831 | nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4832 | cur_params.ht_opmode) || |
| 4833 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 4834 | cur_params.dot11MeshHWMPactivePathToRootTimeout) || |
| 4835 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4836 | cur_params.dot11MeshHWMProotInterval) || |
| 4837 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4838 | cur_params.dot11MeshHWMPconfirmationInterval) || |
| 4839 | nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE, |
| 4840 | cur_params.power_mode) || |
| 4841 | nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW, |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 4842 | cur_params.dot11MeshAwakeWindowDuration) || |
| 4843 | nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT, |
| 4844 | cur_params.plink_timeout)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4845 | goto nla_put_failure; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4846 | nla_nest_end(msg, pinfoattr); |
| 4847 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4848 | return genlmsg_reply(msg, info); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4849 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4850 | nla_put_failure: |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4851 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4852 | out: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 4853 | nlmsg_free(msg); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4854 | return -ENOBUFS; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4855 | } |
| 4856 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 4857 | 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] | 4858 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
| 4859 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, |
| 4860 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, |
| 4861 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, |
| 4862 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, |
| 4863 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 4864 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4865 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 4866 | [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4867 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
| 4868 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, |
| 4869 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, |
| 4870 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, |
| 4871 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 4872 | [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4873 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
Javier Cardona | 699403d | 2011-08-09 16:45:09 -0700 | [diff] [blame] | 4874 | [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 }, |
Javier Cardona | 0507e15 | 2011-08-09 16:45:10 -0700 | [diff] [blame] | 4875 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 }, |
Javier Cardona | 16dd726 | 2011-08-09 16:45:11 -0700 | [diff] [blame] | 4876 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | 94f9065 | 2012-01-21 01:02:16 +0800 | [diff] [blame] | 4877 | [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4878 | [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 }, |
| 4879 | [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4880 | [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 }, |
| 4881 | [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4882 | [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 }, |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4883 | [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 }, |
| 4884 | [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 }, |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 4885 | [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4886 | }; |
| 4887 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4888 | static const struct nla_policy |
| 4889 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 4890 | [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4891 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
| 4892 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 4893 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
Colleen Twitty | 6e16d90 | 2013-05-08 11:45:59 -0700 | [diff] [blame] | 4894 | [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 }, |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 4895 | [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG }, |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4896 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4897 | .len = IEEE80211_MAX_DATA_LEN }, |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 4898 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4899 | }; |
| 4900 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4901 | static int nl80211_parse_mesh_config(struct genl_info *info, |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4902 | struct mesh_config *cfg, |
| 4903 | u32 *mask_out) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4904 | { |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4905 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4906 | u32 mask = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4907 | |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4908 | #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \ |
| 4909 | do { \ |
| 4910 | if (tb[attr]) { \ |
| 4911 | if (fn(tb[attr]) < min || fn(tb[attr]) > max) \ |
| 4912 | return -EINVAL; \ |
| 4913 | cfg->param = fn(tb[attr]); \ |
| 4914 | mask |= (1 << (attr - 1)); \ |
| 4915 | } \ |
| 4916 | } while (0) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4917 | |
| 4918 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4919 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4920 | return -EINVAL; |
| 4921 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4922 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4923 | nl80211_meshconf_params_policy)) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4924 | return -EINVAL; |
| 4925 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4926 | /* This makes sure that there aren't more than 32 mesh config |
| 4927 | * parameters (otherwise our bitfield scheme would not work.) */ |
| 4928 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); |
| 4929 | |
| 4930 | /* Fill in the params struct */ |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4931 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4932 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 4933 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4934 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4935 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 4936 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4937 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4938 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 4939 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4940 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4941 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 4942 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4943 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4944 | mask, NL80211_MESHCONF_MAX_RETRIES, |
| 4945 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4946 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4947 | mask, NL80211_MESHCONF_TTL, nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4948 | 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] | 4949 | mask, NL80211_MESHCONF_ELEMENT_TTL, |
| 4950 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4951 | 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] | 4952 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 4953 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4954 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, |
| 4955 | 1, 255, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4956 | NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 4957 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4958 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4959 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 4960 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4961 | 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] | 4962 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 4963 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4964 | 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] | 4965 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 4966 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4967 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
| 4968 | 1, 65535, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4969 | NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 4970 | nla_get_u32); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4971 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4972 | 1, 65535, mask, |
| 4973 | NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4974 | nla_get_u16); |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 4975 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4976 | 1, 65535, mask, |
| 4977 | NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4978 | nla_get_u16); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4979 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4980 | dot11MeshHWMPnetDiameterTraversalTime, |
| 4981 | 1, 65535, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4982 | NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 4983 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4984 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4, |
| 4985 | mask, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 4986 | nla_get_u8); |
| 4987 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535, |
| 4988 | mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4989 | nla_get_u16); |
Rui Paulo | 63c5723 | 2009-11-09 23:46:57 +0000 | [diff] [blame] | 4990 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4991 | dot11MeshGateAnnouncementProtocol, 0, 1, |
| 4992 | mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4993 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4994 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4995 | mask, NL80211_MESHCONF_FORWARDING, |
| 4996 | nla_get_u8); |
Chun-Yeow Yeoh | 83374fe | 2013-07-11 18:24:03 +0800 | [diff] [blame] | 4997 | 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] | 4998 | mask, NL80211_MESHCONF_RSSI_THRESHOLD, |
Chun-Yeow Yeoh | 83374fe | 2013-07-11 18:24:03 +0800 | [diff] [blame] | 4999 | nla_get_s32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5000 | 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] | 5001 | mask, NL80211_MESHCONF_HT_OPMODE, |
| 5002 | nla_get_u16); |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 5003 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5004 | 1, 65535, mask, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 5005 | NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 5006 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5007 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 5008 | mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
| 5009 | nla_get_u16); |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 5010 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5011 | dot11MeshHWMPconfirmationInterval, |
| 5012 | 1, 65535, mask, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 5013 | NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
| 5014 | nla_get_u16); |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 5015 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode, |
| 5016 | NL80211_MESH_POWER_ACTIVE, |
| 5017 | NL80211_MESH_POWER_MAX, |
| 5018 | mask, NL80211_MESHCONF_POWER_MODE, |
| 5019 | nla_get_u32); |
| 5020 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration, |
| 5021 | 0, 65535, mask, |
| 5022 | NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16); |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 5023 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 1, 0xffffffff, |
| 5024 | mask, NL80211_MESHCONF_PLINK_TIMEOUT, |
| 5025 | nla_get_u32); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5026 | if (mask_out) |
| 5027 | *mask_out = mask; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5028 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5029 | return 0; |
| 5030 | |
| 5031 | #undef FILL_IN_MESH_PARAM_IF_SET |
| 5032 | } |
| 5033 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5034 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
| 5035 | struct mesh_setup *setup) |
| 5036 | { |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 5037 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5038 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
| 5039 | |
| 5040 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) |
| 5041 | return -EINVAL; |
| 5042 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, |
| 5043 | info->attrs[NL80211_ATTR_MESH_SETUP], |
| 5044 | nl80211_mesh_setup_params_policy)) |
| 5045 | return -EINVAL; |
| 5046 | |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 5047 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC]) |
| 5048 | setup->sync_method = |
| 5049 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ? |
| 5050 | IEEE80211_SYNC_METHOD_VENDOR : |
| 5051 | IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET; |
| 5052 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5053 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
| 5054 | setup->path_sel_proto = |
| 5055 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? |
| 5056 | IEEE80211_PATH_PROTOCOL_VENDOR : |
| 5057 | IEEE80211_PATH_PROTOCOL_HWMP; |
| 5058 | |
| 5059 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) |
| 5060 | setup->path_metric = |
| 5061 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? |
| 5062 | IEEE80211_PATH_METRIC_VENDOR : |
| 5063 | IEEE80211_PATH_METRIC_AIRTIME; |
| 5064 | |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 5065 | |
| 5066 | if (tb[NL80211_MESH_SETUP_IE]) { |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5067 | struct nlattr *ieattr = |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 5068 | tb[NL80211_MESH_SETUP_IE]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5069 | if (!is_valid_ie_attr(ieattr)) |
| 5070 | return -EINVAL; |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 5071 | setup->ie = nla_data(ieattr); |
| 5072 | setup->ie_len = nla_len(ieattr); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5073 | } |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 5074 | if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] && |
| 5075 | !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM)) |
| 5076 | return -EINVAL; |
| 5077 | setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]); |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 5078 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
| 5079 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 5080 | if (setup->is_secure) |
| 5081 | setup->user_mpm = true; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5082 | |
Colleen Twitty | 6e16d90 | 2013-05-08 11:45:59 -0700 | [diff] [blame] | 5083 | if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) { |
| 5084 | if (!setup->user_mpm) |
| 5085 | return -EINVAL; |
| 5086 | setup->auth_id = |
| 5087 | nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]); |
| 5088 | } |
| 5089 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5090 | return 0; |
| 5091 | } |
| 5092 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5093 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5094 | struct genl_info *info) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5095 | { |
| 5096 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5097 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5098 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5099 | struct mesh_config cfg; |
| 5100 | u32 mask; |
| 5101 | int err; |
| 5102 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5103 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 5104 | return -EOPNOTSUPP; |
| 5105 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5106 | if (!rdev->ops->update_mesh_config) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5107 | return -EOPNOTSUPP; |
| 5108 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5109 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5110 | if (err) |
| 5111 | return err; |
| 5112 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5113 | wdev_lock(wdev); |
| 5114 | if (!wdev->mesh_id_len) |
| 5115 | err = -ENOLINK; |
| 5116 | |
| 5117 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5118 | err = rdev_update_mesh_config(rdev, dev, mask, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5119 | |
| 5120 | wdev_unlock(wdev); |
| 5121 | |
| 5122 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5123 | } |
| 5124 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5125 | static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info) |
| 5126 | { |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5127 | const struct ieee80211_regdomain *regdom; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5128 | struct sk_buff *msg; |
| 5129 | void *hdr = NULL; |
| 5130 | struct nlattr *nl_reg_rules; |
| 5131 | unsigned int i; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5132 | |
| 5133 | if (!cfg80211_regdomain) |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5134 | return -EINVAL; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5135 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 5136 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5137 | if (!msg) |
| 5138 | return -ENOBUFS; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5139 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5140 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5141 | NL80211_CMD_GET_REG); |
| 5142 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 5143 | goto put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5144 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 5145 | if (reg_last_request_cell_base() && |
| 5146 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, |
| 5147 | NL80211_USER_REG_HINT_CELL_BASE)) |
| 5148 | goto nla_put_failure; |
| 5149 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5150 | rcu_read_lock(); |
| 5151 | regdom = rcu_dereference(cfg80211_regdomain); |
| 5152 | |
| 5153 | if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) || |
| 5154 | (regdom->dfs_region && |
| 5155 | nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region))) |
| 5156 | goto nla_put_failure_rcu; |
| 5157 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5158 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
| 5159 | if (!nl_reg_rules) |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5160 | goto nla_put_failure_rcu; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5161 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5162 | for (i = 0; i < regdom->n_reg_rules; i++) { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5163 | struct nlattr *nl_reg_rule; |
| 5164 | const struct ieee80211_reg_rule *reg_rule; |
| 5165 | const struct ieee80211_freq_range *freq_range; |
| 5166 | const struct ieee80211_power_rule *power_rule; |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 5167 | unsigned int max_bandwidth_khz; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5168 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5169 | reg_rule = ®dom->reg_rules[i]; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5170 | freq_range = ®_rule->freq_range; |
| 5171 | power_rule = ®_rule->power_rule; |
| 5172 | |
| 5173 | nl_reg_rule = nla_nest_start(msg, i); |
| 5174 | if (!nl_reg_rule) |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5175 | goto nla_put_failure_rcu; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5176 | |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 5177 | max_bandwidth_khz = freq_range->max_bandwidth_khz; |
| 5178 | if (!max_bandwidth_khz) |
| 5179 | max_bandwidth_khz = reg_get_max_bandwidth(regdom, |
| 5180 | reg_rule); |
| 5181 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5182 | if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
| 5183 | reg_rule->flags) || |
| 5184 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START, |
| 5185 | freq_range->start_freq_khz) || |
| 5186 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END, |
| 5187 | freq_range->end_freq_khz) || |
| 5188 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 5189 | max_bandwidth_khz) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5190 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
| 5191 | power_rule->max_antenna_gain) || |
| 5192 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, |
Janusz Dziedzic | 089027e | 2014-02-21 19:46:12 +0100 | [diff] [blame] | 5193 | power_rule->max_eirp) || |
| 5194 | nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME, |
| 5195 | reg_rule->dfs_cac_ms)) |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5196 | goto nla_put_failure_rcu; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5197 | |
| 5198 | nla_nest_end(msg, nl_reg_rule); |
| 5199 | } |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5200 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5201 | |
| 5202 | nla_nest_end(msg, nl_reg_rules); |
| 5203 | |
| 5204 | genlmsg_end(msg, hdr); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5205 | return genlmsg_reply(msg, info); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5206 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5207 | nla_put_failure_rcu: |
| 5208 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5209 | nla_put_failure: |
| 5210 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 5211 | put_failure: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 5212 | nlmsg_free(msg); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5213 | return -EMSGSIZE; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5214 | } |
| 5215 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5216 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 5217 | { |
| 5218 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; |
| 5219 | struct nlattr *nl_reg_rule; |
| 5220 | char *alpha2 = NULL; |
| 5221 | int rem_reg_rules = 0, r = 0; |
| 5222 | u32 num_rules = 0, rule_idx = 0, size_of_regd; |
Luis R. Rodriguez | 4c7d398 | 2013-11-13 18:54:02 +0100 | [diff] [blame] | 5223 | enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5224 | struct ieee80211_regdomain *rd = NULL; |
| 5225 | |
| 5226 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 5227 | return -EINVAL; |
| 5228 | |
| 5229 | if (!info->attrs[NL80211_ATTR_REG_RULES]) |
| 5230 | return -EINVAL; |
| 5231 | |
| 5232 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 5233 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 5234 | if (info->attrs[NL80211_ATTR_DFS_REGION]) |
| 5235 | dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); |
| 5236 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5237 | 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] | 5238 | rem_reg_rules) { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5239 | num_rules++; |
| 5240 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) |
Luis R. Rodriguez | 4776c6e | 2009-05-13 17:04:39 -0400 | [diff] [blame] | 5241 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5242 | } |
| 5243 | |
Luis R. Rodriguez | e438768 | 2013-11-05 09:18:01 -0800 | [diff] [blame] | 5244 | if (!reg_is_valid_request(alpha2)) |
| 5245 | return -EINVAL; |
| 5246 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5247 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 5248 | num_rules * sizeof(struct ieee80211_reg_rule); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5249 | |
| 5250 | rd = kzalloc(size_of_regd, GFP_KERNEL); |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 5251 | if (!rd) |
| 5252 | return -ENOMEM; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5253 | |
| 5254 | rd->n_reg_rules = num_rules; |
| 5255 | rd->alpha2[0] = alpha2[0]; |
| 5256 | rd->alpha2[1] = alpha2[1]; |
| 5257 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 5258 | /* |
| 5259 | * Disable DFS master mode if the DFS region was |
| 5260 | * not supported or known on this kernel. |
| 5261 | */ |
| 5262 | if (reg_supported_dfs_region(dfs_region)) |
| 5263 | rd->dfs_region = dfs_region; |
| 5264 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5265 | 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] | 5266 | rem_reg_rules) { |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 5267 | r = nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, |
| 5268 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), |
| 5269 | reg_rule_policy); |
| 5270 | if (r) |
| 5271 | goto bad_reg; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5272 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
| 5273 | if (r) |
| 5274 | goto bad_reg; |
| 5275 | |
| 5276 | rule_idx++; |
| 5277 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 5278 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
| 5279 | r = -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5280 | goto bad_reg; |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 5281 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5282 | } |
| 5283 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5284 | r = set_regdom(rd); |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 5285 | /* set_regdom took ownership */ |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 5286 | rd = NULL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5287 | |
Johannes Berg | d2372b3 | 2008-10-24 20:32:20 +0200 | [diff] [blame] | 5288 | bad_reg: |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5289 | kfree(rd); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 5290 | return r; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5291 | } |
| 5292 | |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5293 | static int validate_scan_freqs(struct nlattr *freqs) |
| 5294 | { |
| 5295 | struct nlattr *attr1, *attr2; |
| 5296 | int n_channels = 0, tmp1, tmp2; |
| 5297 | |
| 5298 | nla_for_each_nested(attr1, freqs, tmp1) { |
| 5299 | n_channels++; |
| 5300 | /* |
| 5301 | * Some hardware has a limited channel list for |
| 5302 | * scanning, and it is pretty much nonsensical |
| 5303 | * to scan for a channel twice, so disallow that |
| 5304 | * and don't require drivers to check that the |
| 5305 | * channel list they get isn't longer than what |
| 5306 | * they can scan, as long as they can scan all |
| 5307 | * the channels they registered at once. |
| 5308 | */ |
| 5309 | nla_for_each_nested(attr2, freqs, tmp2) |
| 5310 | if (attr1 != attr2 && |
| 5311 | nla_get_u32(attr1) == nla_get_u32(attr2)) |
| 5312 | return 0; |
| 5313 | } |
| 5314 | |
| 5315 | return n_channels; |
| 5316 | } |
| 5317 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5318 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
| 5319 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5320 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 5321 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5322 | struct cfg80211_scan_request *request; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5323 | struct nlattr *attr; |
| 5324 | struct wiphy *wiphy; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5325 | int err, tmp, n_ssids = 0, n_channels, i; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5326 | size_t ie_len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5327 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5328 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5329 | return -EINVAL; |
| 5330 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5331 | wiphy = &rdev->wiphy; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5332 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5333 | if (!rdev->ops->scan) |
| 5334 | return -EOPNOTSUPP; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5335 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 5336 | if (rdev->scan_req || rdev->scan_msg) { |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5337 | err = -EBUSY; |
| 5338 | goto unlock; |
| 5339 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5340 | |
| 5341 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5342 | n_channels = validate_scan_freqs( |
| 5343 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5344 | if (!n_channels) { |
| 5345 | err = -EINVAL; |
| 5346 | goto unlock; |
| 5347 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5348 | } else { |
Ilan Peer | bdfbec2 | 2014-01-09 11:37:23 +0200 | [diff] [blame] | 5349 | n_channels = ieee80211_get_num_supported_channels(wiphy); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5350 | } |
| 5351 | |
| 5352 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 5353 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) |
| 5354 | n_ssids++; |
| 5355 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5356 | if (n_ssids > wiphy->max_scan_ssids) { |
| 5357 | err = -EINVAL; |
| 5358 | goto unlock; |
| 5359 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5360 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5361 | if (info->attrs[NL80211_ATTR_IE]) |
| 5362 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5363 | else |
| 5364 | ie_len = 0; |
| 5365 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5366 | if (ie_len > wiphy->max_scan_ie_len) { |
| 5367 | err = -EINVAL; |
| 5368 | goto unlock; |
| 5369 | } |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 5370 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5371 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 5372 | + sizeof(*request->ssids) * n_ssids |
| 5373 | + sizeof(*request->channels) * n_channels |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5374 | + ie_len, GFP_KERNEL); |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5375 | if (!request) { |
| 5376 | err = -ENOMEM; |
| 5377 | goto unlock; |
| 5378 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5379 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5380 | if (n_ssids) |
Johannes Berg | 5ba6353 | 2009-08-07 17:54:07 +0200 | [diff] [blame] | 5381 | request->ssids = (void *)&request->channels[n_channels]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5382 | request->n_ssids = n_ssids; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5383 | if (ie_len) { |
| 5384 | if (request->ssids) |
| 5385 | request->ie = (void *)(request->ssids + n_ssids); |
| 5386 | else |
| 5387 | request->ie = (void *)(request->channels + n_channels); |
| 5388 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5389 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5390 | i = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5391 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 5392 | /* user specified, bail out if channel not found */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5393 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5394 | struct ieee80211_channel *chan; |
| 5395 | |
| 5396 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 5397 | |
| 5398 | if (!chan) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5399 | err = -EINVAL; |
| 5400 | goto out_free; |
| 5401 | } |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5402 | |
| 5403 | /* ignore disabled channels */ |
| 5404 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5405 | continue; |
| 5406 | |
| 5407 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5408 | i++; |
| 5409 | } |
| 5410 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5411 | enum ieee80211_band band; |
| 5412 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5413 | /* all channels */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5414 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 5415 | int j; |
| 5416 | if (!wiphy->bands[band]) |
| 5417 | continue; |
| 5418 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5419 | struct ieee80211_channel *chan; |
| 5420 | |
| 5421 | chan = &wiphy->bands[band]->channels[j]; |
| 5422 | |
| 5423 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5424 | continue; |
| 5425 | |
| 5426 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5427 | i++; |
| 5428 | } |
| 5429 | } |
| 5430 | } |
| 5431 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5432 | if (!i) { |
| 5433 | err = -EINVAL; |
| 5434 | goto out_free; |
| 5435 | } |
| 5436 | |
| 5437 | request->n_channels = i; |
| 5438 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5439 | i = 0; |
| 5440 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 5441 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5442 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5443 | err = -EINVAL; |
| 5444 | goto out_free; |
| 5445 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5446 | request->ssids[i].ssid_len = nla_len(attr); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5447 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5448 | i++; |
| 5449 | } |
| 5450 | } |
| 5451 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5452 | if (info->attrs[NL80211_ATTR_IE]) { |
| 5453 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Johannes Berg | de95a54 | 2009-04-01 11:58:36 +0200 | [diff] [blame] | 5454 | memcpy((void *)request->ie, |
| 5455 | nla_data(info->attrs[NL80211_ATTR_IE]), |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5456 | request->ie_len); |
| 5457 | } |
| 5458 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5459 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) |
Johannes Berg | a401d2b | 2011-07-20 00:52:16 +0200 | [diff] [blame] | 5460 | if (wiphy->bands[i]) |
| 5461 | request->rates[i] = |
| 5462 | (1 << wiphy->bands[i]->n_bitrates) - 1; |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5463 | |
| 5464 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { |
| 5465 | nla_for_each_nested(attr, |
| 5466 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], |
| 5467 | tmp) { |
| 5468 | enum ieee80211_band band = nla_type(attr); |
| 5469 | |
Dan Carpenter | 8440462 | 2011-07-29 11:52:18 +0300 | [diff] [blame] | 5470 | if (band < 0 || band >= IEEE80211_NUM_BANDS) { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5471 | err = -EINVAL; |
| 5472 | goto out_free; |
| 5473 | } |
Felix Fietkau | 1b09cd8 | 2013-11-20 19:40:41 +0100 | [diff] [blame] | 5474 | |
| 5475 | if (!wiphy->bands[band]) |
| 5476 | continue; |
| 5477 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5478 | err = ieee80211_get_ratemask(wiphy->bands[band], |
| 5479 | nla_data(attr), |
| 5480 | nla_len(attr), |
| 5481 | &request->rates[band]); |
| 5482 | if (err) |
| 5483 | goto out_free; |
| 5484 | } |
| 5485 | } |
| 5486 | |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5487 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5488 | request->flags = nla_get_u32( |
| 5489 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); |
Johannes Berg | 00c3a6e | 2013-10-26 17:14:38 +0200 | [diff] [blame] | 5490 | if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 5491 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) { |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5492 | err = -EOPNOTSUPP; |
| 5493 | goto out_free; |
| 5494 | } |
| 5495 | } |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5496 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 5497 | request->no_cck = |
| 5498 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 5499 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 5500 | request->wdev = wdev; |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5501 | request->wiphy = &rdev->wiphy; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 5502 | request->scan_start = jiffies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5503 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5504 | rdev->scan_req = request; |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5505 | err = rdev_scan(rdev, request); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5506 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5507 | if (!err) { |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 5508 | nl80211_send_scan_start(rdev, wdev); |
| 5509 | if (wdev->netdev) |
| 5510 | dev_hold(wdev->netdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5511 | } else { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5512 | out_free: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5513 | rdev->scan_req = NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5514 | kfree(request); |
| 5515 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 5516 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5517 | unlock: |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5518 | return err; |
| 5519 | } |
| 5520 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5521 | static int nl80211_start_sched_scan(struct sk_buff *skb, |
| 5522 | struct genl_info *info) |
| 5523 | { |
| 5524 | struct cfg80211_sched_scan_request *request; |
| 5525 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5526 | struct net_device *dev = info->user_ptr[1]; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5527 | struct nlattr *attr; |
| 5528 | struct wiphy *wiphy; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5529 | 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] | 5530 | u32 interval; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5531 | enum ieee80211_band band; |
| 5532 | size_t ie_len; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5533 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 5534 | s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5535 | |
| 5536 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 5537 | !rdev->ops->sched_scan_start) |
| 5538 | return -EOPNOTSUPP; |
| 5539 | |
| 5540 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5541 | return -EINVAL; |
| 5542 | |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 5543 | if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
| 5544 | return -EINVAL; |
| 5545 | |
| 5546 | interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); |
| 5547 | if (interval == 0) |
| 5548 | return -EINVAL; |
| 5549 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5550 | wiphy = &rdev->wiphy; |
| 5551 | |
| 5552 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 5553 | n_channels = validate_scan_freqs( |
| 5554 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
| 5555 | if (!n_channels) |
| 5556 | return -EINVAL; |
| 5557 | } else { |
Ilan Peer | bdfbec2 | 2014-01-09 11:37:23 +0200 | [diff] [blame] | 5558 | n_channels = ieee80211_get_num_supported_channels(wiphy); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5559 | } |
| 5560 | |
| 5561 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 5562 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 5563 | tmp) |
| 5564 | n_ssids++; |
| 5565 | |
Luciano Coelho | 93b6aa6 | 2011-07-13 14:57:28 +0300 | [diff] [blame] | 5566 | if (n_ssids > wiphy->max_sched_scan_ssids) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5567 | return -EINVAL; |
| 5568 | |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 5569 | /* |
| 5570 | * First, count the number of 'real' matchsets. Due to an issue with |
| 5571 | * the old implementation, matchsets containing only the RSSI attribute |
| 5572 | * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default' |
| 5573 | * RSSI for all matchsets, rather than their own matchset for reporting |
| 5574 | * all APs with a strong RSSI. This is needed to be compatible with |
| 5575 | * older userspace that treated a matchset with only the RSSI as the |
| 5576 | * global RSSI for all other matchsets - if there are other matchsets. |
| 5577 | */ |
| 5578 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5579 | nla_for_each_nested(attr, |
| 5580 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 5581 | tmp) { |
| 5582 | struct nlattr *rssi; |
| 5583 | |
| 5584 | err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
| 5585 | nla_data(attr), nla_len(attr), |
| 5586 | nl80211_match_policy); |
| 5587 | if (err) |
| 5588 | return err; |
| 5589 | /* add other standalone attributes here */ |
| 5590 | if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]) { |
| 5591 | n_match_sets++; |
| 5592 | continue; |
| 5593 | } |
| 5594 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; |
| 5595 | if (rssi) |
| 5596 | default_match_rssi = nla_get_s32(rssi); |
| 5597 | } |
| 5598 | } |
| 5599 | |
| 5600 | /* However, if there's no other matchset, add the RSSI one */ |
| 5601 | if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF) |
| 5602 | n_match_sets = 1; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5603 | |
| 5604 | if (n_match_sets > wiphy->max_match_sets) |
| 5605 | return -EINVAL; |
| 5606 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5607 | if (info->attrs[NL80211_ATTR_IE]) |
| 5608 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5609 | else |
| 5610 | ie_len = 0; |
| 5611 | |
Luciano Coelho | 5a865ba | 2011-07-13 14:57:29 +0300 | [diff] [blame] | 5612 | if (ie_len > wiphy->max_sched_scan_ie_len) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5613 | return -EINVAL; |
| 5614 | |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 5615 | if (rdev->sched_scan_req) { |
| 5616 | err = -EINPROGRESS; |
| 5617 | goto out; |
| 5618 | } |
| 5619 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5620 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 5621 | + sizeof(*request->ssids) * n_ssids |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5622 | + sizeof(*request->match_sets) * n_match_sets |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 5623 | + sizeof(*request->channels) * n_channels |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5624 | + ie_len, GFP_KERNEL); |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 5625 | if (!request) { |
| 5626 | err = -ENOMEM; |
| 5627 | goto out; |
| 5628 | } |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5629 | |
| 5630 | if (n_ssids) |
| 5631 | request->ssids = (void *)&request->channels[n_channels]; |
| 5632 | request->n_ssids = n_ssids; |
| 5633 | if (ie_len) { |
| 5634 | if (request->ssids) |
| 5635 | request->ie = (void *)(request->ssids + n_ssids); |
| 5636 | else |
| 5637 | request->ie = (void *)(request->channels + n_channels); |
| 5638 | } |
| 5639 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5640 | if (n_match_sets) { |
| 5641 | if (request->ie) |
| 5642 | request->match_sets = (void *)(request->ie + ie_len); |
| 5643 | else if (request->ssids) |
| 5644 | request->match_sets = |
| 5645 | (void *)(request->ssids + n_ssids); |
| 5646 | else |
| 5647 | request->match_sets = |
| 5648 | (void *)(request->channels + n_channels); |
| 5649 | } |
| 5650 | request->n_match_sets = n_match_sets; |
| 5651 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5652 | i = 0; |
| 5653 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 5654 | /* user specified, bail out if channel not found */ |
| 5655 | nla_for_each_nested(attr, |
| 5656 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], |
| 5657 | tmp) { |
| 5658 | struct ieee80211_channel *chan; |
| 5659 | |
| 5660 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 5661 | |
| 5662 | if (!chan) { |
| 5663 | err = -EINVAL; |
| 5664 | goto out_free; |
| 5665 | } |
| 5666 | |
| 5667 | /* ignore disabled channels */ |
| 5668 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5669 | continue; |
| 5670 | |
| 5671 | request->channels[i] = chan; |
| 5672 | i++; |
| 5673 | } |
| 5674 | } else { |
| 5675 | /* all channels */ |
| 5676 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 5677 | int j; |
| 5678 | if (!wiphy->bands[band]) |
| 5679 | continue; |
| 5680 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
| 5681 | struct ieee80211_channel *chan; |
| 5682 | |
| 5683 | chan = &wiphy->bands[band]->channels[j]; |
| 5684 | |
| 5685 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5686 | continue; |
| 5687 | |
| 5688 | request->channels[i] = chan; |
| 5689 | i++; |
| 5690 | } |
| 5691 | } |
| 5692 | } |
| 5693 | |
| 5694 | if (!i) { |
| 5695 | err = -EINVAL; |
| 5696 | goto out_free; |
| 5697 | } |
| 5698 | |
| 5699 | request->n_channels = i; |
| 5700 | |
| 5701 | i = 0; |
| 5702 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 5703 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 5704 | tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5705 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5706 | err = -EINVAL; |
| 5707 | goto out_free; |
| 5708 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5709 | request->ssids[i].ssid_len = nla_len(attr); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5710 | memcpy(request->ssids[i].ssid, nla_data(attr), |
| 5711 | nla_len(attr)); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5712 | i++; |
| 5713 | } |
| 5714 | } |
| 5715 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5716 | i = 0; |
| 5717 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
| 5718 | nla_for_each_nested(attr, |
| 5719 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
| 5720 | tmp) { |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 5721 | struct nlattr *ssid, *rssi; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5722 | |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 5723 | err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
| 5724 | nla_data(attr), nla_len(attr), |
| 5725 | nl80211_match_policy); |
| 5726 | if (err) |
| 5727 | goto out_free; |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 5728 | ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5729 | if (ssid) { |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 5730 | if (WARN_ON(i >= n_match_sets)) { |
| 5731 | /* this indicates a programming error, |
| 5732 | * the loop above should have verified |
| 5733 | * things properly |
| 5734 | */ |
| 5735 | err = -EINVAL; |
| 5736 | goto out_free; |
| 5737 | } |
| 5738 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5739 | if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) { |
| 5740 | err = -EINVAL; |
| 5741 | goto out_free; |
| 5742 | } |
| 5743 | memcpy(request->match_sets[i].ssid.ssid, |
| 5744 | nla_data(ssid), nla_len(ssid)); |
| 5745 | request->match_sets[i].ssid.ssid_len = |
| 5746 | nla_len(ssid); |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 5747 | /* special attribute - old implemenation w/a */ |
| 5748 | request->match_sets[i].rssi_thold = |
| 5749 | default_match_rssi; |
| 5750 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; |
| 5751 | if (rssi) |
| 5752 | request->match_sets[i].rssi_thold = |
| 5753 | nla_get_s32(rssi); |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5754 | } |
| 5755 | i++; |
| 5756 | } |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 5757 | |
| 5758 | /* there was no other matchset, so the RSSI one is alone */ |
| 5759 | if (i == 0) |
| 5760 | request->match_sets[0].rssi_thold = default_match_rssi; |
| 5761 | |
| 5762 | request->min_rssi_thold = INT_MAX; |
| 5763 | for (i = 0; i < n_match_sets; i++) |
| 5764 | request->min_rssi_thold = |
| 5765 | min(request->match_sets[i].rssi_thold, |
| 5766 | request->min_rssi_thold); |
| 5767 | } else { |
| 5768 | request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5769 | } |
| 5770 | |
Johannes Berg | 9900e48 | 2014-02-04 21:01:25 +0100 | [diff] [blame] | 5771 | if (ie_len) { |
| 5772 | request->ie_len = ie_len; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5773 | memcpy((void *)request->ie, |
| 5774 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 5775 | request->ie_len); |
| 5776 | } |
| 5777 | |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5778 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5779 | request->flags = nla_get_u32( |
| 5780 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); |
Johannes Berg | 00c3a6e | 2013-10-26 17:14:38 +0200 | [diff] [blame] | 5781 | if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 5782 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) { |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5783 | err = -EOPNOTSUPP; |
| 5784 | goto out_free; |
| 5785 | } |
| 5786 | } |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5787 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5788 | request->dev = dev; |
| 5789 | request->wiphy = &rdev->wiphy; |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 5790 | request->interval = interval; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 5791 | request->scan_start = jiffies; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5792 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5793 | err = rdev_sched_scan_start(rdev, dev, request); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5794 | if (!err) { |
| 5795 | rdev->sched_scan_req = request; |
| 5796 | nl80211_send_sched_scan(rdev, dev, |
| 5797 | NL80211_CMD_START_SCHED_SCAN); |
| 5798 | goto out; |
| 5799 | } |
| 5800 | |
| 5801 | out_free: |
| 5802 | kfree(request); |
| 5803 | out: |
| 5804 | return err; |
| 5805 | } |
| 5806 | |
| 5807 | static int nl80211_stop_sched_scan(struct sk_buff *skb, |
| 5808 | struct genl_info *info) |
| 5809 | { |
| 5810 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5811 | |
| 5812 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 5813 | !rdev->ops->sched_scan_stop) |
| 5814 | return -EOPNOTSUPP; |
| 5815 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5816 | return __cfg80211_stop_sched_scan(rdev, false); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5817 | } |
| 5818 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5819 | static int nl80211_start_radar_detection(struct sk_buff *skb, |
| 5820 | struct genl_info *info) |
| 5821 | { |
| 5822 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5823 | struct net_device *dev = info->user_ptr[1]; |
| 5824 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 5825 | struct cfg80211_chan_def chandef; |
Luis R. Rodriguez | 55f7435 | 2013-11-25 20:56:10 +0100 | [diff] [blame] | 5826 | enum nl80211_dfs_regions dfs_region; |
Janusz Dziedzic | 31559f3 | 2014-02-21 19:46:13 +0100 | [diff] [blame] | 5827 | unsigned int cac_time_ms; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5828 | int err; |
| 5829 | |
Luis R. Rodriguez | 55f7435 | 2013-11-25 20:56:10 +0100 | [diff] [blame] | 5830 | dfs_region = reg_get_dfs_region(wdev->wiphy); |
| 5831 | if (dfs_region == NL80211_DFS_UNSET) |
| 5832 | return -EINVAL; |
| 5833 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5834 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 5835 | if (err) |
| 5836 | return err; |
| 5837 | |
Simon Wunderlich | ff311bc | 2013-09-03 19:43:18 +0200 | [diff] [blame] | 5838 | if (netif_carrier_ok(dev)) |
| 5839 | return -EBUSY; |
| 5840 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5841 | if (wdev->cac_started) |
| 5842 | return -EBUSY; |
| 5843 | |
Luciano Coelho | 2beb6dab | 2014-02-18 11:40:36 +0200 | [diff] [blame] | 5844 | err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, |
Luciano Coelho | 00ec75f | 2014-05-15 13:05:39 +0300 | [diff] [blame] | 5845 | wdev->iftype); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5846 | if (err < 0) |
| 5847 | return err; |
| 5848 | |
| 5849 | if (err == 0) |
| 5850 | return -EINVAL; |
| 5851 | |
Janusz Dziedzic | fe7c3a1 | 2013-11-05 14:48:48 +0100 | [diff] [blame] | 5852 | if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef)) |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5853 | return -EINVAL; |
| 5854 | |
| 5855 | if (!rdev->ops->start_radar_detection) |
| 5856 | return -EOPNOTSUPP; |
| 5857 | |
Janusz Dziedzic | 31559f3 | 2014-02-21 19:46:13 +0100 | [diff] [blame] | 5858 | cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef); |
| 5859 | if (WARN_ON(!cac_time_ms)) |
| 5860 | cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS; |
| 5861 | |
| 5862 | err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef, |
| 5863 | cac_time_ms); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5864 | if (!err) { |
Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 5865 | wdev->chandef = chandef; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5866 | wdev->cac_started = true; |
| 5867 | wdev->cac_start_time = jiffies; |
Janusz Dziedzic | 31559f3 | 2014-02-21 19:46:13 +0100 | [diff] [blame] | 5868 | wdev->cac_time_ms = cac_time_ms; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5869 | } |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5870 | return err; |
| 5871 | } |
| 5872 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5873 | static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info) |
| 5874 | { |
| 5875 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5876 | struct net_device *dev = info->user_ptr[1]; |
| 5877 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 5878 | struct cfg80211_csa_settings params; |
| 5879 | /* csa_attrs is defined static to avoid waste of stack size - this |
| 5880 | * function is called under RTNL lock, so this should not be a problem. |
| 5881 | */ |
| 5882 | static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1]; |
| 5883 | u8 radar_detect_width = 0; |
| 5884 | int err; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5885 | bool need_new_beacon = false; |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 5886 | int len, i; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5887 | |
| 5888 | if (!rdev->ops->channel_switch || |
| 5889 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)) |
| 5890 | return -EOPNOTSUPP; |
| 5891 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5892 | switch (dev->ieee80211_ptr->iftype) { |
| 5893 | case NL80211_IFTYPE_AP: |
| 5894 | case NL80211_IFTYPE_P2P_GO: |
| 5895 | need_new_beacon = true; |
| 5896 | |
| 5897 | /* useless if AP is not running */ |
| 5898 | if (!wdev->beacon_interval) |
Johannes Berg | 1ff79df | 2014-01-22 10:05:27 +0100 | [diff] [blame] | 5899 | return -ENOTCONN; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5900 | break; |
| 5901 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | 1ff79df | 2014-01-22 10:05:27 +0100 | [diff] [blame] | 5902 | if (!wdev->ssid_len) |
| 5903 | return -ENOTCONN; |
| 5904 | break; |
Chun-Yeow Yeoh | c6da674 | 2013-10-14 19:08:28 -0700 | [diff] [blame] | 5905 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 1ff79df | 2014-01-22 10:05:27 +0100 | [diff] [blame] | 5906 | if (!wdev->mesh_id_len) |
| 5907 | return -ENOTCONN; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5908 | break; |
| 5909 | default: |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5910 | return -EOPNOTSUPP; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5911 | } |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5912 | |
| 5913 | memset(¶ms, 0, sizeof(params)); |
| 5914 | |
| 5915 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 5916 | !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]) |
| 5917 | return -EINVAL; |
| 5918 | |
| 5919 | /* only important for AP, IBSS and mesh create IEs internally */ |
Andrei Otcheretianski | d0a361a | 2013-10-17 10:52:17 +0200 | [diff] [blame] | 5920 | if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES]) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5921 | return -EINVAL; |
| 5922 | |
| 5923 | params.count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]); |
| 5924 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5925 | if (!need_new_beacon) |
| 5926 | goto skip_beacons; |
| 5927 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5928 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon_after); |
| 5929 | if (err) |
| 5930 | return err; |
| 5931 | |
| 5932 | err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX, |
| 5933 | info->attrs[NL80211_ATTR_CSA_IES], |
| 5934 | nl80211_policy); |
| 5935 | if (err) |
| 5936 | return err; |
| 5937 | |
| 5938 | err = nl80211_parse_beacon(csa_attrs, ¶ms.beacon_csa); |
| 5939 | if (err) |
| 5940 | return err; |
| 5941 | |
| 5942 | if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]) |
| 5943 | return -EINVAL; |
| 5944 | |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 5945 | len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); |
| 5946 | if (!len || (len % sizeof(u16))) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5947 | return -EINVAL; |
| 5948 | |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 5949 | params.n_counter_offsets_beacon = len / sizeof(u16); |
| 5950 | if (rdev->wiphy.max_num_csa_counters && |
| 5951 | (params.n_counter_offsets_beacon > |
| 5952 | rdev->wiphy.max_num_csa_counters)) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5953 | return -EINVAL; |
| 5954 | |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 5955 | params.counter_offsets_beacon = |
| 5956 | nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); |
| 5957 | |
| 5958 | /* sanity checks - counters should fit and be the same */ |
| 5959 | for (i = 0; i < params.n_counter_offsets_beacon; i++) { |
| 5960 | u16 offset = params.counter_offsets_beacon[i]; |
| 5961 | |
| 5962 | if (offset >= params.beacon_csa.tail_len) |
| 5963 | return -EINVAL; |
| 5964 | |
| 5965 | if (params.beacon_csa.tail[offset] != params.count) |
| 5966 | return -EINVAL; |
| 5967 | } |
| 5968 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5969 | if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) { |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 5970 | len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); |
| 5971 | if (!len || (len % sizeof(u16))) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5972 | return -EINVAL; |
| 5973 | |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 5974 | params.n_counter_offsets_presp = len / sizeof(u16); |
| 5975 | if (rdev->wiphy.max_num_csa_counters && |
| 5976 | (params.n_counter_offsets_beacon > |
| 5977 | rdev->wiphy.max_num_csa_counters)) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5978 | return -EINVAL; |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 5979 | |
| 5980 | params.counter_offsets_presp = |
| 5981 | nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); |
| 5982 | |
| 5983 | /* sanity checks - counters should fit and be the same */ |
| 5984 | for (i = 0; i < params.n_counter_offsets_presp; i++) { |
| 5985 | u16 offset = params.counter_offsets_presp[i]; |
| 5986 | |
| 5987 | if (offset >= params.beacon_csa.probe_resp_len) |
| 5988 | return -EINVAL; |
| 5989 | |
| 5990 | if (params.beacon_csa.probe_resp[offset] != |
| 5991 | params.count) |
| 5992 | return -EINVAL; |
| 5993 | } |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5994 | } |
| 5995 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5996 | skip_beacons: |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5997 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
| 5998 | if (err) |
| 5999 | return err; |
| 6000 | |
Ilan Peer | 174e0cd | 2014-02-23 09:13:01 +0200 | [diff] [blame] | 6001 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, ¶ms.chandef, |
| 6002 | wdev->iftype)) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6003 | return -EINVAL; |
| 6004 | |
Luciano Coelho | 2beb6dab | 2014-02-18 11:40:36 +0200 | [diff] [blame] | 6005 | err = cfg80211_chandef_dfs_required(wdev->wiphy, |
| 6006 | ¶ms.chandef, |
| 6007 | wdev->iftype); |
| 6008 | if (err < 0) |
| 6009 | return err; |
| 6010 | |
| 6011 | if (err > 0) { |
| 6012 | radar_detect_width = BIT(params.chandef.width); |
| 6013 | params.radar_required = true; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6014 | } |
| 6015 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6016 | if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX]) |
| 6017 | params.block_tx = true; |
| 6018 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 6019 | wdev_lock(wdev); |
| 6020 | err = rdev_channel_switch(rdev, dev, ¶ms); |
| 6021 | wdev_unlock(wdev); |
| 6022 | |
| 6023 | return err; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6024 | } |
| 6025 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 6026 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
| 6027 | u32 seq, int flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6028 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6029 | struct wireless_dev *wdev, |
| 6030 | struct cfg80211_internal_bss *intbss) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6031 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6032 | struct cfg80211_bss *res = &intbss->pub; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 6033 | const struct cfg80211_bss_ies *ies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6034 | void *hdr; |
| 6035 | struct nlattr *bss; |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 6036 | bool tsf = false; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6037 | |
| 6038 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6039 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6040 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6041 | NL80211_CMD_NEW_SCAN_RESULTS); |
| 6042 | if (!hdr) |
| 6043 | return -1; |
| 6044 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 6045 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
| 6046 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6047 | if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation)) |
| 6048 | goto nla_put_failure; |
| 6049 | if (wdev->netdev && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6050 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex)) |
| 6051 | goto nla_put_failure; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6052 | if (nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 6053 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6054 | |
| 6055 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); |
| 6056 | if (!bss) |
| 6057 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6058 | if ((!is_zero_ether_addr(res->bssid) && |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 6059 | nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6060 | goto nla_put_failure; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 6061 | |
| 6062 | rcu_read_lock(); |
| 6063 | ies = rcu_dereference(res->ies); |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 6064 | if (ies) { |
| 6065 | if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf)) |
| 6066 | goto fail_unlock_rcu; |
| 6067 | tsf = true; |
| 6068 | if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS, |
| 6069 | ies->len, ies->data)) |
| 6070 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 6071 | } |
| 6072 | ies = rcu_dereference(res->beacon_ies); |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 6073 | if (ies) { |
| 6074 | if (!tsf && nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf)) |
| 6075 | goto fail_unlock_rcu; |
| 6076 | if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES, |
| 6077 | ies->len, ies->data)) |
| 6078 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 6079 | } |
| 6080 | rcu_read_unlock(); |
| 6081 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6082 | if (res->beacon_interval && |
| 6083 | nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval)) |
| 6084 | goto nla_put_failure; |
| 6085 | if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) || |
| 6086 | nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) || |
Simon Wunderlich | dcd6eac | 2013-07-08 16:55:49 +0200 | [diff] [blame] | 6087 | nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6088 | nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO, |
| 6089 | jiffies_to_msecs(jiffies - intbss->ts))) |
| 6090 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6091 | |
Johannes Berg | 77965c9 | 2009-02-18 18:45:06 +0100 | [diff] [blame] | 6092 | switch (rdev->wiphy.signal_type) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6093 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6094 | if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal)) |
| 6095 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6096 | break; |
| 6097 | case CFG80211_SIGNAL_TYPE_UNSPEC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6098 | if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal)) |
| 6099 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6100 | break; |
| 6101 | default: |
| 6102 | break; |
| 6103 | } |
| 6104 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6105 | switch (wdev->iftype) { |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6106 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6107 | case NL80211_IFTYPE_STATION: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6108 | if (intbss == wdev->current_bss && |
| 6109 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 6110 | NL80211_BSS_STATUS_ASSOCIATED)) |
| 6111 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6112 | break; |
| 6113 | case NL80211_IFTYPE_ADHOC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6114 | if (intbss == wdev->current_bss && |
| 6115 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 6116 | NL80211_BSS_STATUS_IBSS_JOINED)) |
| 6117 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6118 | break; |
| 6119 | default: |
| 6120 | break; |
| 6121 | } |
| 6122 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6123 | nla_nest_end(msg, bss); |
| 6124 | |
| 6125 | return genlmsg_end(msg, hdr); |
| 6126 | |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 6127 | fail_unlock_rcu: |
| 6128 | rcu_read_unlock(); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6129 | nla_put_failure: |
| 6130 | genlmsg_cancel(msg, hdr); |
| 6131 | return -EMSGSIZE; |
| 6132 | } |
| 6133 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6134 | 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] | 6135 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6136 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6137 | struct cfg80211_internal_bss *scan; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6138 | struct wireless_dev *wdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6139 | int start = cb->args[2], idx = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6140 | int err; |
| 6141 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6142 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 6143 | if (err) |
| 6144 | return err; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6145 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6146 | wdev_lock(wdev); |
| 6147 | spin_lock_bh(&rdev->bss_lock); |
| 6148 | cfg80211_bss_expire(rdev); |
| 6149 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 6150 | cb->seq = rdev->bss_generation; |
| 6151 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6152 | list_for_each_entry(scan, &rdev->bss_list, list) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6153 | if (++idx <= start) |
| 6154 | continue; |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 6155 | if (nl80211_send_bss(skb, cb, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6156 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6157 | rdev, wdev, scan) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6158 | idx--; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 6159 | break; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6160 | } |
| 6161 | } |
| 6162 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6163 | spin_unlock_bh(&rdev->bss_lock); |
| 6164 | wdev_unlock(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6165 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6166 | cb->args[2] = idx; |
| 6167 | nl80211_finish_wdev_dump(rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6168 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 6169 | return skb->len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6170 | } |
| 6171 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6172 | 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] | 6173 | int flags, struct net_device *dev, |
| 6174 | struct survey_info *survey) |
| 6175 | { |
| 6176 | void *hdr; |
| 6177 | struct nlattr *infoattr; |
| 6178 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6179 | hdr = nl80211hdr_put(msg, portid, seq, flags, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6180 | NL80211_CMD_NEW_SURVEY_RESULTS); |
| 6181 | if (!hdr) |
| 6182 | return -ENOMEM; |
| 6183 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6184 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
| 6185 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6186 | |
| 6187 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); |
| 6188 | if (!infoattr) |
| 6189 | goto nla_put_failure; |
| 6190 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6191 | if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY, |
| 6192 | survey->channel->center_freq)) |
| 6193 | goto nla_put_failure; |
| 6194 | |
| 6195 | if ((survey->filled & SURVEY_INFO_NOISE_DBM) && |
| 6196 | nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise)) |
| 6197 | goto nla_put_failure; |
| 6198 | if ((survey->filled & SURVEY_INFO_IN_USE) && |
| 6199 | nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE)) |
| 6200 | goto nla_put_failure; |
| 6201 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) && |
| 6202 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME, |
| 6203 | survey->channel_time)) |
| 6204 | goto nla_put_failure; |
| 6205 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) && |
| 6206 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY, |
| 6207 | survey->channel_time_busy)) |
| 6208 | goto nla_put_failure; |
| 6209 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) && |
| 6210 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY, |
| 6211 | survey->channel_time_ext_busy)) |
| 6212 | goto nla_put_failure; |
| 6213 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) && |
| 6214 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX, |
| 6215 | survey->channel_time_rx)) |
| 6216 | goto nla_put_failure; |
| 6217 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) && |
| 6218 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX, |
| 6219 | survey->channel_time_tx)) |
| 6220 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6221 | |
| 6222 | nla_nest_end(msg, infoattr); |
| 6223 | |
| 6224 | return genlmsg_end(msg, hdr); |
| 6225 | |
| 6226 | nla_put_failure: |
| 6227 | genlmsg_cancel(msg, hdr); |
| 6228 | return -EMSGSIZE; |
| 6229 | } |
| 6230 | |
| 6231 | static int nl80211_dump_survey(struct sk_buff *skb, |
| 6232 | struct netlink_callback *cb) |
| 6233 | { |
| 6234 | struct survey_info survey; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 6235 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6236 | struct wireless_dev *wdev; |
| 6237 | int survey_idx = cb->args[2]; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6238 | int res; |
| 6239 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 6240 | res = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 6241 | if (res) |
| 6242 | return res; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6243 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6244 | if (!wdev->netdev) { |
| 6245 | res = -EINVAL; |
| 6246 | goto out_err; |
| 6247 | } |
| 6248 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 6249 | if (!rdev->ops->dump_survey) { |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6250 | res = -EOPNOTSUPP; |
| 6251 | goto out_err; |
| 6252 | } |
| 6253 | |
| 6254 | while (1) { |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 6255 | struct ieee80211_channel *chan; |
| 6256 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 6257 | res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6258 | if (res == -ENOENT) |
| 6259 | break; |
| 6260 | if (res) |
| 6261 | goto out_err; |
| 6262 | |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 6263 | /* Survey without a channel doesn't make sense */ |
| 6264 | if (!survey.channel) { |
| 6265 | res = -EINVAL; |
| 6266 | goto out; |
| 6267 | } |
| 6268 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 6269 | chan = ieee80211_get_channel(&rdev->wiphy, |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 6270 | survey.channel->center_freq); |
| 6271 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) { |
| 6272 | survey_idx++; |
| 6273 | continue; |
| 6274 | } |
| 6275 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6276 | if (nl80211_send_survey(skb, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6277 | NETLINK_CB(cb->skb).portid, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6278 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6279 | wdev->netdev, &survey) < 0) |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6280 | goto out; |
| 6281 | survey_idx++; |
| 6282 | } |
| 6283 | |
| 6284 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6285 | cb->args[2] = survey_idx; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6286 | res = skb->len; |
| 6287 | out_err: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 6288 | nl80211_finish_wdev_dump(rdev); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6289 | return res; |
| 6290 | } |
| 6291 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6292 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
| 6293 | { |
| 6294 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | |
| 6295 | NL80211_WPA_VERSION_2)); |
| 6296 | } |
| 6297 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6298 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
| 6299 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6300 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6301 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6302 | struct ieee80211_channel *chan; |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 6303 | const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL; |
| 6304 | int err, ssid_len, ie_len = 0, sae_data_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6305 | enum nl80211_auth_type auth_type; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6306 | struct key_parse key; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6307 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6308 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6309 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6310 | return -EINVAL; |
| 6311 | |
| 6312 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6313 | return -EINVAL; |
| 6314 | |
Jouni Malinen | 1778092 | 2009-03-27 20:52:47 +0200 | [diff] [blame] | 6315 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
| 6316 | return -EINVAL; |
| 6317 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6318 | if (!info->attrs[NL80211_ATTR_SSID]) |
| 6319 | return -EINVAL; |
| 6320 | |
| 6321 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 6322 | return -EINVAL; |
| 6323 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6324 | err = nl80211_parse_key(info, &key); |
| 6325 | if (err) |
| 6326 | return err; |
| 6327 | |
| 6328 | if (key.idx >= 0) { |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 6329 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
| 6330 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6331 | if (!key.p.key || !key.p.key_len) |
| 6332 | return -EINVAL; |
| 6333 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || |
| 6334 | key.p.key_len != WLAN_KEY_LEN_WEP40) && |
| 6335 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || |
| 6336 | key.p.key_len != WLAN_KEY_LEN_WEP104)) |
| 6337 | return -EINVAL; |
| 6338 | if (key.idx > 4) |
| 6339 | return -EINVAL; |
| 6340 | } else { |
| 6341 | key.p.key_len = 0; |
| 6342 | key.p.key = NULL; |
| 6343 | } |
| 6344 | |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 6345 | if (key.idx >= 0) { |
| 6346 | int i; |
| 6347 | bool ok = false; |
| 6348 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { |
| 6349 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { |
| 6350 | ok = true; |
| 6351 | break; |
| 6352 | } |
| 6353 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6354 | if (!ok) |
| 6355 | return -EINVAL; |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 6356 | } |
| 6357 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6358 | if (!rdev->ops->auth) |
| 6359 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6360 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6361 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6362 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6363 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6364 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6365 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 6366 | chan = nl80211_get_valid_chan(&rdev->wiphy, |
| 6367 | info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 6368 | if (!chan) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6369 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6370 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6371 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 6372 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 6373 | |
| 6374 | if (info->attrs[NL80211_ATTR_IE]) { |
| 6375 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6376 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 6377 | } |
| 6378 | |
| 6379 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 6380 | if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6381 | return -EINVAL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6382 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 6383 | if (auth_type == NL80211_AUTHTYPE_SAE && |
| 6384 | !info->attrs[NL80211_ATTR_SAE_DATA]) |
| 6385 | return -EINVAL; |
| 6386 | |
| 6387 | if (info->attrs[NL80211_ATTR_SAE_DATA]) { |
| 6388 | if (auth_type != NL80211_AUTHTYPE_SAE) |
| 6389 | return -EINVAL; |
| 6390 | sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]); |
| 6391 | sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]); |
| 6392 | /* need to include at least Auth Transaction and Status Code */ |
| 6393 | if (sae_data_len < 4) |
| 6394 | return -EINVAL; |
| 6395 | } |
| 6396 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6397 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 6398 | |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 6399 | /* |
| 6400 | * Since we no longer track auth state, ignore |
| 6401 | * requests to only change local state. |
| 6402 | */ |
| 6403 | if (local_state_change) |
| 6404 | return 0; |
| 6405 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6406 | wdev_lock(dev->ieee80211_ptr); |
| 6407 | err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, |
| 6408 | ssid, ssid_len, ie, ie_len, |
| 6409 | key.p.key, key.p.key_len, key.idx, |
| 6410 | sae_data, sae_data_len); |
| 6411 | wdev_unlock(dev->ieee80211_ptr); |
| 6412 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6413 | } |
| 6414 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 6415 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 6416 | struct genl_info *info, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 6417 | struct cfg80211_crypto_settings *settings, |
| 6418 | int cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6419 | { |
Johannes Berg | c0b2bbd | 2009-07-25 16:54:36 +0200 | [diff] [blame] | 6420 | memset(settings, 0, sizeof(*settings)); |
| 6421 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6422 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
| 6423 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 6424 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
| 6425 | u16 proto; |
| 6426 | proto = nla_get_u16( |
| 6427 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); |
| 6428 | settings->control_port_ethertype = cpu_to_be16(proto); |
| 6429 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 6430 | proto != ETH_P_PAE) |
| 6431 | return -EINVAL; |
| 6432 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) |
| 6433 | settings->control_port_no_encrypt = true; |
| 6434 | } else |
| 6435 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); |
| 6436 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6437 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
| 6438 | void *data; |
| 6439 | int len, i; |
| 6440 | |
| 6441 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 6442 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 6443 | settings->n_ciphers_pairwise = len / sizeof(u32); |
| 6444 | |
| 6445 | if (len % sizeof(u32)) |
| 6446 | return -EINVAL; |
| 6447 | |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 6448 | if (settings->n_ciphers_pairwise > cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6449 | return -EINVAL; |
| 6450 | |
| 6451 | memcpy(settings->ciphers_pairwise, data, len); |
| 6452 | |
| 6453 | for (i = 0; i < settings->n_ciphers_pairwise; i++) |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 6454 | if (!cfg80211_supported_cipher_suite( |
| 6455 | &rdev->wiphy, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6456 | settings->ciphers_pairwise[i])) |
| 6457 | return -EINVAL; |
| 6458 | } |
| 6459 | |
| 6460 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { |
| 6461 | settings->cipher_group = |
| 6462 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 6463 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
| 6464 | settings->cipher_group)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6465 | return -EINVAL; |
| 6466 | } |
| 6467 | |
| 6468 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { |
| 6469 | settings->wpa_versions = |
| 6470 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); |
| 6471 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) |
| 6472 | return -EINVAL; |
| 6473 | } |
| 6474 | |
| 6475 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { |
| 6476 | void *data; |
Jouni Malinen | 6d30240 | 2011-09-21 18:11:33 +0300 | [diff] [blame] | 6477 | int len; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6478 | |
| 6479 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 6480 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 6481 | settings->n_akm_suites = len / sizeof(u32); |
| 6482 | |
| 6483 | if (len % sizeof(u32)) |
| 6484 | return -EINVAL; |
| 6485 | |
Jouni Malinen | 1b9ca02 | 2011-09-21 16:13:07 +0300 | [diff] [blame] | 6486 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) |
| 6487 | return -EINVAL; |
| 6488 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6489 | memcpy(settings->akm_suites, data, len); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6490 | } |
| 6491 | |
| 6492 | return 0; |
| 6493 | } |
| 6494 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6495 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
| 6496 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6497 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6498 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 6499 | struct ieee80211_channel *chan; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6500 | struct cfg80211_assoc_request req = {}; |
| 6501 | const u8 *bssid, *ssid; |
| 6502 | int err, ssid_len = 0; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6503 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6504 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6505 | return -EINVAL; |
| 6506 | |
| 6507 | if (!info->attrs[NL80211_ATTR_MAC] || |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6508 | !info->attrs[NL80211_ATTR_SSID] || |
| 6509 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6510 | return -EINVAL; |
| 6511 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6512 | if (!rdev->ops->assoc) |
| 6513 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6514 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6515 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6516 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6517 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6518 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6519 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6520 | |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 6521 | chan = nl80211_get_valid_chan(&rdev->wiphy, |
| 6522 | info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 6523 | if (!chan) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6524 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6525 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6526 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 6527 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6528 | |
| 6529 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6530 | req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6531 | req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6532 | } |
| 6533 | |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 6534 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 6535 | enum nl80211_mfp mfp = |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 6536 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 6537 | if (mfp == NL80211_MFP_REQUIRED) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6538 | req.use_mfp = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6539 | else if (mfp != NL80211_MFP_NO) |
| 6540 | return -EINVAL; |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 6541 | } |
| 6542 | |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 6543 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6544 | req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 6545 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6546 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6547 | req.flags |= ASSOC_REQ_DISABLE_HT; |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6548 | |
| 6549 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6550 | memcpy(&req.ht_capa_mask, |
| 6551 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 6552 | sizeof(req.ht_capa_mask)); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6553 | |
| 6554 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6555 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6556 | return -EINVAL; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6557 | memcpy(&req.ht_capa, |
| 6558 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 6559 | sizeof(req.ht_capa)); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6560 | } |
| 6561 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6562 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6563 | req.flags |= ASSOC_REQ_DISABLE_VHT; |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6564 | |
| 6565 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6566 | memcpy(&req.vht_capa_mask, |
| 6567 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), |
| 6568 | sizeof(req.vht_capa_mask)); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6569 | |
| 6570 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6571 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6572 | return -EINVAL; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6573 | memcpy(&req.vht_capa, |
| 6574 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), |
| 6575 | sizeof(req.vht_capa)); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6576 | } |
| 6577 | |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6578 | err = nl80211_crypto_settings(rdev, info, &req.crypto, 1); |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6579 | if (!err) { |
| 6580 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6581 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, |
| 6582 | ssid, ssid_len, &req); |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6583 | wdev_unlock(dev->ieee80211_ptr); |
| 6584 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6585 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6586 | return err; |
| 6587 | } |
| 6588 | |
| 6589 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) |
| 6590 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6591 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6592 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6593 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6594 | int ie_len = 0, err; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6595 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6596 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6597 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6598 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6599 | return -EINVAL; |
| 6600 | |
| 6601 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6602 | return -EINVAL; |
| 6603 | |
| 6604 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 6605 | return -EINVAL; |
| 6606 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6607 | if (!rdev->ops->deauth) |
| 6608 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6609 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6610 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6611 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6612 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6613 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6614 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6615 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6616 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 6617 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6618 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6619 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 6620 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6621 | |
| 6622 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6623 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6624 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6625 | } |
| 6626 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6627 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 6628 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6629 | wdev_lock(dev->ieee80211_ptr); |
| 6630 | err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, |
| 6631 | local_state_change); |
| 6632 | wdev_unlock(dev->ieee80211_ptr); |
| 6633 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6634 | } |
| 6635 | |
| 6636 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) |
| 6637 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6638 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6639 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6640 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6641 | int ie_len = 0, err; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6642 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6643 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6644 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6645 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6646 | return -EINVAL; |
| 6647 | |
| 6648 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6649 | return -EINVAL; |
| 6650 | |
| 6651 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 6652 | return -EINVAL; |
| 6653 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6654 | if (!rdev->ops->disassoc) |
| 6655 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6656 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6657 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6658 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6659 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6660 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6661 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6662 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6663 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 6664 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6665 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6666 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 6667 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6668 | |
| 6669 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6670 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6671 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6672 | } |
| 6673 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6674 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 6675 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6676 | wdev_lock(dev->ieee80211_ptr); |
| 6677 | err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, |
| 6678 | local_state_change); |
| 6679 | wdev_unlock(dev->ieee80211_ptr); |
| 6680 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6681 | } |
| 6682 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 6683 | static bool |
| 6684 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, |
| 6685 | int mcast_rate[IEEE80211_NUM_BANDS], |
| 6686 | int rateval) |
| 6687 | { |
| 6688 | struct wiphy *wiphy = &rdev->wiphy; |
| 6689 | bool found = false; |
| 6690 | int band, i; |
| 6691 | |
| 6692 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 6693 | struct ieee80211_supported_band *sband; |
| 6694 | |
| 6695 | sband = wiphy->bands[band]; |
| 6696 | if (!sband) |
| 6697 | continue; |
| 6698 | |
| 6699 | for (i = 0; i < sband->n_bitrates; i++) { |
| 6700 | if (sband->bitrates[i].bitrate == rateval) { |
| 6701 | mcast_rate[band] = i + 1; |
| 6702 | found = true; |
| 6703 | break; |
| 6704 | } |
| 6705 | } |
| 6706 | } |
| 6707 | |
| 6708 | return found; |
| 6709 | } |
| 6710 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6711 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
| 6712 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6713 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6714 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6715 | struct cfg80211_ibss_params ibss; |
| 6716 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6717 | struct cfg80211_cached_keys *connkeys = NULL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6718 | int err; |
| 6719 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 6720 | memset(&ibss, 0, sizeof(ibss)); |
| 6721 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6722 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6723 | return -EINVAL; |
| 6724 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6725 | if (!info->attrs[NL80211_ATTR_SSID] || |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6726 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 6727 | return -EINVAL; |
| 6728 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 6729 | ibss.beacon_interval = 100; |
| 6730 | |
| 6731 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 6732 | ibss.beacon_interval = |
| 6733 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 6734 | if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000) |
| 6735 | return -EINVAL; |
| 6736 | } |
| 6737 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6738 | if (!rdev->ops->join_ibss) |
| 6739 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6740 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6741 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 6742 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6743 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 6744 | wiphy = &rdev->wiphy; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6745 | |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 6746 | if (info->attrs[NL80211_ATTR_MAC]) { |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6747 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 6748 | |
| 6749 | if (!is_valid_ether_addr(ibss.bssid)) |
| 6750 | return -EINVAL; |
| 6751 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6752 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 6753 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 6754 | |
| 6755 | if (info->attrs[NL80211_ATTR_IE]) { |
| 6756 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6757 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 6758 | } |
| 6759 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6760 | err = nl80211_parse_chandef(rdev, info, &ibss.chandef); |
| 6761 | if (err) |
| 6762 | return err; |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 6763 | |
Ilan Peer | 174e0cd | 2014-02-23 09:13:01 +0200 | [diff] [blame] | 6764 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef, |
| 6765 | NL80211_IFTYPE_ADHOC)) |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 6766 | return -EINVAL; |
| 6767 | |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 6768 | switch (ibss.chandef.width) { |
Simon Wunderlich | bf37264 | 2013-07-08 16:55:58 +0200 | [diff] [blame] | 6769 | case NL80211_CHAN_WIDTH_5: |
| 6770 | case NL80211_CHAN_WIDTH_10: |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 6771 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 6772 | break; |
| 6773 | case NL80211_CHAN_WIDTH_20: |
| 6774 | case NL80211_CHAN_WIDTH_40: |
| 6775 | if (rdev->wiphy.features & NL80211_FEATURE_HT_IBSS) |
| 6776 | break; |
| 6777 | default: |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 6778 | return -EINVAL; |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 6779 | } |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 6780 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6781 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6782 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6783 | |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 6784 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 6785 | u8 *rates = |
| 6786 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 6787 | int n_rates = |
| 6788 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 6789 | struct ieee80211_supported_band *sband = |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6790 | wiphy->bands[ibss.chandef.chan->band]; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 6791 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 6792 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 6793 | &ibss.basic_rates); |
| 6794 | if (err) |
| 6795 | return err; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 6796 | } |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 6797 | |
Simon Wunderlich | 803768f | 2013-06-28 10:39:58 +0200 | [diff] [blame] | 6798 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 6799 | memcpy(&ibss.ht_capa_mask, |
| 6800 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 6801 | sizeof(ibss.ht_capa_mask)); |
| 6802 | |
| 6803 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
| 6804 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 6805 | return -EINVAL; |
| 6806 | memcpy(&ibss.ht_capa, |
| 6807 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 6808 | sizeof(ibss.ht_capa)); |
| 6809 | } |
| 6810 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 6811 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 6812 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, |
| 6813 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 6814 | return -EINVAL; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 6815 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6816 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6817 | bool no_ht = false; |
| 6818 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6819 | connkeys = nl80211_parse_connkeys(rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6820 | info->attrs[NL80211_ATTR_KEYS], |
| 6821 | &no_ht); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6822 | if (IS_ERR(connkeys)) |
| 6823 | return PTR_ERR(connkeys); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6824 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 6825 | if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) && |
| 6826 | no_ht) { |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6827 | kfree(connkeys); |
| 6828 | return -EINVAL; |
| 6829 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6830 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6831 | |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 6832 | ibss.control_port = |
| 6833 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]); |
| 6834 | |
Simon Wunderlich | 5336fa8 | 2013-10-07 18:41:05 +0200 | [diff] [blame] | 6835 | ibss.userspace_handles_dfs = |
| 6836 | nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]); |
| 6837 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6838 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6839 | if (err) |
| 6840 | kfree(connkeys); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6841 | return err; |
| 6842 | } |
| 6843 | |
| 6844 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) |
| 6845 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6846 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6847 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6848 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6849 | if (!rdev->ops->leave_ibss) |
| 6850 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6851 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6852 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 6853 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6854 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6855 | return cfg80211_leave_ibss(rdev, dev, false); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6856 | } |
| 6857 | |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 6858 | static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info) |
| 6859 | { |
| 6860 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6861 | struct net_device *dev = info->user_ptr[1]; |
| 6862 | int mcast_rate[IEEE80211_NUM_BANDS]; |
| 6863 | u32 nla_rate; |
| 6864 | int err; |
| 6865 | |
| 6866 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
| 6867 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 6868 | return -EOPNOTSUPP; |
| 6869 | |
| 6870 | if (!rdev->ops->set_mcast_rate) |
| 6871 | return -EOPNOTSUPP; |
| 6872 | |
| 6873 | memset(mcast_rate, 0, sizeof(mcast_rate)); |
| 6874 | |
| 6875 | if (!info->attrs[NL80211_ATTR_MCAST_RATE]) |
| 6876 | return -EINVAL; |
| 6877 | |
| 6878 | nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]); |
| 6879 | if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate)) |
| 6880 | return -EINVAL; |
| 6881 | |
| 6882 | err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate); |
| 6883 | |
| 6884 | return err; |
| 6885 | } |
| 6886 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 6887 | static struct sk_buff * |
| 6888 | __cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev, |
| 6889 | int approxlen, u32 portid, u32 seq, |
| 6890 | enum nl80211_commands cmd, |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 6891 | enum nl80211_attrs attr, |
| 6892 | const struct nl80211_vendor_cmd_info *info, |
| 6893 | gfp_t gfp) |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 6894 | { |
| 6895 | struct sk_buff *skb; |
| 6896 | void *hdr; |
| 6897 | struct nlattr *data; |
| 6898 | |
| 6899 | skb = nlmsg_new(approxlen + 100, gfp); |
| 6900 | if (!skb) |
| 6901 | return NULL; |
| 6902 | |
| 6903 | hdr = nl80211hdr_put(skb, portid, seq, 0, cmd); |
| 6904 | if (!hdr) { |
| 6905 | kfree_skb(skb); |
| 6906 | return NULL; |
| 6907 | } |
| 6908 | |
| 6909 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 6910 | goto nla_put_failure; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 6911 | |
| 6912 | if (info) { |
| 6913 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID, |
| 6914 | info->vendor_id)) |
| 6915 | goto nla_put_failure; |
| 6916 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD, |
| 6917 | info->subcmd)) |
| 6918 | goto nla_put_failure; |
| 6919 | } |
| 6920 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 6921 | data = nla_nest_start(skb, attr); |
| 6922 | |
| 6923 | ((void **)skb->cb)[0] = rdev; |
| 6924 | ((void **)skb->cb)[1] = hdr; |
| 6925 | ((void **)skb->cb)[2] = data; |
| 6926 | |
| 6927 | return skb; |
| 6928 | |
| 6929 | nla_put_failure: |
| 6930 | kfree_skb(skb); |
| 6931 | return NULL; |
| 6932 | } |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 6933 | |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 6934 | struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy, |
| 6935 | enum nl80211_commands cmd, |
| 6936 | enum nl80211_attrs attr, |
| 6937 | int vendor_event_idx, |
| 6938 | int approxlen, gfp_t gfp) |
| 6939 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 6940 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 6941 | const struct nl80211_vendor_cmd_info *info; |
| 6942 | |
| 6943 | switch (cmd) { |
| 6944 | case NL80211_CMD_TESTMODE: |
| 6945 | if (WARN_ON(vendor_event_idx != -1)) |
| 6946 | return NULL; |
| 6947 | info = NULL; |
| 6948 | break; |
| 6949 | case NL80211_CMD_VENDOR: |
| 6950 | if (WARN_ON(vendor_event_idx < 0 || |
| 6951 | vendor_event_idx >= wiphy->n_vendor_events)) |
| 6952 | return NULL; |
| 6953 | info = &wiphy->vendor_events[vendor_event_idx]; |
| 6954 | break; |
| 6955 | default: |
| 6956 | WARN_ON(1); |
| 6957 | return NULL; |
| 6958 | } |
| 6959 | |
| 6960 | return __cfg80211_alloc_vendor_skb(rdev, approxlen, 0, 0, |
| 6961 | cmd, attr, info, gfp); |
| 6962 | } |
| 6963 | EXPORT_SYMBOL(__cfg80211_alloc_event_skb); |
| 6964 | |
| 6965 | void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp) |
| 6966 | { |
| 6967 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 6968 | void *hdr = ((void **)skb->cb)[1]; |
| 6969 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 6970 | enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE; |
| 6971 | |
| 6972 | nla_nest_end(skb, data); |
| 6973 | genlmsg_end(skb, hdr); |
| 6974 | |
| 6975 | if (data->nla_type == NL80211_ATTR_VENDOR_DATA) |
| 6976 | mcgrp = NL80211_MCGRP_VENDOR; |
| 6977 | |
| 6978 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0, |
| 6979 | mcgrp, gfp); |
| 6980 | } |
| 6981 | EXPORT_SYMBOL(__cfg80211_send_event_skb); |
| 6982 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6983 | #ifdef CONFIG_NL80211_TESTMODE |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6984 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
| 6985 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6986 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 6987 | struct wireless_dev *wdev = |
| 6988 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6989 | int err; |
| 6990 | |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 6991 | if (!rdev->ops->testmode_cmd) |
| 6992 | return -EOPNOTSUPP; |
| 6993 | |
| 6994 | if (IS_ERR(wdev)) { |
| 6995 | err = PTR_ERR(wdev); |
| 6996 | if (err != -EINVAL) |
| 6997 | return err; |
| 6998 | wdev = NULL; |
| 6999 | } else if (wdev->wiphy != &rdev->wiphy) { |
| 7000 | return -EINVAL; |
| 7001 | } |
| 7002 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7003 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
| 7004 | return -EINVAL; |
| 7005 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 7006 | rdev->cur_cmd_info = info; |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 7007 | err = rdev_testmode_cmd(rdev, wdev, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7008 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
| 7009 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 7010 | rdev->cur_cmd_info = NULL; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7011 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7012 | return err; |
| 7013 | } |
| 7014 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7015 | static int nl80211_testmode_dump(struct sk_buff *skb, |
| 7016 | struct netlink_callback *cb) |
| 7017 | { |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 7018 | struct cfg80211_registered_device *rdev; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7019 | int err; |
| 7020 | long phy_idx; |
| 7021 | void *data = NULL; |
| 7022 | int data_len = 0; |
| 7023 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 7024 | rtnl_lock(); |
| 7025 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7026 | if (cb->args[0]) { |
| 7027 | /* |
| 7028 | * 0 is a valid index, but not valid for args[0], |
| 7029 | * so we need to offset by 1. |
| 7030 | */ |
| 7031 | phy_idx = cb->args[0] - 1; |
| 7032 | } else { |
| 7033 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 7034 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 7035 | nl80211_policy); |
| 7036 | if (err) |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 7037 | goto out_err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 7038 | |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 7039 | rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), |
| 7040 | nl80211_fam.attrbuf); |
| 7041 | if (IS_ERR(rdev)) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 7042 | err = PTR_ERR(rdev); |
| 7043 | goto out_err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 7044 | } |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 7045 | phy_idx = rdev->wiphy_idx; |
| 7046 | rdev = NULL; |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 7047 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7048 | if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]) |
| 7049 | cb->args[1] = |
| 7050 | (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]; |
| 7051 | } |
| 7052 | |
| 7053 | if (cb->args[1]) { |
| 7054 | data = nla_data((void *)cb->args[1]); |
| 7055 | data_len = nla_len((void *)cb->args[1]); |
| 7056 | } |
| 7057 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 7058 | rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
| 7059 | if (!rdev) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 7060 | err = -ENOENT; |
| 7061 | goto out_err; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7062 | } |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7063 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 7064 | if (!rdev->ops->testmode_dump) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7065 | err = -EOPNOTSUPP; |
| 7066 | goto out_err; |
| 7067 | } |
| 7068 | |
| 7069 | while (1) { |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7070 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7071 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 7072 | NL80211_CMD_TESTMODE); |
| 7073 | struct nlattr *tmdata; |
| 7074 | |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 7075 | if (!hdr) |
| 7076 | break; |
| 7077 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7078 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7079 | genlmsg_cancel(skb, hdr); |
| 7080 | break; |
| 7081 | } |
| 7082 | |
| 7083 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 7084 | if (!tmdata) { |
| 7085 | genlmsg_cancel(skb, hdr); |
| 7086 | break; |
| 7087 | } |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7088 | err = rdev_testmode_dump(rdev, skb, cb, data, data_len); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7089 | nla_nest_end(skb, tmdata); |
| 7090 | |
| 7091 | if (err == -ENOBUFS || err == -ENOENT) { |
| 7092 | genlmsg_cancel(skb, hdr); |
| 7093 | break; |
| 7094 | } else if (err) { |
| 7095 | genlmsg_cancel(skb, hdr); |
| 7096 | goto out_err; |
| 7097 | } |
| 7098 | |
| 7099 | genlmsg_end(skb, hdr); |
| 7100 | } |
| 7101 | |
| 7102 | err = skb->len; |
| 7103 | /* see above */ |
| 7104 | cb->args[0] = phy_idx + 1; |
| 7105 | out_err: |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 7106 | rtnl_unlock(); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7107 | return err; |
| 7108 | } |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7109 | #endif |
| 7110 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7111 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
| 7112 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7113 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7114 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7115 | struct cfg80211_connect_params connect; |
| 7116 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7117 | struct cfg80211_cached_keys *connkeys = NULL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7118 | int err; |
| 7119 | |
| 7120 | memset(&connect, 0, sizeof(connect)); |
| 7121 | |
| 7122 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 7123 | return -EINVAL; |
| 7124 | |
| 7125 | if (!info->attrs[NL80211_ATTR_SSID] || |
| 7126 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 7127 | return -EINVAL; |
| 7128 | |
| 7129 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 7130 | connect.auth_type = |
| 7131 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 7132 | if (!nl80211_valid_auth_type(rdev, connect.auth_type, |
| 7133 | NL80211_CMD_CONNECT)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7134 | return -EINVAL; |
| 7135 | } else |
| 7136 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 7137 | |
| 7138 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; |
| 7139 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 7140 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 7141 | NL80211_MAX_NR_CIPHER_SUITES); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7142 | if (err) |
| 7143 | return err; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7144 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7145 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7146 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7147 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7148 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 7149 | wiphy = &rdev->wiphy; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7150 | |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 7151 | connect.bg_scan_period = -1; |
| 7152 | if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] && |
| 7153 | (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) { |
| 7154 | connect.bg_scan_period = |
| 7155 | nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]); |
| 7156 | } |
| 7157 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7158 | if (info->attrs[NL80211_ATTR_MAC]) |
| 7159 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 7160 | else if (info->attrs[NL80211_ATTR_MAC_HINT]) |
| 7161 | connect.bssid_hint = |
| 7162 | nla_data(info->attrs[NL80211_ATTR_MAC_HINT]); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7163 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 7164 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 7165 | |
| 7166 | if (info->attrs[NL80211_ATTR_IE]) { |
| 7167 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 7168 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 7169 | } |
| 7170 | |
Jouni Malinen | cee00a9 | 2013-01-15 17:15:57 +0200 | [diff] [blame] | 7171 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
| 7172 | connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
| 7173 | if (connect.mfp != NL80211_MFP_REQUIRED && |
| 7174 | connect.mfp != NL80211_MFP_NO) |
| 7175 | return -EINVAL; |
| 7176 | } else { |
| 7177 | connect.mfp = NL80211_MFP_NO; |
| 7178 | } |
| 7179 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7180 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 7181 | connect.channel = nl80211_get_valid_chan( |
| 7182 | wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 7183 | if (!connect.channel) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7184 | return -EINVAL; |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 7185 | } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) { |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 7186 | connect.channel_hint = nl80211_get_valid_chan( |
| 7187 | wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]); |
| 7188 | if (!connect.channel_hint) |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 7189 | return -EINVAL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7190 | } |
| 7191 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7192 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
| 7193 | connkeys = nl80211_parse_connkeys(rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 7194 | info->attrs[NL80211_ATTR_KEYS], NULL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7195 | if (IS_ERR(connkeys)) |
| 7196 | return PTR_ERR(connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7197 | } |
| 7198 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 7199 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
| 7200 | connect.flags |= ASSOC_REQ_DISABLE_HT; |
| 7201 | |
| 7202 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 7203 | memcpy(&connect.ht_capa_mask, |
| 7204 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 7205 | sizeof(connect.ht_capa_mask)); |
| 7206 | |
| 7207 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 7208 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) { |
| 7209 | kfree(connkeys); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 7210 | return -EINVAL; |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 7211 | } |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 7212 | memcpy(&connect.ht_capa, |
| 7213 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 7214 | sizeof(connect.ht_capa)); |
| 7215 | } |
| 7216 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 7217 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
| 7218 | connect.flags |= ASSOC_REQ_DISABLE_VHT; |
| 7219 | |
| 7220 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
| 7221 | memcpy(&connect.vht_capa_mask, |
| 7222 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), |
| 7223 | sizeof(connect.vht_capa_mask)); |
| 7224 | |
| 7225 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { |
| 7226 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) { |
| 7227 | kfree(connkeys); |
| 7228 | return -EINVAL; |
| 7229 | } |
| 7230 | memcpy(&connect.vht_capa, |
| 7231 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), |
| 7232 | sizeof(connect.vht_capa)); |
| 7233 | } |
| 7234 | |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7235 | wdev_lock(dev->ieee80211_ptr); |
| 7236 | err = cfg80211_connect(rdev, dev, &connect, connkeys, NULL); |
| 7237 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7238 | if (err) |
| 7239 | kfree(connkeys); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7240 | return err; |
| 7241 | } |
| 7242 | |
| 7243 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) |
| 7244 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7245 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7246 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7247 | u16 reason; |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7248 | int ret; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7249 | |
| 7250 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 7251 | reason = WLAN_REASON_DEAUTH_LEAVING; |
| 7252 | else |
| 7253 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 7254 | |
| 7255 | if (reason == 0) |
| 7256 | return -EINVAL; |
| 7257 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7258 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7259 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7260 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7261 | |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7262 | wdev_lock(dev->ieee80211_ptr); |
| 7263 | ret = cfg80211_disconnect(rdev, dev, reason, true); |
| 7264 | wdev_unlock(dev->ieee80211_ptr); |
| 7265 | return ret; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7266 | } |
| 7267 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7268 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
| 7269 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7270 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7271 | struct net *net; |
| 7272 | int err; |
| 7273 | u32 pid; |
| 7274 | |
| 7275 | if (!info->attrs[NL80211_ATTR_PID]) |
| 7276 | return -EINVAL; |
| 7277 | |
| 7278 | pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); |
| 7279 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7280 | net = get_net_ns_by_pid(pid); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7281 | if (IS_ERR(net)) |
| 7282 | return PTR_ERR(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7283 | |
| 7284 | err = 0; |
| 7285 | |
| 7286 | /* check if anything to do */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7287 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
| 7288 | err = cfg80211_switch_netns(rdev, net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7289 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7290 | put_net(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7291 | return err; |
| 7292 | } |
| 7293 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7294 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 7295 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7296 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7297 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
| 7298 | struct cfg80211_pmksa *pmksa) = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7299 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7300 | struct cfg80211_pmksa pmksa; |
| 7301 | |
| 7302 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); |
| 7303 | |
| 7304 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 7305 | return -EINVAL; |
| 7306 | |
| 7307 | if (!info->attrs[NL80211_ATTR_PMKID]) |
| 7308 | return -EINVAL; |
| 7309 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7310 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
| 7311 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 7312 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7313 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7314 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7315 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7316 | |
| 7317 | switch (info->genlhdr->cmd) { |
| 7318 | case NL80211_CMD_SET_PMKSA: |
| 7319 | rdev_ops = rdev->ops->set_pmksa; |
| 7320 | break; |
| 7321 | case NL80211_CMD_DEL_PMKSA: |
| 7322 | rdev_ops = rdev->ops->del_pmksa; |
| 7323 | break; |
| 7324 | default: |
| 7325 | WARN_ON(1); |
| 7326 | break; |
| 7327 | } |
| 7328 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7329 | if (!rdev_ops) |
| 7330 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7331 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7332 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7333 | } |
| 7334 | |
| 7335 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 7336 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7337 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7338 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7339 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7340 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7341 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7342 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7343 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7344 | if (!rdev->ops->flush_pmksa) |
| 7345 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7346 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7347 | return rdev_flush_pmksa(rdev, dev); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7348 | } |
| 7349 | |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7350 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) |
| 7351 | { |
| 7352 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7353 | struct net_device *dev = info->user_ptr[1]; |
| 7354 | u8 action_code, dialog_token; |
Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 7355 | u32 peer_capability = 0; |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7356 | u16 status_code; |
| 7357 | u8 *peer; |
Arik Nemtsov | 31fa97c | 2014-06-11 17:18:21 +0300 | [diff] [blame] | 7358 | bool initiator; |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7359 | |
| 7360 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 7361 | !rdev->ops->tdls_mgmt) |
| 7362 | return -EOPNOTSUPP; |
| 7363 | |
| 7364 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || |
| 7365 | !info->attrs[NL80211_ATTR_STATUS_CODE] || |
| 7366 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || |
| 7367 | !info->attrs[NL80211_ATTR_IE] || |
| 7368 | !info->attrs[NL80211_ATTR_MAC]) |
| 7369 | return -EINVAL; |
| 7370 | |
| 7371 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 7372 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); |
| 7373 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); |
| 7374 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); |
Arik Nemtsov | 31fa97c | 2014-06-11 17:18:21 +0300 | [diff] [blame] | 7375 | initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]); |
Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 7376 | if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]) |
| 7377 | peer_capability = |
| 7378 | nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7379 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7380 | return rdev_tdls_mgmt(rdev, dev, peer, action_code, |
Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 7381 | dialog_token, status_code, peer_capability, |
Arik Nemtsov | 31fa97c | 2014-06-11 17:18:21 +0300 | [diff] [blame] | 7382 | initiator, |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7383 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 7384 | nla_len(info->attrs[NL80211_ATTR_IE])); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7385 | } |
| 7386 | |
| 7387 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) |
| 7388 | { |
| 7389 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7390 | struct net_device *dev = info->user_ptr[1]; |
| 7391 | enum nl80211_tdls_operation operation; |
| 7392 | u8 *peer; |
| 7393 | |
| 7394 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 7395 | !rdev->ops->tdls_oper) |
| 7396 | return -EOPNOTSUPP; |
| 7397 | |
| 7398 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || |
| 7399 | !info->attrs[NL80211_ATTR_MAC]) |
| 7400 | return -EINVAL; |
| 7401 | |
| 7402 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); |
| 7403 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 7404 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7405 | return rdev_tdls_oper(rdev, dev, peer, operation); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7406 | } |
| 7407 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7408 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
| 7409 | struct genl_info *info) |
| 7410 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7411 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7412 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7413 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7414 | struct sk_buff *msg; |
| 7415 | void *hdr; |
| 7416 | u64 cookie; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7417 | u32 duration; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7418 | int err; |
| 7419 | |
| 7420 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 7421 | !info->attrs[NL80211_ATTR_DURATION]) |
| 7422 | return -EINVAL; |
| 7423 | |
| 7424 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
| 7425 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 7426 | if (!rdev->ops->remain_on_channel || |
| 7427 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7428 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7429 | |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 7430 | /* |
| 7431 | * We should be on that channel for at least a minimum amount of |
| 7432 | * time (10ms) but no longer than the driver supports. |
| 7433 | */ |
| 7434 | if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 7435 | duration > rdev->wiphy.max_remain_on_channel_duration) |
| 7436 | return -EINVAL; |
| 7437 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7438 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 7439 | if (err) |
| 7440 | return err; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7441 | |
| 7442 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7443 | if (!msg) |
| 7444 | return -ENOMEM; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7445 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7446 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7447 | NL80211_CMD_REMAIN_ON_CHANNEL); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 7448 | if (!hdr) { |
| 7449 | err = -ENOBUFS; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7450 | goto free_msg; |
| 7451 | } |
| 7452 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7453 | err = rdev_remain_on_channel(rdev, wdev, chandef.chan, |
| 7454 | duration, &cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7455 | |
| 7456 | if (err) |
| 7457 | goto free_msg; |
| 7458 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7459 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 7460 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7461 | |
| 7462 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7463 | |
| 7464 | return genlmsg_reply(msg, info); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7465 | |
| 7466 | nla_put_failure: |
| 7467 | err = -ENOBUFS; |
| 7468 | free_msg: |
| 7469 | nlmsg_free(msg); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7470 | return err; |
| 7471 | } |
| 7472 | |
| 7473 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, |
| 7474 | struct genl_info *info) |
| 7475 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7476 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7477 | struct wireless_dev *wdev = info->user_ptr[1]; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7478 | u64 cookie; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7479 | |
| 7480 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 7481 | return -EINVAL; |
| 7482 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7483 | if (!rdev->ops->cancel_remain_on_channel) |
| 7484 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7485 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7486 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 7487 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7488 | return rdev_cancel_remain_on_channel(rdev, wdev, cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7489 | } |
| 7490 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7491 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
| 7492 | u8 *rates, u8 rates_len) |
| 7493 | { |
| 7494 | u8 i; |
| 7495 | u32 mask = 0; |
| 7496 | |
| 7497 | for (i = 0; i < rates_len; i++) { |
| 7498 | int rate = (rates[i] & 0x7f) * 5; |
| 7499 | int ridx; |
| 7500 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { |
| 7501 | struct ieee80211_rate *srate = |
| 7502 | &sband->bitrates[ridx]; |
| 7503 | if (rate == srate->bitrate) { |
| 7504 | mask |= 1 << ridx; |
| 7505 | break; |
| 7506 | } |
| 7507 | } |
| 7508 | if (ridx == sband->n_bitrates) |
| 7509 | return 0; /* rate not found */ |
| 7510 | } |
| 7511 | |
| 7512 | return mask; |
| 7513 | } |
| 7514 | |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7515 | static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, |
| 7516 | u8 *rates, u8 rates_len, |
| 7517 | u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) |
| 7518 | { |
| 7519 | u8 i; |
| 7520 | |
| 7521 | memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); |
| 7522 | |
| 7523 | for (i = 0; i < rates_len; i++) { |
| 7524 | int ridx, rbit; |
| 7525 | |
| 7526 | ridx = rates[i] / 8; |
| 7527 | rbit = BIT(rates[i] % 8); |
| 7528 | |
| 7529 | /* check validity */ |
Dan Carpenter | 910570b5 | 2012-02-01 10:42:11 +0300 | [diff] [blame] | 7530 | if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7531 | return false; |
| 7532 | |
| 7533 | /* check availability */ |
| 7534 | if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) |
| 7535 | mcs[ridx] |= rbit; |
| 7536 | else |
| 7537 | return false; |
| 7538 | } |
| 7539 | |
| 7540 | return true; |
| 7541 | } |
| 7542 | |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 7543 | static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map) |
| 7544 | { |
| 7545 | u16 mcs_mask = 0; |
| 7546 | |
| 7547 | switch (vht_mcs_map) { |
| 7548 | case IEEE80211_VHT_MCS_NOT_SUPPORTED: |
| 7549 | break; |
| 7550 | case IEEE80211_VHT_MCS_SUPPORT_0_7: |
| 7551 | mcs_mask = 0x00FF; |
| 7552 | break; |
| 7553 | case IEEE80211_VHT_MCS_SUPPORT_0_8: |
| 7554 | mcs_mask = 0x01FF; |
| 7555 | break; |
| 7556 | case IEEE80211_VHT_MCS_SUPPORT_0_9: |
| 7557 | mcs_mask = 0x03FF; |
| 7558 | break; |
| 7559 | default: |
| 7560 | break; |
| 7561 | } |
| 7562 | |
| 7563 | return mcs_mask; |
| 7564 | } |
| 7565 | |
| 7566 | static void vht_build_mcs_mask(u16 vht_mcs_map, |
| 7567 | u16 vht_mcs_mask[NL80211_VHT_NSS_MAX]) |
| 7568 | { |
| 7569 | u8 nss; |
| 7570 | |
| 7571 | for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) { |
| 7572 | vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03); |
| 7573 | vht_mcs_map >>= 2; |
| 7574 | } |
| 7575 | } |
| 7576 | |
| 7577 | static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband, |
| 7578 | struct nl80211_txrate_vht *txrate, |
| 7579 | u16 mcs[NL80211_VHT_NSS_MAX]) |
| 7580 | { |
| 7581 | u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); |
| 7582 | u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {}; |
| 7583 | u8 i; |
| 7584 | |
| 7585 | if (!sband->vht_cap.vht_supported) |
| 7586 | return false; |
| 7587 | |
| 7588 | memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX); |
| 7589 | |
| 7590 | /* Build vht_mcs_mask from VHT capabilities */ |
| 7591 | vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask); |
| 7592 | |
| 7593 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) { |
| 7594 | if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i]) |
| 7595 | mcs[i] = txrate->mcs[i]; |
| 7596 | else |
| 7597 | return false; |
| 7598 | } |
| 7599 | |
| 7600 | return true; |
| 7601 | } |
| 7602 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 7603 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7604 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
| 7605 | .len = NL80211_MAX_SUPP_RATES }, |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 7606 | [NL80211_TXRATE_HT] = { .type = NLA_BINARY, |
| 7607 | .len = NL80211_MAX_SUPP_HT_RATES }, |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 7608 | [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)}, |
Janusz Dziedzic | 0b9323f | 2014-01-08 08:46:02 +0100 | [diff] [blame] | 7609 | [NL80211_TXRATE_GI] = { .type = NLA_U8 }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7610 | }; |
| 7611 | |
| 7612 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, |
| 7613 | struct genl_info *info) |
| 7614 | { |
| 7615 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7616 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7617 | struct cfg80211_bitrate_mask mask; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7618 | int rem, i; |
| 7619 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7620 | struct nlattr *tx_rates; |
| 7621 | struct ieee80211_supported_band *sband; |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 7622 | u16 vht_tx_mcs_map; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7623 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7624 | if (!rdev->ops->set_bitrate_mask) |
| 7625 | return -EOPNOTSUPP; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7626 | |
| 7627 | memset(&mask, 0, sizeof(mask)); |
| 7628 | /* Default to all rates enabled */ |
| 7629 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) { |
| 7630 | sband = rdev->wiphy.bands[i]; |
Janusz Dziedzic | 7869303 | 2013-12-03 09:50:44 +0100 | [diff] [blame] | 7631 | |
| 7632 | if (!sband) |
| 7633 | continue; |
| 7634 | |
| 7635 | mask.control[i].legacy = (1 << sband->n_bitrates) - 1; |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 7636 | memcpy(mask.control[i].ht_mcs, |
Janusz Dziedzic | 7869303 | 2013-12-03 09:50:44 +0100 | [diff] [blame] | 7637 | sband->ht_cap.mcs.rx_mask, |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 7638 | sizeof(mask.control[i].ht_mcs)); |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 7639 | |
| 7640 | if (!sband->vht_cap.vht_supported) |
| 7641 | continue; |
| 7642 | |
| 7643 | vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); |
| 7644 | 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] | 7645 | } |
| 7646 | |
Janusz Dziedzic | b9243ab | 2013-12-05 10:02:14 +0100 | [diff] [blame] | 7647 | /* if no rates are given set it back to the defaults */ |
| 7648 | if (!info->attrs[NL80211_ATTR_TX_RATES]) |
| 7649 | goto out; |
| 7650 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7651 | /* |
| 7652 | * The nested attribute uses enum nl80211_band as the index. This maps |
| 7653 | * directly to the enum ieee80211_band values used in cfg80211. |
| 7654 | */ |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7655 | 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] | 7656 | 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] | 7657 | enum ieee80211_band band = nla_type(tx_rates); |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 7658 | int err; |
| 7659 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7660 | if (band < 0 || band >= IEEE80211_NUM_BANDS) |
| 7661 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7662 | sband = rdev->wiphy.bands[band]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7663 | if (sband == NULL) |
| 7664 | return -EINVAL; |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 7665 | err = nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), |
| 7666 | nla_len(tx_rates), nl80211_txattr_policy); |
| 7667 | if (err) |
| 7668 | return err; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7669 | if (tb[NL80211_TXRATE_LEGACY]) { |
| 7670 | mask.control[band].legacy = rateset_to_mask( |
| 7671 | sband, |
| 7672 | nla_data(tb[NL80211_TXRATE_LEGACY]), |
| 7673 | nla_len(tb[NL80211_TXRATE_LEGACY])); |
Bala Shanmugam | 218d2e2 | 2012-04-20 19:12:58 +0530 | [diff] [blame] | 7674 | if ((mask.control[band].legacy == 0) && |
| 7675 | nla_len(tb[NL80211_TXRATE_LEGACY])) |
| 7676 | return -EINVAL; |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7677 | } |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 7678 | if (tb[NL80211_TXRATE_HT]) { |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7679 | if (!ht_rateset_to_mask( |
| 7680 | sband, |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 7681 | nla_data(tb[NL80211_TXRATE_HT]), |
| 7682 | nla_len(tb[NL80211_TXRATE_HT]), |
| 7683 | mask.control[band].ht_mcs)) |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7684 | return -EINVAL; |
| 7685 | } |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 7686 | if (tb[NL80211_TXRATE_VHT]) { |
| 7687 | if (!vht_set_mcs_mask( |
| 7688 | sband, |
| 7689 | nla_data(tb[NL80211_TXRATE_VHT]), |
| 7690 | mask.control[band].vht_mcs)) |
| 7691 | return -EINVAL; |
| 7692 | } |
Janusz Dziedzic | 0b9323f | 2014-01-08 08:46:02 +0100 | [diff] [blame] | 7693 | if (tb[NL80211_TXRATE_GI]) { |
| 7694 | mask.control[band].gi = |
| 7695 | nla_get_u8(tb[NL80211_TXRATE_GI]); |
| 7696 | if (mask.control[band].gi > NL80211_TXRATE_FORCE_LGI) |
| 7697 | return -EINVAL; |
| 7698 | } |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7699 | |
| 7700 | if (mask.control[band].legacy == 0) { |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 7701 | /* don't allow empty legacy rates if HT or VHT |
| 7702 | * are not even supported. |
| 7703 | */ |
| 7704 | if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported || |
| 7705 | rdev->wiphy.bands[band]->vht_cap.vht_supported)) |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7706 | return -EINVAL; |
| 7707 | |
| 7708 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 7709 | if (mask.control[band].ht_mcs[i]) |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 7710 | goto out; |
| 7711 | |
| 7712 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) |
| 7713 | if (mask.control[band].vht_mcs[i]) |
| 7714 | goto out; |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7715 | |
| 7716 | /* legacy and mcs rates may not be both empty */ |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 7717 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7718 | } |
| 7719 | } |
| 7720 | |
Janusz Dziedzic | b9243ab | 2013-12-05 10:02:14 +0100 | [diff] [blame] | 7721 | out: |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7722 | return rdev_set_bitrate_mask(rdev, dev, NULL, &mask); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7723 | } |
| 7724 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7725 | 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] | 7726 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7727 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7728 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7729 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7730 | |
| 7731 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) |
| 7732 | return -EINVAL; |
| 7733 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7734 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
| 7735 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7736 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7737 | switch (wdev->iftype) { |
| 7738 | case NL80211_IFTYPE_STATION: |
| 7739 | case NL80211_IFTYPE_ADHOC: |
| 7740 | case NL80211_IFTYPE_P2P_CLIENT: |
| 7741 | case NL80211_IFTYPE_AP: |
| 7742 | case NL80211_IFTYPE_AP_VLAN: |
| 7743 | case NL80211_IFTYPE_MESH_POINT: |
| 7744 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7745 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7746 | break; |
| 7747 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7748 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7749 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7750 | |
| 7751 | /* not much point in registering if we can't reply */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7752 | if (!rdev->ops->mgmt_tx) |
| 7753 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7754 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7755 | return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7756 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
| 7757 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7758 | } |
| 7759 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7760 | 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] | 7761 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7762 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7763 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7764 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7765 | int err; |
Johannes Berg | d64d373 | 2011-11-10 09:44:46 +0100 | [diff] [blame] | 7766 | void *hdr = NULL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7767 | u64 cookie; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7768 | struct sk_buff *msg = NULL; |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7769 | struct cfg80211_mgmt_tx_params params = { |
| 7770 | .dont_wait_for_ack = |
| 7771 | info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK], |
| 7772 | }; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7773 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7774 | if (!info->attrs[NL80211_ATTR_FRAME]) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7775 | return -EINVAL; |
| 7776 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7777 | if (!rdev->ops->mgmt_tx) |
| 7778 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7779 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7780 | switch (wdev->iftype) { |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 7781 | case NL80211_IFTYPE_P2P_DEVICE: |
| 7782 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 7783 | return -EINVAL; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7784 | case NL80211_IFTYPE_STATION: |
| 7785 | case NL80211_IFTYPE_ADHOC: |
| 7786 | case NL80211_IFTYPE_P2P_CLIENT: |
| 7787 | case NL80211_IFTYPE_AP: |
| 7788 | case NL80211_IFTYPE_AP_VLAN: |
| 7789 | case NL80211_IFTYPE_MESH_POINT: |
| 7790 | case NL80211_IFTYPE_P2P_GO: |
| 7791 | break; |
| 7792 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7793 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7794 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7795 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7796 | if (info->attrs[NL80211_ATTR_DURATION]) { |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 7797 | if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7798 | return -EINVAL; |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7799 | params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 7800 | |
| 7801 | /* |
| 7802 | * We should wait on the channel for at least a minimum amount |
| 7803 | * of time (10ms) but no longer than the driver supports. |
| 7804 | */ |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7805 | if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 7806 | params.wait > rdev->wiphy.max_remain_on_channel_duration) |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 7807 | return -EINVAL; |
| 7808 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7809 | } |
| 7810 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7811 | params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7812 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7813 | if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 7814 | return -EINVAL; |
| 7815 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7816 | 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] | 7817 | |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 7818 | /* get the channel if any has been specified, otherwise pass NULL to |
| 7819 | * the driver. The latter will use the current one |
| 7820 | */ |
| 7821 | chandef.chan = NULL; |
| 7822 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 7823 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 7824 | if (err) |
| 7825 | return err; |
| 7826 | } |
| 7827 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7828 | if (!chandef.chan && params.offchan) |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 7829 | return -EINVAL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7830 | |
Andrei Otcheretianski | 34d22ce | 2014-05-09 14:11:44 +0300 | [diff] [blame] | 7831 | params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]); |
| 7832 | params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]); |
| 7833 | |
| 7834 | if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) { |
| 7835 | int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]); |
| 7836 | int i; |
| 7837 | |
| 7838 | if (len % sizeof(u16)) |
| 7839 | return -EINVAL; |
| 7840 | |
| 7841 | params.n_csa_offsets = len / sizeof(u16); |
| 7842 | params.csa_offsets = |
| 7843 | nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]); |
| 7844 | |
| 7845 | /* check that all the offsets fit the frame */ |
| 7846 | for (i = 0; i < params.n_csa_offsets; i++) { |
| 7847 | if (params.csa_offsets[i] >= params.len) |
| 7848 | return -EINVAL; |
| 7849 | } |
| 7850 | } |
| 7851 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7852 | if (!params.dont_wait_for_ack) { |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7853 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 7854 | if (!msg) |
| 7855 | return -ENOMEM; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7856 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7857 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7858 | NL80211_CMD_FRAME); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 7859 | if (!hdr) { |
| 7860 | err = -ENOBUFS; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7861 | goto free_msg; |
| 7862 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7863 | } |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7864 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7865 | params.chan = chandef.chan; |
| 7866 | err = cfg80211_mlme_mgmt_tx(rdev, wdev, ¶ms, &cookie); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7867 | if (err) |
| 7868 | goto free_msg; |
| 7869 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7870 | if (msg) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7871 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 7872 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7873 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7874 | genlmsg_end(msg, hdr); |
| 7875 | return genlmsg_reply(msg, info); |
| 7876 | } |
| 7877 | |
| 7878 | return 0; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7879 | |
| 7880 | nla_put_failure: |
| 7881 | err = -ENOBUFS; |
| 7882 | free_msg: |
| 7883 | nlmsg_free(msg); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7884 | return err; |
| 7885 | } |
| 7886 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7887 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
| 7888 | { |
| 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 | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7891 | u64 cookie; |
| 7892 | |
| 7893 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 7894 | return -EINVAL; |
| 7895 | |
| 7896 | if (!rdev->ops->mgmt_tx_cancel_wait) |
| 7897 | return -EOPNOTSUPP; |
| 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_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7906 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7907 | break; |
| 7908 | default: |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7909 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7910 | } |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7911 | |
| 7912 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 7913 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7914 | return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie); |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7915 | } |
| 7916 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7917 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
| 7918 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7919 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7920 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7921 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7922 | u8 ps_state; |
| 7923 | bool state; |
| 7924 | int err; |
| 7925 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7926 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
| 7927 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7928 | |
| 7929 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); |
| 7930 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7931 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
| 7932 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7933 | |
| 7934 | wdev = dev->ieee80211_ptr; |
| 7935 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7936 | if (!rdev->ops->set_power_mgmt) |
| 7937 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7938 | |
| 7939 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; |
| 7940 | |
| 7941 | if (state == wdev->ps) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7942 | return 0; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7943 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7944 | err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7945 | if (!err) |
| 7946 | wdev->ps = state; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7947 | return err; |
| 7948 | } |
| 7949 | |
| 7950 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) |
| 7951 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7952 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7953 | enum nl80211_ps_state ps_state; |
| 7954 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7955 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7956 | struct sk_buff *msg; |
| 7957 | void *hdr; |
| 7958 | int err; |
| 7959 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7960 | wdev = dev->ieee80211_ptr; |
| 7961 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7962 | if (!rdev->ops->set_power_mgmt) |
| 7963 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7964 | |
| 7965 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7966 | if (!msg) |
| 7967 | return -ENOMEM; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7968 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7969 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7970 | NL80211_CMD_GET_POWER_SAVE); |
| 7971 | if (!hdr) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7972 | err = -ENOBUFS; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7973 | goto free_msg; |
| 7974 | } |
| 7975 | |
| 7976 | if (wdev->ps) |
| 7977 | ps_state = NL80211_PS_ENABLED; |
| 7978 | else |
| 7979 | ps_state = NL80211_PS_DISABLED; |
| 7980 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7981 | if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) |
| 7982 | goto nla_put_failure; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7983 | |
| 7984 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7985 | return genlmsg_reply(msg, info); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7986 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7987 | nla_put_failure: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7988 | err = -ENOBUFS; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7989 | free_msg: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7990 | nlmsg_free(msg); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7991 | return err; |
| 7992 | } |
| 7993 | |
Johannes Berg | 94e860f | 2014-01-20 23:58:15 +0100 | [diff] [blame] | 7994 | static const struct nla_policy |
| 7995 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = { |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7996 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, |
| 7997 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, |
| 7998 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7999 | [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 }, |
| 8000 | [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 }, |
| 8001 | [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8002 | }; |
| 8003 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 8004 | static int nl80211_set_cqm_txe(struct genl_info *info, |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 8005 | u32 rate, u32 pkts, u32 intvl) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 8006 | { |
| 8007 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 8008 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 8009 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 8010 | |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 8011 | if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 8012 | return -EINVAL; |
| 8013 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 8014 | if (!rdev->ops->set_cqm_txe_config) |
| 8015 | return -EOPNOTSUPP; |
| 8016 | |
| 8017 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
| 8018 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 8019 | return -EOPNOTSUPP; |
| 8020 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8021 | return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 8022 | } |
| 8023 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8024 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
| 8025 | s32 threshold, u32 hysteresis) |
| 8026 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8027 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8028 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 8029 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8030 | |
| 8031 | if (threshold > 0) |
| 8032 | return -EINVAL; |
| 8033 | |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 8034 | /* disabling - hysteresis should also be zero then */ |
| 8035 | if (threshold == 0) |
| 8036 | hysteresis = 0; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8037 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8038 | if (!rdev->ops->set_cqm_rssi_config) |
| 8039 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8040 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 8041 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8042 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 8043 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8044 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8045 | return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8046 | } |
| 8047 | |
| 8048 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) |
| 8049 | { |
| 8050 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; |
| 8051 | struct nlattr *cqm; |
| 8052 | int err; |
| 8053 | |
| 8054 | cqm = info->attrs[NL80211_ATTR_CQM]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 8055 | if (!cqm) |
| 8056 | return -EINVAL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8057 | |
| 8058 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, |
| 8059 | nl80211_attr_cqm_policy); |
| 8060 | if (err) |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 8061 | return err; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8062 | |
| 8063 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && |
| 8064 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 8065 | s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
| 8066 | u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8067 | |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 8068 | return nl80211_set_cqm_rssi(info, threshold, hysteresis); |
| 8069 | } |
| 8070 | |
| 8071 | if (attrs[NL80211_ATTR_CQM_TXE_RATE] && |
| 8072 | attrs[NL80211_ATTR_CQM_TXE_PKTS] && |
| 8073 | attrs[NL80211_ATTR_CQM_TXE_INTVL]) { |
| 8074 | u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]); |
| 8075 | u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]); |
| 8076 | u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]); |
| 8077 | |
| 8078 | return nl80211_set_cqm_txe(info, rate, pkts, intvl); |
| 8079 | } |
| 8080 | |
| 8081 | return -EINVAL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8082 | } |
| 8083 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8084 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
| 8085 | { |
| 8086 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8087 | struct net_device *dev = info->user_ptr[1]; |
| 8088 | struct mesh_config cfg; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 8089 | struct mesh_setup setup; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8090 | int err; |
| 8091 | |
| 8092 | /* start with default */ |
| 8093 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 8094 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8095 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 8096 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8097 | /* and parse parameters if given */ |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 8098 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8099 | if (err) |
| 8100 | return err; |
| 8101 | } |
| 8102 | |
| 8103 | if (!info->attrs[NL80211_ATTR_MESH_ID] || |
| 8104 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) |
| 8105 | return -EINVAL; |
| 8106 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 8107 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
| 8108 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 8109 | |
Chun-Yeow Yeoh | 4bb6234 | 2011-11-24 17:15:20 -0800 | [diff] [blame] | 8110 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 8111 | !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, |
| 8112 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 8113 | return -EINVAL; |
| 8114 | |
Marco Porsch | 9bdbf04 | 2013-01-07 16:04:51 +0100 | [diff] [blame] | 8115 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 8116 | setup.beacon_interval = |
| 8117 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 8118 | if (setup.beacon_interval < 10 || |
| 8119 | setup.beacon_interval > 10000) |
| 8120 | return -EINVAL; |
| 8121 | } |
| 8122 | |
| 8123 | if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) { |
| 8124 | setup.dtim_period = |
| 8125 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 8126 | if (setup.dtim_period < 1 || setup.dtim_period > 100) |
| 8127 | return -EINVAL; |
| 8128 | } |
| 8129 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 8130 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
| 8131 | /* parse additional setup parameters if given */ |
| 8132 | err = nl80211_parse_mesh_setup(info, &setup); |
| 8133 | if (err) |
| 8134 | return err; |
| 8135 | } |
| 8136 | |
Thomas Pedersen | d37bb18 | 2013-03-04 13:06:13 -0800 | [diff] [blame] | 8137 | if (setup.user_mpm) |
| 8138 | cfg.auto_open_plinks = false; |
| 8139 | |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 8140 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 8141 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
| 8142 | if (err) |
| 8143 | return err; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 8144 | } else { |
| 8145 | /* cfg80211_join_mesh() will sort it out */ |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 8146 | setup.chandef.chan = NULL; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 8147 | } |
| 8148 | |
Ashok Nagarajan | ffb3cf3 | 2013-06-03 10:33:36 -0700 | [diff] [blame] | 8149 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 8150 | u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 8151 | int n_rates = |
| 8152 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 8153 | struct ieee80211_supported_band *sband; |
| 8154 | |
| 8155 | if (!setup.chandef.chan) |
| 8156 | return -EINVAL; |
| 8157 | |
| 8158 | sband = rdev->wiphy.bands[setup.chandef.chan->band]; |
| 8159 | |
| 8160 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 8161 | &setup.basic_rates); |
| 8162 | if (err) |
| 8163 | return err; |
| 8164 | } |
| 8165 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 8166 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8167 | } |
| 8168 | |
| 8169 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) |
| 8170 | { |
| 8171 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8172 | struct net_device *dev = info->user_ptr[1]; |
| 8173 | |
| 8174 | return cfg80211_leave_mesh(rdev, dev); |
| 8175 | } |
| 8176 | |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 8177 | #ifdef CONFIG_PM |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8178 | static int nl80211_send_wowlan_patterns(struct sk_buff *msg, |
| 8179 | struct cfg80211_registered_device *rdev) |
| 8180 | { |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8181 | struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config; |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8182 | struct nlattr *nl_pats, *nl_pat; |
| 8183 | int i, pat_len; |
| 8184 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8185 | if (!wowlan->n_patterns) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8186 | return 0; |
| 8187 | |
| 8188 | nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN); |
| 8189 | if (!nl_pats) |
| 8190 | return -ENOBUFS; |
| 8191 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8192 | for (i = 0; i < wowlan->n_patterns; i++) { |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8193 | nl_pat = nla_nest_start(msg, i + 1); |
| 8194 | if (!nl_pat) |
| 8195 | return -ENOBUFS; |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8196 | pat_len = wowlan->patterns[i].pattern_len; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8197 | 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] | 8198 | wowlan->patterns[i].mask) || |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8199 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
| 8200 | wowlan->patterns[i].pattern) || |
| 8201 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8202 | wowlan->patterns[i].pkt_offset)) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8203 | return -ENOBUFS; |
| 8204 | nla_nest_end(msg, nl_pat); |
| 8205 | } |
| 8206 | nla_nest_end(msg, nl_pats); |
| 8207 | |
| 8208 | return 0; |
| 8209 | } |
| 8210 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8211 | static int nl80211_send_wowlan_tcp(struct sk_buff *msg, |
| 8212 | struct cfg80211_wowlan_tcp *tcp) |
| 8213 | { |
| 8214 | struct nlattr *nl_tcp; |
| 8215 | |
| 8216 | if (!tcp) |
| 8217 | return 0; |
| 8218 | |
| 8219 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); |
| 8220 | if (!nl_tcp) |
| 8221 | return -ENOBUFS; |
| 8222 | |
| 8223 | if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) || |
| 8224 | nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) || |
| 8225 | nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) || |
| 8226 | nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) || |
| 8227 | nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) || |
| 8228 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 8229 | tcp->payload_len, tcp->payload) || |
| 8230 | nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, |
| 8231 | tcp->data_interval) || |
| 8232 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, |
| 8233 | tcp->wake_len, tcp->wake_data) || |
| 8234 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK, |
| 8235 | DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask)) |
| 8236 | return -ENOBUFS; |
| 8237 | |
| 8238 | if (tcp->payload_seq.len && |
| 8239 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ, |
| 8240 | sizeof(tcp->payload_seq), &tcp->payload_seq)) |
| 8241 | return -ENOBUFS; |
| 8242 | |
| 8243 | if (tcp->payload_tok.len && |
| 8244 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, |
| 8245 | sizeof(tcp->payload_tok) + tcp->tokens_size, |
| 8246 | &tcp->payload_tok)) |
| 8247 | return -ENOBUFS; |
| 8248 | |
Johannes Berg | e248ad3 | 2013-05-16 10:24:28 +0200 | [diff] [blame] | 8249 | nla_nest_end(msg, nl_tcp); |
| 8250 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8251 | return 0; |
| 8252 | } |
| 8253 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8254 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 8255 | { |
| 8256 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8257 | struct sk_buff *msg; |
| 8258 | void *hdr; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8259 | u32 size = NLMSG_DEFAULT_SIZE; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8260 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8261 | if (!rdev->wiphy.wowlan) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8262 | return -EOPNOTSUPP; |
| 8263 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8264 | if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) { |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8265 | /* adjust size to have room for all the data */ |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8266 | size += rdev->wiphy.wowlan_config->tcp->tokens_size + |
| 8267 | rdev->wiphy.wowlan_config->tcp->payload_len + |
| 8268 | rdev->wiphy.wowlan_config->tcp->wake_len + |
| 8269 | rdev->wiphy.wowlan_config->tcp->wake_len / 8; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8270 | } |
| 8271 | |
| 8272 | msg = nlmsg_new(size, GFP_KERNEL); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8273 | if (!msg) |
| 8274 | return -ENOMEM; |
| 8275 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8276 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8277 | NL80211_CMD_GET_WOWLAN); |
| 8278 | if (!hdr) |
| 8279 | goto nla_put_failure; |
| 8280 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8281 | if (rdev->wiphy.wowlan_config) { |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8282 | struct nlattr *nl_wowlan; |
| 8283 | |
| 8284 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
| 8285 | if (!nl_wowlan) |
| 8286 | goto nla_put_failure; |
| 8287 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8288 | if ((rdev->wiphy.wowlan_config->any && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8289 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8290 | (rdev->wiphy.wowlan_config->disconnect && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8291 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8292 | (rdev->wiphy.wowlan_config->magic_pkt && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8293 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8294 | (rdev->wiphy.wowlan_config->gtk_rekey_failure && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8295 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8296 | (rdev->wiphy.wowlan_config->eap_identity_req && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8297 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8298 | (rdev->wiphy.wowlan_config->four_way_handshake && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8299 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8300 | (rdev->wiphy.wowlan_config->rfkill_release && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8301 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 8302 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8303 | |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8304 | if (nl80211_send_wowlan_patterns(msg, rdev)) |
| 8305 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8306 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8307 | if (nl80211_send_wowlan_tcp(msg, |
| 8308 | rdev->wiphy.wowlan_config->tcp)) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8309 | goto nla_put_failure; |
| 8310 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8311 | nla_nest_end(msg, nl_wowlan); |
| 8312 | } |
| 8313 | |
| 8314 | genlmsg_end(msg, hdr); |
| 8315 | return genlmsg_reply(msg, info); |
| 8316 | |
| 8317 | nla_put_failure: |
| 8318 | nlmsg_free(msg); |
| 8319 | return -ENOBUFS; |
| 8320 | } |
| 8321 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8322 | static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev, |
| 8323 | struct nlattr *attr, |
| 8324 | struct cfg80211_wowlan *trig) |
| 8325 | { |
| 8326 | struct nlattr *tb[NUM_NL80211_WOWLAN_TCP]; |
| 8327 | struct cfg80211_wowlan_tcp *cfg; |
| 8328 | struct nl80211_wowlan_tcp_data_token *tok = NULL; |
| 8329 | struct nl80211_wowlan_tcp_data_seq *seq = NULL; |
| 8330 | u32 size; |
| 8331 | u32 data_size, wake_size, tokens_size = 0, wake_mask_size; |
| 8332 | int err, port; |
| 8333 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8334 | if (!rdev->wiphy.wowlan->tcp) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8335 | return -EINVAL; |
| 8336 | |
| 8337 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP, |
| 8338 | nla_data(attr), nla_len(attr), |
| 8339 | nl80211_wowlan_tcp_policy); |
| 8340 | if (err) |
| 8341 | return err; |
| 8342 | |
| 8343 | if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] || |
| 8344 | !tb[NL80211_WOWLAN_TCP_DST_IPV4] || |
| 8345 | !tb[NL80211_WOWLAN_TCP_DST_MAC] || |
| 8346 | !tb[NL80211_WOWLAN_TCP_DST_PORT] || |
| 8347 | !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] || |
| 8348 | !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] || |
| 8349 | !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] || |
| 8350 | !tb[NL80211_WOWLAN_TCP_WAKE_MASK]) |
| 8351 | return -EINVAL; |
| 8352 | |
| 8353 | data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8354 | if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8355 | return -EINVAL; |
| 8356 | |
| 8357 | if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) > |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8358 | rdev->wiphy.wowlan->tcp->data_interval_max || |
Johannes Berg | 723d568 | 2013-02-26 13:56:40 +0100 | [diff] [blame] | 8359 | nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8360 | return -EINVAL; |
| 8361 | |
| 8362 | wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8363 | if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8364 | return -EINVAL; |
| 8365 | |
| 8366 | wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]); |
| 8367 | if (wake_mask_size != DIV_ROUND_UP(wake_size, 8)) |
| 8368 | return -EINVAL; |
| 8369 | |
| 8370 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) { |
| 8371 | u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 8372 | |
| 8373 | tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 8374 | tokens_size = tokln - sizeof(*tok); |
| 8375 | |
| 8376 | if (!tok->len || tokens_size % tok->len) |
| 8377 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8378 | if (!rdev->wiphy.wowlan->tcp->tok) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8379 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8380 | if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8381 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8382 | if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8383 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8384 | if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8385 | return -EINVAL; |
| 8386 | if (tok->offset + tok->len > data_size) |
| 8387 | return -EINVAL; |
| 8388 | } |
| 8389 | |
| 8390 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) { |
| 8391 | seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8392 | if (!rdev->wiphy.wowlan->tcp->seq) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8393 | return -EINVAL; |
| 8394 | if (seq->len == 0 || seq->len > 4) |
| 8395 | return -EINVAL; |
| 8396 | if (seq->len + seq->offset > data_size) |
| 8397 | return -EINVAL; |
| 8398 | } |
| 8399 | |
| 8400 | size = sizeof(*cfg); |
| 8401 | size += data_size; |
| 8402 | size += wake_size + wake_mask_size; |
| 8403 | size += tokens_size; |
| 8404 | |
| 8405 | cfg = kzalloc(size, GFP_KERNEL); |
| 8406 | if (!cfg) |
| 8407 | return -ENOMEM; |
| 8408 | cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]); |
| 8409 | cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]); |
| 8410 | memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]), |
| 8411 | ETH_ALEN); |
| 8412 | if (tb[NL80211_WOWLAN_TCP_SRC_PORT]) |
| 8413 | port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]); |
| 8414 | else |
| 8415 | port = 0; |
| 8416 | #ifdef CONFIG_INET |
| 8417 | /* allocate a socket and port for it and use it */ |
| 8418 | err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM, |
| 8419 | IPPROTO_TCP, &cfg->sock, 1); |
| 8420 | if (err) { |
| 8421 | kfree(cfg); |
| 8422 | return err; |
| 8423 | } |
| 8424 | if (inet_csk_get_port(cfg->sock->sk, port)) { |
| 8425 | sock_release(cfg->sock); |
| 8426 | kfree(cfg); |
| 8427 | return -EADDRINUSE; |
| 8428 | } |
| 8429 | cfg->src_port = inet_sk(cfg->sock->sk)->inet_num; |
| 8430 | #else |
| 8431 | if (!port) { |
| 8432 | kfree(cfg); |
| 8433 | return -EINVAL; |
| 8434 | } |
| 8435 | cfg->src_port = port; |
| 8436 | #endif |
| 8437 | |
| 8438 | cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]); |
| 8439 | cfg->payload_len = data_size; |
| 8440 | cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size; |
| 8441 | memcpy((void *)cfg->payload, |
| 8442 | nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]), |
| 8443 | data_size); |
| 8444 | if (seq) |
| 8445 | cfg->payload_seq = *seq; |
| 8446 | cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]); |
| 8447 | cfg->wake_len = wake_size; |
| 8448 | cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size; |
| 8449 | memcpy((void *)cfg->wake_data, |
| 8450 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]), |
| 8451 | wake_size); |
| 8452 | cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size + |
| 8453 | data_size + wake_size; |
| 8454 | memcpy((void *)cfg->wake_mask, |
| 8455 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]), |
| 8456 | wake_mask_size); |
| 8457 | if (tok) { |
| 8458 | cfg->tokens_size = tokens_size; |
| 8459 | memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size); |
| 8460 | } |
| 8461 | |
| 8462 | trig->tcp = cfg; |
| 8463 | |
| 8464 | return 0; |
| 8465 | } |
| 8466 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8467 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 8468 | { |
| 8469 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8470 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8471 | struct cfg80211_wowlan new_triggers = {}; |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8472 | struct cfg80211_wowlan *ntrig; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8473 | const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8474 | int err, i; |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8475 | bool prev_enabled = rdev->wiphy.wowlan_config; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8476 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8477 | if (!wowlan) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8478 | return -EOPNOTSUPP; |
| 8479 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8480 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) { |
| 8481 | cfg80211_rdev_free_wowlan(rdev); |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8482 | rdev->wiphy.wowlan_config = NULL; |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8483 | goto set_wakeup; |
| 8484 | } |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8485 | |
| 8486 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG, |
| 8487 | nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 8488 | nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 8489 | nl80211_wowlan_policy); |
| 8490 | if (err) |
| 8491 | return err; |
| 8492 | |
| 8493 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { |
| 8494 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) |
| 8495 | return -EINVAL; |
| 8496 | new_triggers.any = true; |
| 8497 | } |
| 8498 | |
| 8499 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { |
| 8500 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) |
| 8501 | return -EINVAL; |
| 8502 | new_triggers.disconnect = true; |
| 8503 | } |
| 8504 | |
| 8505 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { |
| 8506 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) |
| 8507 | return -EINVAL; |
| 8508 | new_triggers.magic_pkt = true; |
| 8509 | } |
| 8510 | |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 8511 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
| 8512 | return -EINVAL; |
| 8513 | |
| 8514 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { |
| 8515 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) |
| 8516 | return -EINVAL; |
| 8517 | new_triggers.gtk_rekey_failure = true; |
| 8518 | } |
| 8519 | |
| 8520 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { |
| 8521 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) |
| 8522 | return -EINVAL; |
| 8523 | new_triggers.eap_identity_req = true; |
| 8524 | } |
| 8525 | |
| 8526 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { |
| 8527 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) |
| 8528 | return -EINVAL; |
| 8529 | new_triggers.four_way_handshake = true; |
| 8530 | } |
| 8531 | |
| 8532 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { |
| 8533 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) |
| 8534 | return -EINVAL; |
| 8535 | new_triggers.rfkill_release = true; |
| 8536 | } |
| 8537 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8538 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
| 8539 | struct nlattr *pat; |
| 8540 | int n_patterns = 0; |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8541 | int rem, pat_len, mask_len, pkt_offset; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8542 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8543 | |
| 8544 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 8545 | rem) |
| 8546 | n_patterns++; |
| 8547 | if (n_patterns > wowlan->n_patterns) |
| 8548 | return -EINVAL; |
| 8549 | |
| 8550 | new_triggers.patterns = kcalloc(n_patterns, |
| 8551 | sizeof(new_triggers.patterns[0]), |
| 8552 | GFP_KERNEL); |
| 8553 | if (!new_triggers.patterns) |
| 8554 | return -ENOMEM; |
| 8555 | |
| 8556 | new_triggers.n_patterns = n_patterns; |
| 8557 | i = 0; |
| 8558 | |
| 8559 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 8560 | rem) { |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 8561 | u8 *mask_pat; |
| 8562 | |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8563 | nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat), |
| 8564 | nla_len(pat), NULL); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8565 | err = -EINVAL; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8566 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
| 8567 | !pat_tb[NL80211_PKTPAT_PATTERN]) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8568 | goto error; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8569 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8570 | mask_len = DIV_ROUND_UP(pat_len, 8); |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8571 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8572 | goto error; |
| 8573 | if (pat_len > wowlan->pattern_max_len || |
| 8574 | pat_len < wowlan->pattern_min_len) |
| 8575 | goto error; |
| 8576 | |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8577 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8578 | pkt_offset = 0; |
| 8579 | else |
| 8580 | pkt_offset = nla_get_u32( |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8581 | pat_tb[NL80211_PKTPAT_OFFSET]); |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8582 | if (pkt_offset > wowlan->max_pkt_offset) |
| 8583 | goto error; |
| 8584 | new_triggers.patterns[i].pkt_offset = pkt_offset; |
| 8585 | |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 8586 | mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 8587 | if (!mask_pat) { |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8588 | err = -ENOMEM; |
| 8589 | goto error; |
| 8590 | } |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 8591 | new_triggers.patterns[i].mask = mask_pat; |
| 8592 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]), |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8593 | mask_len); |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 8594 | mask_pat += mask_len; |
| 8595 | new_triggers.patterns[i].pattern = mask_pat; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8596 | new_triggers.patterns[i].pattern_len = pat_len; |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 8597 | memcpy(mask_pat, |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8598 | nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8599 | pat_len); |
| 8600 | i++; |
| 8601 | } |
| 8602 | } |
| 8603 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8604 | if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) { |
| 8605 | err = nl80211_parse_wowlan_tcp( |
| 8606 | rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION], |
| 8607 | &new_triggers); |
| 8608 | if (err) |
| 8609 | goto error; |
| 8610 | } |
| 8611 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8612 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL); |
| 8613 | if (!ntrig) { |
| 8614 | err = -ENOMEM; |
| 8615 | goto error; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8616 | } |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8617 | cfg80211_rdev_free_wowlan(rdev); |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8618 | rdev->wiphy.wowlan_config = ntrig; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8619 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8620 | set_wakeup: |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8621 | if (rdev->ops->set_wakeup && |
| 8622 | prev_enabled != !!rdev->wiphy.wowlan_config) |
| 8623 | rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config); |
Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame] | 8624 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8625 | return 0; |
| 8626 | error: |
| 8627 | for (i = 0; i < new_triggers.n_patterns; i++) |
| 8628 | kfree(new_triggers.patterns[i].mask); |
| 8629 | kfree(new_triggers.patterns); |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8630 | if (new_triggers.tcp && new_triggers.tcp->sock) |
| 8631 | sock_release(new_triggers.tcp->sock); |
| 8632 | kfree(new_triggers.tcp); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8633 | return err; |
| 8634 | } |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 8635 | #endif |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8636 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 8637 | static int nl80211_send_coalesce_rules(struct sk_buff *msg, |
| 8638 | struct cfg80211_registered_device *rdev) |
| 8639 | { |
| 8640 | struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules; |
| 8641 | int i, j, pat_len; |
| 8642 | struct cfg80211_coalesce_rules *rule; |
| 8643 | |
| 8644 | if (!rdev->coalesce->n_rules) |
| 8645 | return 0; |
| 8646 | |
| 8647 | nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE); |
| 8648 | if (!nl_rules) |
| 8649 | return -ENOBUFS; |
| 8650 | |
| 8651 | for (i = 0; i < rdev->coalesce->n_rules; i++) { |
| 8652 | nl_rule = nla_nest_start(msg, i + 1); |
| 8653 | if (!nl_rule) |
| 8654 | return -ENOBUFS; |
| 8655 | |
| 8656 | rule = &rdev->coalesce->rules[i]; |
| 8657 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY, |
| 8658 | rule->delay)) |
| 8659 | return -ENOBUFS; |
| 8660 | |
| 8661 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION, |
| 8662 | rule->condition)) |
| 8663 | return -ENOBUFS; |
| 8664 | |
| 8665 | nl_pats = nla_nest_start(msg, |
| 8666 | NL80211_ATTR_COALESCE_RULE_PKT_PATTERN); |
| 8667 | if (!nl_pats) |
| 8668 | return -ENOBUFS; |
| 8669 | |
| 8670 | for (j = 0; j < rule->n_patterns; j++) { |
| 8671 | nl_pat = nla_nest_start(msg, j + 1); |
| 8672 | if (!nl_pat) |
| 8673 | return -ENOBUFS; |
| 8674 | pat_len = rule->patterns[j].pattern_len; |
| 8675 | if (nla_put(msg, NL80211_PKTPAT_MASK, |
| 8676 | DIV_ROUND_UP(pat_len, 8), |
| 8677 | rule->patterns[j].mask) || |
| 8678 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
| 8679 | rule->patterns[j].pattern) || |
| 8680 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, |
| 8681 | rule->patterns[j].pkt_offset)) |
| 8682 | return -ENOBUFS; |
| 8683 | nla_nest_end(msg, nl_pat); |
| 8684 | } |
| 8685 | nla_nest_end(msg, nl_pats); |
| 8686 | nla_nest_end(msg, nl_rule); |
| 8687 | } |
| 8688 | nla_nest_end(msg, nl_rules); |
| 8689 | |
| 8690 | return 0; |
| 8691 | } |
| 8692 | |
| 8693 | static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info) |
| 8694 | { |
| 8695 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8696 | struct sk_buff *msg; |
| 8697 | void *hdr; |
| 8698 | |
| 8699 | if (!rdev->wiphy.coalesce) |
| 8700 | return -EOPNOTSUPP; |
| 8701 | |
| 8702 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 8703 | if (!msg) |
| 8704 | return -ENOMEM; |
| 8705 | |
| 8706 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 8707 | NL80211_CMD_GET_COALESCE); |
| 8708 | if (!hdr) |
| 8709 | goto nla_put_failure; |
| 8710 | |
| 8711 | if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev)) |
| 8712 | goto nla_put_failure; |
| 8713 | |
| 8714 | genlmsg_end(msg, hdr); |
| 8715 | return genlmsg_reply(msg, info); |
| 8716 | |
| 8717 | nla_put_failure: |
| 8718 | nlmsg_free(msg); |
| 8719 | return -ENOBUFS; |
| 8720 | } |
| 8721 | |
| 8722 | void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev) |
| 8723 | { |
| 8724 | struct cfg80211_coalesce *coalesce = rdev->coalesce; |
| 8725 | int i, j; |
| 8726 | struct cfg80211_coalesce_rules *rule; |
| 8727 | |
| 8728 | if (!coalesce) |
| 8729 | return; |
| 8730 | |
| 8731 | for (i = 0; i < coalesce->n_rules; i++) { |
| 8732 | rule = &coalesce->rules[i]; |
| 8733 | for (j = 0; j < rule->n_patterns; j++) |
| 8734 | kfree(rule->patterns[j].mask); |
| 8735 | kfree(rule->patterns); |
| 8736 | } |
| 8737 | kfree(coalesce->rules); |
| 8738 | kfree(coalesce); |
| 8739 | rdev->coalesce = NULL; |
| 8740 | } |
| 8741 | |
| 8742 | static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev, |
| 8743 | struct nlattr *rule, |
| 8744 | struct cfg80211_coalesce_rules *new_rule) |
| 8745 | { |
| 8746 | int err, i; |
| 8747 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; |
| 8748 | struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat; |
| 8749 | int rem, pat_len, mask_len, pkt_offset, n_patterns = 0; |
| 8750 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
| 8751 | |
| 8752 | err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule), |
| 8753 | nla_len(rule), nl80211_coalesce_policy); |
| 8754 | if (err) |
| 8755 | return err; |
| 8756 | |
| 8757 | if (tb[NL80211_ATTR_COALESCE_RULE_DELAY]) |
| 8758 | new_rule->delay = |
| 8759 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]); |
| 8760 | if (new_rule->delay > coalesce->max_delay) |
| 8761 | return -EINVAL; |
| 8762 | |
| 8763 | if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION]) |
| 8764 | new_rule->condition = |
| 8765 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]); |
| 8766 | if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH && |
| 8767 | new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH) |
| 8768 | return -EINVAL; |
| 8769 | |
| 8770 | if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN]) |
| 8771 | return -EINVAL; |
| 8772 | |
| 8773 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], |
| 8774 | rem) |
| 8775 | n_patterns++; |
| 8776 | if (n_patterns > coalesce->n_patterns) |
| 8777 | return -EINVAL; |
| 8778 | |
| 8779 | new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]), |
| 8780 | GFP_KERNEL); |
| 8781 | if (!new_rule->patterns) |
| 8782 | return -ENOMEM; |
| 8783 | |
| 8784 | new_rule->n_patterns = n_patterns; |
| 8785 | i = 0; |
| 8786 | |
| 8787 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], |
| 8788 | rem) { |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 8789 | u8 *mask_pat; |
| 8790 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 8791 | nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat), |
| 8792 | nla_len(pat), NULL); |
| 8793 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
| 8794 | !pat_tb[NL80211_PKTPAT_PATTERN]) |
| 8795 | return -EINVAL; |
| 8796 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
| 8797 | mask_len = DIV_ROUND_UP(pat_len, 8); |
| 8798 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
| 8799 | return -EINVAL; |
| 8800 | if (pat_len > coalesce->pattern_max_len || |
| 8801 | pat_len < coalesce->pattern_min_len) |
| 8802 | return -EINVAL; |
| 8803 | |
| 8804 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
| 8805 | pkt_offset = 0; |
| 8806 | else |
| 8807 | pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]); |
| 8808 | if (pkt_offset > coalesce->max_pkt_offset) |
| 8809 | return -EINVAL; |
| 8810 | new_rule->patterns[i].pkt_offset = pkt_offset; |
| 8811 | |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 8812 | mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 8813 | if (!mask_pat) |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 8814 | return -ENOMEM; |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 8815 | |
| 8816 | new_rule->patterns[i].mask = mask_pat; |
| 8817 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]), |
| 8818 | mask_len); |
| 8819 | |
| 8820 | mask_pat += mask_len; |
| 8821 | new_rule->patterns[i].pattern = mask_pat; |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 8822 | new_rule->patterns[i].pattern_len = pat_len; |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 8823 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
| 8824 | pat_len); |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 8825 | i++; |
| 8826 | } |
| 8827 | |
| 8828 | return 0; |
| 8829 | } |
| 8830 | |
| 8831 | static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info) |
| 8832 | { |
| 8833 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8834 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; |
| 8835 | struct cfg80211_coalesce new_coalesce = {}; |
| 8836 | struct cfg80211_coalesce *n_coalesce; |
| 8837 | int err, rem_rule, n_rules = 0, i, j; |
| 8838 | struct nlattr *rule; |
| 8839 | struct cfg80211_coalesce_rules *tmp_rule; |
| 8840 | |
| 8841 | if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce) |
| 8842 | return -EOPNOTSUPP; |
| 8843 | |
| 8844 | if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) { |
| 8845 | cfg80211_rdev_free_coalesce(rdev); |
| 8846 | rdev->ops->set_coalesce(&rdev->wiphy, NULL); |
| 8847 | return 0; |
| 8848 | } |
| 8849 | |
| 8850 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], |
| 8851 | rem_rule) |
| 8852 | n_rules++; |
| 8853 | if (n_rules > coalesce->n_rules) |
| 8854 | return -EINVAL; |
| 8855 | |
| 8856 | new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]), |
| 8857 | GFP_KERNEL); |
| 8858 | if (!new_coalesce.rules) |
| 8859 | return -ENOMEM; |
| 8860 | |
| 8861 | new_coalesce.n_rules = n_rules; |
| 8862 | i = 0; |
| 8863 | |
| 8864 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], |
| 8865 | rem_rule) { |
| 8866 | err = nl80211_parse_coalesce_rule(rdev, rule, |
| 8867 | &new_coalesce.rules[i]); |
| 8868 | if (err) |
| 8869 | goto error; |
| 8870 | |
| 8871 | i++; |
| 8872 | } |
| 8873 | |
| 8874 | err = rdev->ops->set_coalesce(&rdev->wiphy, &new_coalesce); |
| 8875 | if (err) |
| 8876 | goto error; |
| 8877 | |
| 8878 | n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL); |
| 8879 | if (!n_coalesce) { |
| 8880 | err = -ENOMEM; |
| 8881 | goto error; |
| 8882 | } |
| 8883 | cfg80211_rdev_free_coalesce(rdev); |
| 8884 | rdev->coalesce = n_coalesce; |
| 8885 | |
| 8886 | return 0; |
| 8887 | error: |
| 8888 | for (i = 0; i < new_coalesce.n_rules; i++) { |
| 8889 | tmp_rule = &new_coalesce.rules[i]; |
| 8890 | for (j = 0; j < tmp_rule->n_patterns; j++) |
| 8891 | kfree(tmp_rule->patterns[j].mask); |
| 8892 | kfree(tmp_rule->patterns); |
| 8893 | } |
| 8894 | kfree(new_coalesce.rules); |
| 8895 | |
| 8896 | return err; |
| 8897 | } |
| 8898 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 8899 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
| 8900 | { |
| 8901 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8902 | struct net_device *dev = info->user_ptr[1]; |
| 8903 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 8904 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; |
| 8905 | struct cfg80211_gtk_rekey_data rekey_data; |
| 8906 | int err; |
| 8907 | |
| 8908 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) |
| 8909 | return -EINVAL; |
| 8910 | |
| 8911 | err = nla_parse(tb, MAX_NL80211_REKEY_DATA, |
| 8912 | nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 8913 | nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 8914 | nl80211_rekey_policy); |
| 8915 | if (err) |
| 8916 | return err; |
| 8917 | |
| 8918 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) |
| 8919 | return -ERANGE; |
| 8920 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) |
| 8921 | return -ERANGE; |
| 8922 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) |
| 8923 | return -ERANGE; |
| 8924 | |
| 8925 | memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]), |
| 8926 | NL80211_KEK_LEN); |
| 8927 | memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]), |
| 8928 | NL80211_KCK_LEN); |
| 8929 | memcpy(rekey_data.replay_ctr, |
| 8930 | nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]), |
| 8931 | NL80211_REPLAY_CTR_LEN); |
| 8932 | |
| 8933 | wdev_lock(wdev); |
| 8934 | if (!wdev->current_bss) { |
| 8935 | err = -ENOTCONN; |
| 8936 | goto out; |
| 8937 | } |
| 8938 | |
| 8939 | if (!rdev->ops->set_rekey_data) { |
| 8940 | err = -EOPNOTSUPP; |
| 8941 | goto out; |
| 8942 | } |
| 8943 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8944 | err = rdev_set_rekey_data(rdev, dev, &rekey_data); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 8945 | out: |
| 8946 | wdev_unlock(wdev); |
| 8947 | return err; |
| 8948 | } |
| 8949 | |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8950 | static int nl80211_register_unexpected_frame(struct sk_buff *skb, |
| 8951 | struct genl_info *info) |
| 8952 | { |
| 8953 | struct net_device *dev = info->user_ptr[1]; |
| 8954 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 8955 | |
| 8956 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 8957 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 8958 | return -EINVAL; |
| 8959 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8960 | if (wdev->ap_unexpected_nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8961 | return -EBUSY; |
| 8962 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8963 | wdev->ap_unexpected_nlportid = info->snd_portid; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8964 | return 0; |
| 8965 | } |
| 8966 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8967 | static int nl80211_probe_client(struct sk_buff *skb, |
| 8968 | struct genl_info *info) |
| 8969 | { |
| 8970 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8971 | struct net_device *dev = info->user_ptr[1]; |
| 8972 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 8973 | struct sk_buff *msg; |
| 8974 | void *hdr; |
| 8975 | const u8 *addr; |
| 8976 | u64 cookie; |
| 8977 | int err; |
| 8978 | |
| 8979 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 8980 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 8981 | return -EOPNOTSUPP; |
| 8982 | |
| 8983 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 8984 | return -EINVAL; |
| 8985 | |
| 8986 | if (!rdev->ops->probe_client) |
| 8987 | return -EOPNOTSUPP; |
| 8988 | |
| 8989 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 8990 | if (!msg) |
| 8991 | return -ENOMEM; |
| 8992 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8993 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8994 | NL80211_CMD_PROBE_CLIENT); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 8995 | if (!hdr) { |
| 8996 | err = -ENOBUFS; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8997 | goto free_msg; |
| 8998 | } |
| 8999 | |
| 9000 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 9001 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 9002 | err = rdev_probe_client(rdev, dev, addr, &cookie); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9003 | if (err) |
| 9004 | goto free_msg; |
| 9005 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9006 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 9007 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9008 | |
| 9009 | genlmsg_end(msg, hdr); |
| 9010 | |
| 9011 | return genlmsg_reply(msg, info); |
| 9012 | |
| 9013 | nla_put_failure: |
| 9014 | err = -ENOBUFS; |
| 9015 | free_msg: |
| 9016 | nlmsg_free(msg); |
| 9017 | return err; |
| 9018 | } |
| 9019 | |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9020 | static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) |
| 9021 | { |
| 9022 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9023 | struct cfg80211_beacon_registration *reg, *nreg; |
| 9024 | int rv; |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9025 | |
| 9026 | if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) |
| 9027 | return -EOPNOTSUPP; |
| 9028 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9029 | nreg = kzalloc(sizeof(*nreg), GFP_KERNEL); |
| 9030 | if (!nreg) |
| 9031 | return -ENOMEM; |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9032 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9033 | /* First, check if already registered. */ |
| 9034 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 9035 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 9036 | if (reg->nlportid == info->snd_portid) { |
| 9037 | rv = -EALREADY; |
| 9038 | goto out_err; |
| 9039 | } |
| 9040 | } |
| 9041 | /* Add it to the list */ |
| 9042 | nreg->nlportid = info->snd_portid; |
| 9043 | list_add(&nreg->list, &rdev->beacon_registrations); |
| 9044 | |
| 9045 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9046 | |
| 9047 | return 0; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9048 | out_err: |
| 9049 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 9050 | kfree(nreg); |
| 9051 | return rv; |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9052 | } |
| 9053 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9054 | static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 9055 | { |
| 9056 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9057 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 9058 | int err; |
| 9059 | |
| 9060 | if (!rdev->ops->start_p2p_device) |
| 9061 | return -EOPNOTSUPP; |
| 9062 | |
| 9063 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 9064 | return -EOPNOTSUPP; |
| 9065 | |
| 9066 | if (wdev->p2p_started) |
| 9067 | return 0; |
| 9068 | |
Luciano Coelho | b6a5501 | 2014-02-27 11:07:21 +0200 | [diff] [blame] | 9069 | if (rfkill_blocked(rdev->rfkill)) |
| 9070 | return -ERFKILL; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9071 | |
Johannes Berg | eeb126e | 2012-10-23 15:16:50 +0200 | [diff] [blame] | 9072 | err = rdev_start_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9073 | if (err) |
| 9074 | return err; |
| 9075 | |
| 9076 | wdev->p2p_started = true; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9077 | rdev->opencount++; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9078 | |
| 9079 | return 0; |
| 9080 | } |
| 9081 | |
| 9082 | static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 9083 | { |
| 9084 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9085 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 9086 | |
| 9087 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 9088 | return -EOPNOTSUPP; |
| 9089 | |
| 9090 | if (!rdev->ops->stop_p2p_device) |
| 9091 | return -EOPNOTSUPP; |
| 9092 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 9093 | cfg80211_stop_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9094 | |
| 9095 | return 0; |
| 9096 | } |
| 9097 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 9098 | static int nl80211_get_protocol_features(struct sk_buff *skb, |
| 9099 | struct genl_info *info) |
| 9100 | { |
| 9101 | void *hdr; |
| 9102 | struct sk_buff *msg; |
| 9103 | |
| 9104 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 9105 | if (!msg) |
| 9106 | return -ENOMEM; |
| 9107 | |
| 9108 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 9109 | NL80211_CMD_GET_PROTOCOL_FEATURES); |
| 9110 | if (!hdr) |
| 9111 | goto nla_put_failure; |
| 9112 | |
| 9113 | if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES, |
| 9114 | NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)) |
| 9115 | goto nla_put_failure; |
| 9116 | |
| 9117 | genlmsg_end(msg, hdr); |
| 9118 | return genlmsg_reply(msg, info); |
| 9119 | |
| 9120 | nla_put_failure: |
| 9121 | kfree_skb(msg); |
| 9122 | return -ENOBUFS; |
| 9123 | } |
| 9124 | |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 9125 | static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info) |
| 9126 | { |
| 9127 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9128 | struct cfg80211_update_ft_ies_params ft_params; |
| 9129 | struct net_device *dev = info->user_ptr[1]; |
| 9130 | |
| 9131 | if (!rdev->ops->update_ft_ies) |
| 9132 | return -EOPNOTSUPP; |
| 9133 | |
| 9134 | if (!info->attrs[NL80211_ATTR_MDID] || |
| 9135 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 9136 | return -EINVAL; |
| 9137 | |
| 9138 | memset(&ft_params, 0, sizeof(ft_params)); |
| 9139 | ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]); |
| 9140 | ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 9141 | ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 9142 | |
| 9143 | return rdev_update_ft_ies(rdev, dev, &ft_params); |
| 9144 | } |
| 9145 | |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 9146 | static int nl80211_crit_protocol_start(struct sk_buff *skb, |
| 9147 | struct genl_info *info) |
| 9148 | { |
| 9149 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9150 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 9151 | enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC; |
| 9152 | u16 duration; |
| 9153 | int ret; |
| 9154 | |
| 9155 | if (!rdev->ops->crit_proto_start) |
| 9156 | return -EOPNOTSUPP; |
| 9157 | |
| 9158 | if (WARN_ON(!rdev->ops->crit_proto_stop)) |
| 9159 | return -EINVAL; |
| 9160 | |
| 9161 | if (rdev->crit_proto_nlportid) |
| 9162 | return -EBUSY; |
| 9163 | |
| 9164 | /* determine protocol if provided */ |
| 9165 | if (info->attrs[NL80211_ATTR_CRIT_PROT_ID]) |
| 9166 | proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]); |
| 9167 | |
| 9168 | if (proto >= NUM_NL80211_CRIT_PROTO) |
| 9169 | return -EINVAL; |
| 9170 | |
| 9171 | /* timeout must be provided */ |
| 9172 | if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]) |
| 9173 | return -EINVAL; |
| 9174 | |
| 9175 | duration = |
| 9176 | nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]); |
| 9177 | |
| 9178 | if (duration > NL80211_CRIT_PROTO_MAX_DURATION) |
| 9179 | return -ERANGE; |
| 9180 | |
| 9181 | ret = rdev_crit_proto_start(rdev, wdev, proto, duration); |
| 9182 | if (!ret) |
| 9183 | rdev->crit_proto_nlportid = info->snd_portid; |
| 9184 | |
| 9185 | return ret; |
| 9186 | } |
| 9187 | |
| 9188 | static int nl80211_crit_protocol_stop(struct sk_buff *skb, |
| 9189 | struct genl_info *info) |
| 9190 | { |
| 9191 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9192 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 9193 | |
| 9194 | if (!rdev->ops->crit_proto_stop) |
| 9195 | return -EOPNOTSUPP; |
| 9196 | |
| 9197 | if (rdev->crit_proto_nlportid) { |
| 9198 | rdev->crit_proto_nlportid = 0; |
| 9199 | rdev_crit_proto_stop(rdev, wdev); |
| 9200 | } |
| 9201 | return 0; |
| 9202 | } |
| 9203 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 9204 | static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info) |
| 9205 | { |
| 9206 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9207 | struct wireless_dev *wdev = |
| 9208 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); |
| 9209 | int i, err; |
| 9210 | u32 vid, subcmd; |
| 9211 | |
| 9212 | if (!rdev->wiphy.vendor_commands) |
| 9213 | return -EOPNOTSUPP; |
| 9214 | |
| 9215 | if (IS_ERR(wdev)) { |
| 9216 | err = PTR_ERR(wdev); |
| 9217 | if (err != -EINVAL) |
| 9218 | return err; |
| 9219 | wdev = NULL; |
| 9220 | } else if (wdev->wiphy != &rdev->wiphy) { |
| 9221 | return -EINVAL; |
| 9222 | } |
| 9223 | |
| 9224 | if (!info->attrs[NL80211_ATTR_VENDOR_ID] || |
| 9225 | !info->attrs[NL80211_ATTR_VENDOR_SUBCMD]) |
| 9226 | return -EINVAL; |
| 9227 | |
| 9228 | vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]); |
| 9229 | subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]); |
| 9230 | for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { |
| 9231 | const struct wiphy_vendor_command *vcmd; |
| 9232 | void *data = NULL; |
| 9233 | int len = 0; |
| 9234 | |
| 9235 | vcmd = &rdev->wiphy.vendor_commands[i]; |
| 9236 | |
| 9237 | if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd) |
| 9238 | continue; |
| 9239 | |
| 9240 | if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV | |
| 9241 | WIPHY_VENDOR_CMD_NEED_NETDEV)) { |
| 9242 | if (!wdev) |
| 9243 | return -EINVAL; |
| 9244 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV && |
| 9245 | !wdev->netdev) |
| 9246 | return -EINVAL; |
| 9247 | |
| 9248 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) { |
| 9249 | if (wdev->netdev && |
| 9250 | !netif_running(wdev->netdev)) |
| 9251 | return -ENETDOWN; |
| 9252 | if (!wdev->netdev && !wdev->p2p_started) |
| 9253 | return -ENETDOWN; |
| 9254 | } |
| 9255 | } else { |
| 9256 | wdev = NULL; |
| 9257 | } |
| 9258 | |
| 9259 | if (info->attrs[NL80211_ATTR_VENDOR_DATA]) { |
| 9260 | data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]); |
| 9261 | len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]); |
| 9262 | } |
| 9263 | |
| 9264 | rdev->cur_cmd_info = info; |
| 9265 | err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev, |
| 9266 | data, len); |
| 9267 | rdev->cur_cmd_info = NULL; |
| 9268 | return err; |
| 9269 | } |
| 9270 | |
| 9271 | return -EOPNOTSUPP; |
| 9272 | } |
| 9273 | |
| 9274 | struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy, |
| 9275 | enum nl80211_commands cmd, |
| 9276 | enum nl80211_attrs attr, |
| 9277 | int approxlen) |
| 9278 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 9279 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 9280 | |
| 9281 | if (WARN_ON(!rdev->cur_cmd_info)) |
| 9282 | return NULL; |
| 9283 | |
| 9284 | return __cfg80211_alloc_vendor_skb(rdev, approxlen, |
| 9285 | rdev->cur_cmd_info->snd_portid, |
| 9286 | rdev->cur_cmd_info->snd_seq, |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 9287 | cmd, attr, NULL, GFP_KERNEL); |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 9288 | } |
| 9289 | EXPORT_SYMBOL(__cfg80211_alloc_reply_skb); |
| 9290 | |
| 9291 | int cfg80211_vendor_cmd_reply(struct sk_buff *skb) |
| 9292 | { |
| 9293 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 9294 | void *hdr = ((void **)skb->cb)[1]; |
| 9295 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 9296 | |
| 9297 | if (WARN_ON(!rdev->cur_cmd_info)) { |
| 9298 | kfree_skb(skb); |
| 9299 | return -EINVAL; |
| 9300 | } |
| 9301 | |
| 9302 | nla_nest_end(skb, data); |
| 9303 | genlmsg_end(skb, hdr); |
| 9304 | return genlmsg_reply(skb, rdev->cur_cmd_info); |
| 9305 | } |
| 9306 | EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply); |
| 9307 | |
| 9308 | |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 9309 | static int nl80211_set_qos_map(struct sk_buff *skb, |
| 9310 | struct genl_info *info) |
| 9311 | { |
| 9312 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9313 | struct cfg80211_qos_map *qos_map = NULL; |
| 9314 | struct net_device *dev = info->user_ptr[1]; |
| 9315 | u8 *pos, len, num_des, des_len, des; |
| 9316 | int ret; |
| 9317 | |
| 9318 | if (!rdev->ops->set_qos_map) |
| 9319 | return -EOPNOTSUPP; |
| 9320 | |
| 9321 | if (info->attrs[NL80211_ATTR_QOS_MAP]) { |
| 9322 | pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]); |
| 9323 | len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]); |
| 9324 | |
| 9325 | if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN || |
| 9326 | len > IEEE80211_QOS_MAP_LEN_MAX) |
| 9327 | return -EINVAL; |
| 9328 | |
| 9329 | qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL); |
| 9330 | if (!qos_map) |
| 9331 | return -ENOMEM; |
| 9332 | |
| 9333 | num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1; |
| 9334 | if (num_des) { |
| 9335 | des_len = num_des * |
| 9336 | sizeof(struct cfg80211_dscp_exception); |
| 9337 | memcpy(qos_map->dscp_exception, pos, des_len); |
| 9338 | qos_map->num_des = num_des; |
| 9339 | for (des = 0; des < num_des; des++) { |
| 9340 | if (qos_map->dscp_exception[des].up > 7) { |
| 9341 | kfree(qos_map); |
| 9342 | return -EINVAL; |
| 9343 | } |
| 9344 | } |
| 9345 | pos += des_len; |
| 9346 | } |
| 9347 | memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN); |
| 9348 | } |
| 9349 | |
| 9350 | wdev_lock(dev->ieee80211_ptr); |
| 9351 | ret = nl80211_key_allowed(dev->ieee80211_ptr); |
| 9352 | if (!ret) |
| 9353 | ret = rdev_set_qos_map(rdev, dev, qos_map); |
| 9354 | wdev_unlock(dev->ieee80211_ptr); |
| 9355 | |
| 9356 | kfree(qos_map); |
| 9357 | return ret; |
| 9358 | } |
| 9359 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9360 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
| 9361 | #define NL80211_FLAG_NEED_NETDEV 0x02 |
| 9362 | #define NL80211_FLAG_NEED_RTNL 0x04 |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9363 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
| 9364 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ |
| 9365 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 9366 | #define NL80211_FLAG_NEED_WDEV 0x10 |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9367 | /* 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] | 9368 | #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\ |
| 9369 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9370 | |
Johannes Berg | f84f771 | 2013-11-14 17:14:45 +0100 | [diff] [blame] | 9371 | 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] | 9372 | struct genl_info *info) |
| 9373 | { |
| 9374 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 9375 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9376 | struct net_device *dev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9377 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
| 9378 | |
| 9379 | if (rtnl) |
| 9380 | rtnl_lock(); |
| 9381 | |
| 9382 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 9383 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9384 | if (IS_ERR(rdev)) { |
| 9385 | if (rtnl) |
| 9386 | rtnl_unlock(); |
| 9387 | return PTR_ERR(rdev); |
| 9388 | } |
| 9389 | info->user_ptr[0] = rdev; |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 9390 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV || |
| 9391 | ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 9392 | ASSERT_RTNL(); |
| 9393 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 9394 | wdev = __cfg80211_wdev_from_attrs(genl_info_net(info), |
| 9395 | info->attrs); |
| 9396 | if (IS_ERR(wdev)) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9397 | if (rtnl) |
| 9398 | rtnl_unlock(); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 9399 | return PTR_ERR(wdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9400 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 9401 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 9402 | dev = wdev->netdev; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 9403 | rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 9404 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 9405 | if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
| 9406 | if (!dev) { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 9407 | if (rtnl) |
| 9408 | rtnl_unlock(); |
| 9409 | return -EINVAL; |
| 9410 | } |
| 9411 | |
| 9412 | info->user_ptr[1] = dev; |
| 9413 | } else { |
| 9414 | info->user_ptr[1] = wdev; |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9415 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 9416 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 9417 | if (dev) { |
| 9418 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && |
| 9419 | !netif_running(dev)) { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 9420 | if (rtnl) |
| 9421 | rtnl_unlock(); |
| 9422 | return -ENETDOWN; |
| 9423 | } |
| 9424 | |
| 9425 | dev_hold(dev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9426 | } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) { |
| 9427 | if (!wdev->p2p_started) { |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9428 | if (rtnl) |
| 9429 | rtnl_unlock(); |
| 9430 | return -ENETDOWN; |
| 9431 | } |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 9432 | } |
| 9433 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9434 | info->user_ptr[0] = rdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9435 | } |
| 9436 | |
| 9437 | return 0; |
| 9438 | } |
| 9439 | |
Johannes Berg | f84f771 | 2013-11-14 17:14:45 +0100 | [diff] [blame] | 9440 | 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] | 9441 | struct genl_info *info) |
| 9442 | { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 9443 | if (info->user_ptr[1]) { |
| 9444 | if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
| 9445 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 9446 | |
| 9447 | if (wdev->netdev) |
| 9448 | dev_put(wdev->netdev); |
| 9449 | } else { |
| 9450 | dev_put(info->user_ptr[1]); |
| 9451 | } |
| 9452 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9453 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
| 9454 | rtnl_unlock(); |
| 9455 | } |
| 9456 | |
Johannes Berg | 4534de8 | 2013-11-14 17:14:46 +0100 | [diff] [blame] | 9457 | static const struct genl_ops nl80211_ops[] = { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9458 | { |
| 9459 | .cmd = NL80211_CMD_GET_WIPHY, |
| 9460 | .doit = nl80211_get_wiphy, |
| 9461 | .dumpit = nl80211_dump_wiphy, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 9462 | .done = nl80211_dump_wiphy_done, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9463 | .policy = nl80211_policy, |
| 9464 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 9465 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9466 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9467 | }, |
| 9468 | { |
| 9469 | .cmd = NL80211_CMD_SET_WIPHY, |
| 9470 | .doit = nl80211_set_wiphy, |
| 9471 | .policy = nl80211_policy, |
| 9472 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9473 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9474 | }, |
| 9475 | { |
| 9476 | .cmd = NL80211_CMD_GET_INTERFACE, |
| 9477 | .doit = nl80211_get_interface, |
| 9478 | .dumpit = nl80211_dump_interface, |
| 9479 | .policy = nl80211_policy, |
| 9480 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 9481 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 9482 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9483 | }, |
| 9484 | { |
| 9485 | .cmd = NL80211_CMD_SET_INTERFACE, |
| 9486 | .doit = nl80211_set_interface, |
| 9487 | .policy = nl80211_policy, |
| 9488 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9489 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9490 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9491 | }, |
| 9492 | { |
| 9493 | .cmd = NL80211_CMD_NEW_INTERFACE, |
| 9494 | .doit = nl80211_new_interface, |
| 9495 | .policy = nl80211_policy, |
| 9496 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9497 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9498 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9499 | }, |
| 9500 | { |
| 9501 | .cmd = NL80211_CMD_DEL_INTERFACE, |
| 9502 | .doit = nl80211_del_interface, |
| 9503 | .policy = nl80211_policy, |
| 9504 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 9505 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9506 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9507 | }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 9508 | { |
| 9509 | .cmd = NL80211_CMD_GET_KEY, |
| 9510 | .doit = nl80211_get_key, |
| 9511 | .policy = nl80211_policy, |
| 9512 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9513 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9514 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 9515 | }, |
| 9516 | { |
| 9517 | .cmd = NL80211_CMD_SET_KEY, |
| 9518 | .doit = nl80211_set_key, |
| 9519 | .policy = nl80211_policy, |
| 9520 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9521 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9522 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 9523 | }, |
| 9524 | { |
| 9525 | .cmd = NL80211_CMD_NEW_KEY, |
| 9526 | .doit = nl80211_new_key, |
| 9527 | .policy = nl80211_policy, |
| 9528 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9529 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9530 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 9531 | }, |
| 9532 | { |
| 9533 | .cmd = NL80211_CMD_DEL_KEY, |
| 9534 | .doit = nl80211_del_key, |
| 9535 | .policy = nl80211_policy, |
| 9536 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9537 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9538 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 9539 | }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 9540 | { |
| 9541 | .cmd = NL80211_CMD_SET_BEACON, |
| 9542 | .policy = nl80211_policy, |
| 9543 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 9544 | .doit = nl80211_set_beacon, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9545 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9546 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 9547 | }, |
| 9548 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 9549 | .cmd = NL80211_CMD_START_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 9550 | .policy = nl80211_policy, |
| 9551 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 9552 | .doit = nl80211_start_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9553 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9554 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 9555 | }, |
| 9556 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 9557 | .cmd = NL80211_CMD_STOP_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 9558 | .policy = nl80211_policy, |
| 9559 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 9560 | .doit = nl80211_stop_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9561 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9562 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 9563 | }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 9564 | { |
| 9565 | .cmd = NL80211_CMD_GET_STATION, |
| 9566 | .doit = nl80211_get_station, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9567 | .dumpit = nl80211_dump_station, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 9568 | .policy = nl80211_policy, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9569 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9570 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 9571 | }, |
| 9572 | { |
| 9573 | .cmd = NL80211_CMD_SET_STATION, |
| 9574 | .doit = nl80211_set_station, |
| 9575 | .policy = nl80211_policy, |
| 9576 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9577 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9578 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 9579 | }, |
| 9580 | { |
| 9581 | .cmd = NL80211_CMD_NEW_STATION, |
| 9582 | .doit = nl80211_new_station, |
| 9583 | .policy = nl80211_policy, |
| 9584 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9585 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9586 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 9587 | }, |
| 9588 | { |
| 9589 | .cmd = NL80211_CMD_DEL_STATION, |
| 9590 | .doit = nl80211_del_station, |
| 9591 | .policy = nl80211_policy, |
| 9592 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9593 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9594 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 9595 | }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9596 | { |
| 9597 | .cmd = NL80211_CMD_GET_MPATH, |
| 9598 | .doit = nl80211_get_mpath, |
| 9599 | .dumpit = nl80211_dump_mpath, |
| 9600 | .policy = nl80211_policy, |
| 9601 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9602 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9603 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9604 | }, |
| 9605 | { |
| 9606 | .cmd = NL80211_CMD_SET_MPATH, |
| 9607 | .doit = nl80211_set_mpath, |
| 9608 | .policy = nl80211_policy, |
| 9609 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9610 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9611 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9612 | }, |
| 9613 | { |
| 9614 | .cmd = NL80211_CMD_NEW_MPATH, |
| 9615 | .doit = nl80211_new_mpath, |
| 9616 | .policy = nl80211_policy, |
| 9617 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9618 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9619 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9620 | }, |
| 9621 | { |
| 9622 | .cmd = NL80211_CMD_DEL_MPATH, |
| 9623 | .doit = nl80211_del_mpath, |
| 9624 | .policy = nl80211_policy, |
| 9625 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9626 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9627 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9628 | }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 9629 | { |
| 9630 | .cmd = NL80211_CMD_SET_BSS, |
| 9631 | .doit = nl80211_set_bss, |
| 9632 | .policy = nl80211_policy, |
| 9633 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9634 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9635 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 9636 | }, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 9637 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 9638 | .cmd = NL80211_CMD_GET_REG, |
| 9639 | .doit = nl80211_get_reg, |
| 9640 | .policy = nl80211_policy, |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 9641 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 9642 | /* can be retrieved by unprivileged users */ |
| 9643 | }, |
| 9644 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 9645 | .cmd = NL80211_CMD_SET_REG, |
| 9646 | .doit = nl80211_set_reg, |
| 9647 | .policy = nl80211_policy, |
| 9648 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 9649 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 9650 | }, |
| 9651 | { |
| 9652 | .cmd = NL80211_CMD_REQ_SET_REG, |
| 9653 | .doit = nl80211_req_set_reg, |
| 9654 | .policy = nl80211_policy, |
| 9655 | .flags = GENL_ADMIN_PERM, |
| 9656 | }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 9657 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 9658 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
| 9659 | .doit = nl80211_get_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 9660 | .policy = nl80211_policy, |
| 9661 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9662 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9663 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 9664 | }, |
| 9665 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 9666 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
| 9667 | .doit = nl80211_update_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 9668 | .policy = nl80211_policy, |
| 9669 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 9670 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9671 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 9672 | }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 9673 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9674 | .cmd = NL80211_CMD_TRIGGER_SCAN, |
| 9675 | .doit = nl80211_trigger_scan, |
| 9676 | .policy = nl80211_policy, |
| 9677 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9678 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9679 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9680 | }, |
| 9681 | { |
| 9682 | .cmd = NL80211_CMD_GET_SCAN, |
| 9683 | .policy = nl80211_policy, |
| 9684 | .dumpit = nl80211_dump_scan, |
| 9685 | }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9686 | { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9687 | .cmd = NL80211_CMD_START_SCHED_SCAN, |
| 9688 | .doit = nl80211_start_sched_scan, |
| 9689 | .policy = nl80211_policy, |
| 9690 | .flags = GENL_ADMIN_PERM, |
| 9691 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9692 | NL80211_FLAG_NEED_RTNL, |
| 9693 | }, |
| 9694 | { |
| 9695 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, |
| 9696 | .doit = nl80211_stop_sched_scan, |
| 9697 | .policy = nl80211_policy, |
| 9698 | .flags = GENL_ADMIN_PERM, |
| 9699 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9700 | NL80211_FLAG_NEED_RTNL, |
| 9701 | }, |
| 9702 | { |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9703 | .cmd = NL80211_CMD_AUTHENTICATE, |
| 9704 | .doit = nl80211_authenticate, |
| 9705 | .policy = nl80211_policy, |
| 9706 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9707 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9708 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9709 | }, |
| 9710 | { |
| 9711 | .cmd = NL80211_CMD_ASSOCIATE, |
| 9712 | .doit = nl80211_associate, |
| 9713 | .policy = nl80211_policy, |
| 9714 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9715 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9716 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9717 | }, |
| 9718 | { |
| 9719 | .cmd = NL80211_CMD_DEAUTHENTICATE, |
| 9720 | .doit = nl80211_deauthenticate, |
| 9721 | .policy = nl80211_policy, |
| 9722 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9723 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9724 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9725 | }, |
| 9726 | { |
| 9727 | .cmd = NL80211_CMD_DISASSOCIATE, |
| 9728 | .doit = nl80211_disassociate, |
| 9729 | .policy = nl80211_policy, |
| 9730 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9731 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9732 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9733 | }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9734 | { |
| 9735 | .cmd = NL80211_CMD_JOIN_IBSS, |
| 9736 | .doit = nl80211_join_ibss, |
| 9737 | .policy = nl80211_policy, |
| 9738 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9739 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9740 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9741 | }, |
| 9742 | { |
| 9743 | .cmd = NL80211_CMD_LEAVE_IBSS, |
| 9744 | .doit = nl80211_leave_ibss, |
| 9745 | .policy = nl80211_policy, |
| 9746 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9747 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9748 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9749 | }, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 9750 | #ifdef CONFIG_NL80211_TESTMODE |
| 9751 | { |
| 9752 | .cmd = NL80211_CMD_TESTMODE, |
| 9753 | .doit = nl80211_testmode_do, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 9754 | .dumpit = nl80211_testmode_dump, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 9755 | .policy = nl80211_policy, |
| 9756 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9757 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9758 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 9759 | }, |
| 9760 | #endif |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9761 | { |
| 9762 | .cmd = NL80211_CMD_CONNECT, |
| 9763 | .doit = nl80211_connect, |
| 9764 | .policy = nl80211_policy, |
| 9765 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9766 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9767 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9768 | }, |
| 9769 | { |
| 9770 | .cmd = NL80211_CMD_DISCONNECT, |
| 9771 | .doit = nl80211_disconnect, |
| 9772 | .policy = nl80211_policy, |
| 9773 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +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, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9776 | }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9777 | { |
| 9778 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, |
| 9779 | .doit = nl80211_wiphy_netns, |
| 9780 | .policy = nl80211_policy, |
| 9781 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9782 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9783 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9784 | }, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 9785 | { |
| 9786 | .cmd = NL80211_CMD_GET_SURVEY, |
| 9787 | .policy = nl80211_policy, |
| 9788 | .dumpit = nl80211_dump_survey, |
| 9789 | }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9790 | { |
| 9791 | .cmd = NL80211_CMD_SET_PMKSA, |
| 9792 | .doit = nl80211_setdel_pmksa, |
| 9793 | .policy = nl80211_policy, |
| 9794 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9795 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9796 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9797 | }, |
| 9798 | { |
| 9799 | .cmd = NL80211_CMD_DEL_PMKSA, |
| 9800 | .doit = nl80211_setdel_pmksa, |
| 9801 | .policy = nl80211_policy, |
| 9802 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9803 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9804 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9805 | }, |
| 9806 | { |
| 9807 | .cmd = NL80211_CMD_FLUSH_PMKSA, |
| 9808 | .doit = nl80211_flush_pmksa, |
| 9809 | .policy = nl80211_policy, |
| 9810 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9811 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9812 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9813 | }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9814 | { |
| 9815 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, |
| 9816 | .doit = nl80211_remain_on_channel, |
| 9817 | .policy = nl80211_policy, |
| 9818 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9819 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9820 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9821 | }, |
| 9822 | { |
| 9823 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
| 9824 | .doit = nl80211_cancel_remain_on_channel, |
| 9825 | .policy = nl80211_policy, |
| 9826 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9827 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9828 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9829 | }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 9830 | { |
| 9831 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, |
| 9832 | .doit = nl80211_set_tx_bitrate_mask, |
| 9833 | .policy = nl80211_policy, |
| 9834 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9835 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9836 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 9837 | }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9838 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9839 | .cmd = NL80211_CMD_REGISTER_FRAME, |
| 9840 | .doit = nl80211_register_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9841 | .policy = nl80211_policy, |
| 9842 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9843 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9844 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9845 | }, |
| 9846 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9847 | .cmd = NL80211_CMD_FRAME, |
| 9848 | .doit = nl80211_tx_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9849 | .policy = nl80211_policy, |
| 9850 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9851 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9852 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9853 | }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9854 | { |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 9855 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, |
| 9856 | .doit = nl80211_tx_mgmt_cancel_wait, |
| 9857 | .policy = nl80211_policy, |
| 9858 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9859 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 9860 | NL80211_FLAG_NEED_RTNL, |
| 9861 | }, |
| 9862 | { |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9863 | .cmd = NL80211_CMD_SET_POWER_SAVE, |
| 9864 | .doit = nl80211_set_power_save, |
| 9865 | .policy = nl80211_policy, |
| 9866 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9867 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9868 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9869 | }, |
| 9870 | { |
| 9871 | .cmd = NL80211_CMD_GET_POWER_SAVE, |
| 9872 | .doit = nl80211_get_power_save, |
| 9873 | .policy = nl80211_policy, |
| 9874 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9875 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9876 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9877 | }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9878 | { |
| 9879 | .cmd = NL80211_CMD_SET_CQM, |
| 9880 | .doit = nl80211_set_cqm, |
| 9881 | .policy = nl80211_policy, |
| 9882 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9883 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9884 | NL80211_FLAG_NEED_RTNL, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9885 | }, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 9886 | { |
| 9887 | .cmd = NL80211_CMD_SET_CHANNEL, |
| 9888 | .doit = nl80211_set_channel, |
| 9889 | .policy = nl80211_policy, |
| 9890 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9891 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9892 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 9893 | }, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 9894 | { |
| 9895 | .cmd = NL80211_CMD_SET_WDS_PEER, |
| 9896 | .doit = nl80211_set_wds_peer, |
| 9897 | .policy = nl80211_policy, |
| 9898 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 9899 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9900 | NL80211_FLAG_NEED_RTNL, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 9901 | }, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 9902 | { |
| 9903 | .cmd = NL80211_CMD_JOIN_MESH, |
| 9904 | .doit = nl80211_join_mesh, |
| 9905 | .policy = nl80211_policy, |
| 9906 | .flags = GENL_ADMIN_PERM, |
| 9907 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9908 | NL80211_FLAG_NEED_RTNL, |
| 9909 | }, |
| 9910 | { |
| 9911 | .cmd = NL80211_CMD_LEAVE_MESH, |
| 9912 | .doit = nl80211_leave_mesh, |
| 9913 | .policy = nl80211_policy, |
| 9914 | .flags = GENL_ADMIN_PERM, |
| 9915 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9916 | NL80211_FLAG_NEED_RTNL, |
| 9917 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 9918 | #ifdef CONFIG_PM |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9919 | { |
| 9920 | .cmd = NL80211_CMD_GET_WOWLAN, |
| 9921 | .doit = nl80211_get_wowlan, |
| 9922 | .policy = nl80211_policy, |
| 9923 | /* can be retrieved by unprivileged users */ |
| 9924 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9925 | NL80211_FLAG_NEED_RTNL, |
| 9926 | }, |
| 9927 | { |
| 9928 | .cmd = NL80211_CMD_SET_WOWLAN, |
| 9929 | .doit = nl80211_set_wowlan, |
| 9930 | .policy = nl80211_policy, |
| 9931 | .flags = GENL_ADMIN_PERM, |
| 9932 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9933 | NL80211_FLAG_NEED_RTNL, |
| 9934 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 9935 | #endif |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 9936 | { |
| 9937 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, |
| 9938 | .doit = nl80211_set_rekey_data, |
| 9939 | .policy = nl80211_policy, |
| 9940 | .flags = GENL_ADMIN_PERM, |
| 9941 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9942 | NL80211_FLAG_NEED_RTNL, |
| 9943 | }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 9944 | { |
| 9945 | .cmd = NL80211_CMD_TDLS_MGMT, |
| 9946 | .doit = nl80211_tdls_mgmt, |
| 9947 | .policy = nl80211_policy, |
| 9948 | .flags = GENL_ADMIN_PERM, |
| 9949 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9950 | NL80211_FLAG_NEED_RTNL, |
| 9951 | }, |
| 9952 | { |
| 9953 | .cmd = NL80211_CMD_TDLS_OPER, |
| 9954 | .doit = nl80211_tdls_oper, |
| 9955 | .policy = nl80211_policy, |
| 9956 | .flags = GENL_ADMIN_PERM, |
| 9957 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9958 | NL80211_FLAG_NEED_RTNL, |
| 9959 | }, |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9960 | { |
| 9961 | .cmd = NL80211_CMD_UNEXPECTED_FRAME, |
| 9962 | .doit = nl80211_register_unexpected_frame, |
| 9963 | .policy = nl80211_policy, |
| 9964 | .flags = GENL_ADMIN_PERM, |
| 9965 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9966 | NL80211_FLAG_NEED_RTNL, |
| 9967 | }, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9968 | { |
| 9969 | .cmd = NL80211_CMD_PROBE_CLIENT, |
| 9970 | .doit = nl80211_probe_client, |
| 9971 | .policy = nl80211_policy, |
| 9972 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9973 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9974 | NL80211_FLAG_NEED_RTNL, |
| 9975 | }, |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9976 | { |
| 9977 | .cmd = NL80211_CMD_REGISTER_BEACONS, |
| 9978 | .doit = nl80211_register_beacons, |
| 9979 | .policy = nl80211_policy, |
| 9980 | .flags = GENL_ADMIN_PERM, |
| 9981 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9982 | NL80211_FLAG_NEED_RTNL, |
| 9983 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 9984 | { |
| 9985 | .cmd = NL80211_CMD_SET_NOACK_MAP, |
| 9986 | .doit = nl80211_set_noack_map, |
| 9987 | .policy = nl80211_policy, |
| 9988 | .flags = GENL_ADMIN_PERM, |
| 9989 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9990 | NL80211_FLAG_NEED_RTNL, |
| 9991 | }, |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9992 | { |
| 9993 | .cmd = NL80211_CMD_START_P2P_DEVICE, |
| 9994 | .doit = nl80211_start_p2p_device, |
| 9995 | .policy = nl80211_policy, |
| 9996 | .flags = GENL_ADMIN_PERM, |
| 9997 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 9998 | NL80211_FLAG_NEED_RTNL, |
| 9999 | }, |
| 10000 | { |
| 10001 | .cmd = NL80211_CMD_STOP_P2P_DEVICE, |
| 10002 | .doit = nl80211_stop_p2p_device, |
| 10003 | .policy = nl80211_policy, |
| 10004 | .flags = GENL_ADMIN_PERM, |
| 10005 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 10006 | NL80211_FLAG_NEED_RTNL, |
| 10007 | }, |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 10008 | { |
| 10009 | .cmd = NL80211_CMD_SET_MCAST_RATE, |
| 10010 | .doit = nl80211_set_mcast_rate, |
| 10011 | .policy = nl80211_policy, |
| 10012 | .flags = GENL_ADMIN_PERM, |
| 10013 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 10014 | NL80211_FLAG_NEED_RTNL, |
| 10015 | }, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 10016 | { |
| 10017 | .cmd = NL80211_CMD_SET_MAC_ACL, |
| 10018 | .doit = nl80211_set_mac_acl, |
| 10019 | .policy = nl80211_policy, |
| 10020 | .flags = GENL_ADMIN_PERM, |
| 10021 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 10022 | NL80211_FLAG_NEED_RTNL, |
| 10023 | }, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 10024 | { |
| 10025 | .cmd = NL80211_CMD_RADAR_DETECT, |
| 10026 | .doit = nl80211_start_radar_detection, |
| 10027 | .policy = nl80211_policy, |
| 10028 | .flags = GENL_ADMIN_PERM, |
| 10029 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10030 | NL80211_FLAG_NEED_RTNL, |
| 10031 | }, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 10032 | { |
| 10033 | .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES, |
| 10034 | .doit = nl80211_get_protocol_features, |
| 10035 | .policy = nl80211_policy, |
| 10036 | }, |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 10037 | { |
| 10038 | .cmd = NL80211_CMD_UPDATE_FT_IES, |
| 10039 | .doit = nl80211_update_ft_ies, |
| 10040 | .policy = nl80211_policy, |
| 10041 | .flags = GENL_ADMIN_PERM, |
| 10042 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10043 | NL80211_FLAG_NEED_RTNL, |
| 10044 | }, |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 10045 | { |
| 10046 | .cmd = NL80211_CMD_CRIT_PROTOCOL_START, |
| 10047 | .doit = nl80211_crit_protocol_start, |
| 10048 | .policy = nl80211_policy, |
| 10049 | .flags = GENL_ADMIN_PERM, |
| 10050 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 10051 | NL80211_FLAG_NEED_RTNL, |
| 10052 | }, |
| 10053 | { |
| 10054 | .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP, |
| 10055 | .doit = nl80211_crit_protocol_stop, |
| 10056 | .policy = nl80211_policy, |
| 10057 | .flags = GENL_ADMIN_PERM, |
| 10058 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 10059 | NL80211_FLAG_NEED_RTNL, |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 10060 | }, |
| 10061 | { |
| 10062 | .cmd = NL80211_CMD_GET_COALESCE, |
| 10063 | .doit = nl80211_get_coalesce, |
| 10064 | .policy = nl80211_policy, |
| 10065 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 10066 | NL80211_FLAG_NEED_RTNL, |
| 10067 | }, |
| 10068 | { |
| 10069 | .cmd = NL80211_CMD_SET_COALESCE, |
| 10070 | .doit = nl80211_set_coalesce, |
| 10071 | .policy = nl80211_policy, |
| 10072 | .flags = GENL_ADMIN_PERM, |
| 10073 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 10074 | NL80211_FLAG_NEED_RTNL, |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 10075 | }, |
| 10076 | { |
| 10077 | .cmd = NL80211_CMD_CHANNEL_SWITCH, |
| 10078 | .doit = nl80211_channel_switch, |
| 10079 | .policy = nl80211_policy, |
| 10080 | .flags = GENL_ADMIN_PERM, |
| 10081 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10082 | NL80211_FLAG_NEED_RTNL, |
| 10083 | }, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 10084 | { |
| 10085 | .cmd = NL80211_CMD_VENDOR, |
| 10086 | .doit = nl80211_vendor_cmd, |
| 10087 | .policy = nl80211_policy, |
| 10088 | .flags = GENL_ADMIN_PERM, |
| 10089 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 10090 | NL80211_FLAG_NEED_RTNL, |
| 10091 | }, |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 10092 | { |
| 10093 | .cmd = NL80211_CMD_SET_QOS_MAP, |
| 10094 | .doit = nl80211_set_qos_map, |
| 10095 | .policy = nl80211_policy, |
| 10096 | .flags = GENL_ADMIN_PERM, |
| 10097 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10098 | NL80211_FLAG_NEED_RTNL, |
| 10099 | }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10100 | }; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10101 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10102 | /* notification functions */ |
| 10103 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 10104 | void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev, |
| 10105 | enum nl80211_commands cmd) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10106 | { |
| 10107 | struct sk_buff *msg; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 10108 | struct nl80211_dump_wiphy_state state = {}; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10109 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 10110 | WARN_ON(cmd != NL80211_CMD_NEW_WIPHY && |
| 10111 | cmd != NL80211_CMD_DEL_WIPHY); |
| 10112 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 10113 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10114 | if (!msg) |
| 10115 | return; |
| 10116 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 10117 | if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10118 | nlmsg_free(msg); |
| 10119 | return; |
| 10120 | } |
| 10121 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10122 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10123 | NL80211_MCGRP_CONFIG, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10124 | } |
| 10125 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 10126 | static int nl80211_add_scan_req(struct sk_buff *msg, |
| 10127 | struct cfg80211_registered_device *rdev) |
| 10128 | { |
| 10129 | struct cfg80211_scan_request *req = rdev->scan_req; |
| 10130 | struct nlattr *nest; |
| 10131 | int i; |
| 10132 | |
| 10133 | if (WARN_ON(!req)) |
| 10134 | return 0; |
| 10135 | |
| 10136 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); |
| 10137 | if (!nest) |
| 10138 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10139 | for (i = 0; i < req->n_ssids; i++) { |
| 10140 | if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) |
| 10141 | goto nla_put_failure; |
| 10142 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 10143 | nla_nest_end(msg, nest); |
| 10144 | |
| 10145 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 10146 | if (!nest) |
| 10147 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10148 | for (i = 0; i < req->n_channels; i++) { |
| 10149 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) |
| 10150 | goto nla_put_failure; |
| 10151 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 10152 | nla_nest_end(msg, nest); |
| 10153 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10154 | if (req->ie && |
| 10155 | nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie)) |
| 10156 | goto nla_put_failure; |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 10157 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 10158 | if (req->flags && |
| 10159 | nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags)) |
| 10160 | goto nla_put_failure; |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 10161 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 10162 | return 0; |
| 10163 | nla_put_failure: |
| 10164 | return -ENOBUFS; |
| 10165 | } |
| 10166 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 10167 | static int nl80211_send_scan_msg(struct sk_buff *msg, |
| 10168 | struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 10169 | struct wireless_dev *wdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10170 | u32 portid, u32 seq, int flags, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 10171 | u32 cmd) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10172 | { |
| 10173 | void *hdr; |
| 10174 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10175 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10176 | if (!hdr) |
| 10177 | return -1; |
| 10178 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10179 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 10180 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 10181 | wdev->netdev->ifindex)) || |
| 10182 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10183 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10184 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 10185 | /* ignore errors and send incomplete event anyway */ |
| 10186 | nl80211_add_scan_req(msg, rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10187 | |
| 10188 | return genlmsg_end(msg, hdr); |
| 10189 | |
| 10190 | nla_put_failure: |
| 10191 | genlmsg_cancel(msg, hdr); |
| 10192 | return -EMSGSIZE; |
| 10193 | } |
| 10194 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 10195 | static int |
| 10196 | nl80211_send_sched_scan_msg(struct sk_buff *msg, |
| 10197 | struct cfg80211_registered_device *rdev, |
| 10198 | struct net_device *netdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10199 | u32 portid, u32 seq, int flags, u32 cmd) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 10200 | { |
| 10201 | void *hdr; |
| 10202 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10203 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 10204 | if (!hdr) |
| 10205 | return -1; |
| 10206 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10207 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10208 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 10209 | goto nla_put_failure; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 10210 | |
| 10211 | return genlmsg_end(msg, hdr); |
| 10212 | |
| 10213 | nla_put_failure: |
| 10214 | genlmsg_cancel(msg, hdr); |
| 10215 | return -EMSGSIZE; |
| 10216 | } |
| 10217 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 10218 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 10219 | struct wireless_dev *wdev) |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 10220 | { |
| 10221 | struct sk_buff *msg; |
| 10222 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10223 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 10224 | if (!msg) |
| 10225 | return; |
| 10226 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 10227 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 10228 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
| 10229 | nlmsg_free(msg); |
| 10230 | return; |
| 10231 | } |
| 10232 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10233 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10234 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 10235 | } |
| 10236 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 10237 | struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev, |
| 10238 | struct wireless_dev *wdev, bool aborted) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10239 | { |
| 10240 | struct sk_buff *msg; |
| 10241 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 10242 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10243 | if (!msg) |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 10244 | return NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10245 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 10246 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 10247 | aborted ? NL80211_CMD_SCAN_ABORTED : |
| 10248 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10249 | nlmsg_free(msg); |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 10250 | return NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10251 | } |
| 10252 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 10253 | return msg; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10254 | } |
| 10255 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 10256 | void nl80211_send_scan_result(struct cfg80211_registered_device *rdev, |
| 10257 | struct sk_buff *msg) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10258 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10259 | if (!msg) |
| 10260 | return; |
| 10261 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10262 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10263 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10264 | } |
| 10265 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 10266 | void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev, |
| 10267 | struct net_device *netdev) |
| 10268 | { |
| 10269 | struct sk_buff *msg; |
| 10270 | |
| 10271 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 10272 | if (!msg) |
| 10273 | return; |
| 10274 | |
| 10275 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 10276 | NL80211_CMD_SCHED_SCAN_RESULTS) < 0) { |
| 10277 | nlmsg_free(msg); |
| 10278 | return; |
| 10279 | } |
| 10280 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10281 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10282 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 10283 | } |
| 10284 | |
| 10285 | void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev, |
| 10286 | struct net_device *netdev, u32 cmd) |
| 10287 | { |
| 10288 | struct sk_buff *msg; |
| 10289 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10290 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 10291 | if (!msg) |
| 10292 | return; |
| 10293 | |
| 10294 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) { |
| 10295 | nlmsg_free(msg); |
| 10296 | return; |
| 10297 | } |
| 10298 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10299 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10300 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 10301 | } |
| 10302 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 10303 | /* |
| 10304 | * This can happen on global regulatory changes or device specific settings |
| 10305 | * based on custom world regulatory domains. |
| 10306 | */ |
| 10307 | void nl80211_send_reg_change_event(struct regulatory_request *request) |
| 10308 | { |
| 10309 | struct sk_buff *msg; |
| 10310 | void *hdr; |
| 10311 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 10312 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 10313 | if (!msg) |
| 10314 | return; |
| 10315 | |
| 10316 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE); |
| 10317 | if (!hdr) { |
| 10318 | nlmsg_free(msg); |
| 10319 | return; |
| 10320 | } |
| 10321 | |
| 10322 | /* Userspace can always count this one always being set */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10323 | if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator)) |
| 10324 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 10325 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10326 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') { |
| 10327 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 10328 | NL80211_REGDOM_TYPE_WORLD)) |
| 10329 | goto nla_put_failure; |
| 10330 | } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') { |
| 10331 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 10332 | NL80211_REGDOM_TYPE_CUSTOM_WORLD)) |
| 10333 | goto nla_put_failure; |
| 10334 | } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || |
| 10335 | request->intersect) { |
| 10336 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 10337 | NL80211_REGDOM_TYPE_INTERSECTION)) |
| 10338 | goto nla_put_failure; |
| 10339 | } else { |
| 10340 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 10341 | NL80211_REGDOM_TYPE_COUNTRY) || |
| 10342 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, |
| 10343 | request->alpha2)) |
| 10344 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 10345 | } |
| 10346 | |
Johannes Berg | f417376 | 2012-12-03 18:23:37 +0100 | [diff] [blame] | 10347 | if (request->wiphy_idx != WIPHY_IDX_INVALID && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10348 | nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) |
| 10349 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 10350 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10351 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 10352 | |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 10353 | rcu_read_lock(); |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10354 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10355 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 10356 | rcu_read_unlock(); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 10357 | |
| 10358 | return; |
| 10359 | |
| 10360 | nla_put_failure: |
| 10361 | genlmsg_cancel(msg, hdr); |
| 10362 | nlmsg_free(msg); |
| 10363 | } |
| 10364 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10365 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
| 10366 | struct net_device *netdev, |
| 10367 | const u8 *buf, size_t len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10368 | enum nl80211_commands cmd, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10369 | { |
| 10370 | struct sk_buff *msg; |
| 10371 | void *hdr; |
| 10372 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10373 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10374 | if (!msg) |
| 10375 | return; |
| 10376 | |
| 10377 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 10378 | if (!hdr) { |
| 10379 | nlmsg_free(msg); |
| 10380 | return; |
| 10381 | } |
| 10382 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10383 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10384 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10385 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) |
| 10386 | goto nla_put_failure; |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10387 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10388 | genlmsg_end(msg, hdr); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10389 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10390 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10391 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10392 | return; |
| 10393 | |
| 10394 | nla_put_failure: |
| 10395 | genlmsg_cancel(msg, hdr); |
| 10396 | nlmsg_free(msg); |
| 10397 | } |
| 10398 | |
| 10399 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10400 | struct net_device *netdev, const u8 *buf, |
| 10401 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10402 | { |
| 10403 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10404 | NL80211_CMD_AUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10405 | } |
| 10406 | |
| 10407 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, |
| 10408 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10409 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10410 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10411 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 10412 | NL80211_CMD_ASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10413 | } |
| 10414 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 10415 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10416 | struct net_device *netdev, const u8 *buf, |
| 10417 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10418 | { |
| 10419 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10420 | NL80211_CMD_DEAUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10421 | } |
| 10422 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 10423 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
| 10424 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10425 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10426 | { |
| 10427 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10428 | NL80211_CMD_DISASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10429 | } |
| 10430 | |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 10431 | void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf, |
| 10432 | size_t len) |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 10433 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10434 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10435 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 10436 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 10437 | const struct ieee80211_mgmt *mgmt = (void *)buf; |
| 10438 | u32 cmd; |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 10439 | |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 10440 | if (WARN_ON(len < 2)) |
| 10441 | return; |
| 10442 | |
| 10443 | if (ieee80211_is_deauth(mgmt->frame_control)) |
| 10444 | cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE; |
| 10445 | else |
| 10446 | cmd = NL80211_CMD_UNPROT_DISASSOCIATE; |
| 10447 | |
| 10448 | trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len); |
| 10449 | nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC); |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 10450 | } |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 10451 | EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt); |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 10452 | |
Luis R. Rodriguez | 1b06bb4 | 2009-05-02 00:34:48 -0400 | [diff] [blame] | 10453 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
| 10454 | struct net_device *netdev, int cmd, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10455 | const u8 *addr, gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10456 | { |
| 10457 | struct sk_buff *msg; |
| 10458 | void *hdr; |
| 10459 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10460 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10461 | if (!msg) |
| 10462 | return; |
| 10463 | |
| 10464 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 10465 | if (!hdr) { |
| 10466 | nlmsg_free(msg); |
| 10467 | return; |
| 10468 | } |
| 10469 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10470 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10471 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10472 | nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || |
| 10473 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 10474 | goto nla_put_failure; |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10475 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10476 | genlmsg_end(msg, hdr); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10477 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10478 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10479 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10480 | return; |
| 10481 | |
| 10482 | nla_put_failure: |
| 10483 | genlmsg_cancel(msg, hdr); |
| 10484 | nlmsg_free(msg); |
| 10485 | } |
| 10486 | |
| 10487 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10488 | struct net_device *netdev, const u8 *addr, |
| 10489 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10490 | { |
| 10491 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10492 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10493 | } |
| 10494 | |
| 10495 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10496 | struct net_device *netdev, const u8 *addr, |
| 10497 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10498 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10499 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
| 10500 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10501 | } |
| 10502 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10503 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
| 10504 | struct net_device *netdev, const u8 *bssid, |
| 10505 | const u8 *req_ie, size_t req_ie_len, |
| 10506 | const u8 *resp_ie, size_t resp_ie_len, |
| 10507 | u16 status, gfp_t gfp) |
| 10508 | { |
| 10509 | struct sk_buff *msg; |
| 10510 | void *hdr; |
| 10511 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10512 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10513 | if (!msg) |
| 10514 | return; |
| 10515 | |
| 10516 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); |
| 10517 | if (!hdr) { |
| 10518 | nlmsg_free(msg); |
| 10519 | return; |
| 10520 | } |
| 10521 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10522 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10523 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10524 | (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) || |
| 10525 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) || |
| 10526 | (req_ie && |
| 10527 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 10528 | (resp_ie && |
| 10529 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 10530 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10531 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10532 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10533 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10534 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10535 | NL80211_MCGRP_MLME, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10536 | return; |
| 10537 | |
| 10538 | nla_put_failure: |
| 10539 | genlmsg_cancel(msg, hdr); |
| 10540 | nlmsg_free(msg); |
| 10541 | |
| 10542 | } |
| 10543 | |
| 10544 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, |
| 10545 | struct net_device *netdev, const u8 *bssid, |
| 10546 | const u8 *req_ie, size_t req_ie_len, |
| 10547 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) |
| 10548 | { |
| 10549 | struct sk_buff *msg; |
| 10550 | void *hdr; |
| 10551 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10552 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10553 | if (!msg) |
| 10554 | return; |
| 10555 | |
| 10556 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); |
| 10557 | if (!hdr) { |
| 10558 | nlmsg_free(msg); |
| 10559 | return; |
| 10560 | } |
| 10561 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10562 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10563 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10564 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) || |
| 10565 | (req_ie && |
| 10566 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 10567 | (resp_ie && |
| 10568 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 10569 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10570 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10571 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10572 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10573 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10574 | NL80211_MCGRP_MLME, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10575 | return; |
| 10576 | |
| 10577 | nla_put_failure: |
| 10578 | genlmsg_cancel(msg, hdr); |
| 10579 | nlmsg_free(msg); |
| 10580 | |
| 10581 | } |
| 10582 | |
| 10583 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, |
| 10584 | struct net_device *netdev, u16 reason, |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 10585 | const u8 *ie, size_t ie_len, bool from_ap) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10586 | { |
| 10587 | struct sk_buff *msg; |
| 10588 | void *hdr; |
| 10589 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10590 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10591 | if (!msg) |
| 10592 | return; |
| 10593 | |
| 10594 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); |
| 10595 | if (!hdr) { |
| 10596 | nlmsg_free(msg); |
| 10597 | return; |
| 10598 | } |
| 10599 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10600 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10601 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10602 | (from_ap && reason && |
| 10603 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) || |
| 10604 | (from_ap && |
| 10605 | nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) || |
| 10606 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) |
| 10607 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10608 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10609 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10610 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10611 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10612 | NL80211_MCGRP_MLME, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10613 | return; |
| 10614 | |
| 10615 | nla_put_failure: |
| 10616 | genlmsg_cancel(msg, hdr); |
| 10617 | nlmsg_free(msg); |
| 10618 | |
| 10619 | } |
| 10620 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10621 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
| 10622 | struct net_device *netdev, const u8 *bssid, |
| 10623 | gfp_t gfp) |
| 10624 | { |
| 10625 | struct sk_buff *msg; |
| 10626 | void *hdr; |
| 10627 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 10628 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10629 | if (!msg) |
| 10630 | return; |
| 10631 | |
| 10632 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); |
| 10633 | if (!hdr) { |
| 10634 | nlmsg_free(msg); |
| 10635 | return; |
| 10636 | } |
| 10637 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10638 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10639 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10640 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 10641 | goto nla_put_failure; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10642 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10643 | genlmsg_end(msg, hdr); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10644 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10645 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10646 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10647 | return; |
| 10648 | |
| 10649 | nla_put_failure: |
| 10650 | genlmsg_cancel(msg, hdr); |
| 10651 | nlmsg_free(msg); |
| 10652 | } |
| 10653 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10654 | void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr, |
| 10655 | const u8* ie, u8 ie_len, gfp_t gfp) |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10656 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10657 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 10658 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10659 | struct sk_buff *msg; |
| 10660 | void *hdr; |
| 10661 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10662 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT)) |
| 10663 | return; |
| 10664 | |
| 10665 | trace_cfg80211_notify_new_peer_candidate(dev, addr); |
| 10666 | |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10667 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 10668 | if (!msg) |
| 10669 | return; |
| 10670 | |
| 10671 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); |
| 10672 | if (!hdr) { |
| 10673 | nlmsg_free(msg); |
| 10674 | return; |
| 10675 | } |
| 10676 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10677 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10678 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 10679 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10680 | (ie_len && ie && |
| 10681 | nla_put(msg, NL80211_ATTR_IE, ie_len , ie))) |
| 10682 | goto nla_put_failure; |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10683 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10684 | genlmsg_end(msg, hdr); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10685 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10686 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10687 | NL80211_MCGRP_MLME, gfp); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10688 | return; |
| 10689 | |
| 10690 | nla_put_failure: |
| 10691 | genlmsg_cancel(msg, hdr); |
| 10692 | nlmsg_free(msg); |
| 10693 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10694 | EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10695 | |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 10696 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
| 10697 | struct net_device *netdev, const u8 *addr, |
| 10698 | enum nl80211_key_type key_type, int key_id, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10699 | const u8 *tsc, gfp_t gfp) |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 10700 | { |
| 10701 | struct sk_buff *msg; |
| 10702 | void *hdr; |
| 10703 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10704 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 10705 | if (!msg) |
| 10706 | return; |
| 10707 | |
| 10708 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); |
| 10709 | if (!hdr) { |
| 10710 | nlmsg_free(msg); |
| 10711 | return; |
| 10712 | } |
| 10713 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10714 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10715 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10716 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
| 10717 | nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) || |
| 10718 | (key_id != -1 && |
| 10719 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) || |
| 10720 | (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc))) |
| 10721 | goto nla_put_failure; |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 10722 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10723 | genlmsg_end(msg, hdr); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 10724 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10725 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10726 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 10727 | return; |
| 10728 | |
| 10729 | nla_put_failure: |
| 10730 | genlmsg_cancel(msg, hdr); |
| 10731 | nlmsg_free(msg); |
| 10732 | } |
| 10733 | |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10734 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
| 10735 | struct ieee80211_channel *channel_before, |
| 10736 | struct ieee80211_channel *channel_after) |
| 10737 | { |
| 10738 | struct sk_buff *msg; |
| 10739 | void *hdr; |
| 10740 | struct nlattr *nl_freq; |
| 10741 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 10742 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10743 | if (!msg) |
| 10744 | return; |
| 10745 | |
| 10746 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); |
| 10747 | if (!hdr) { |
| 10748 | nlmsg_free(msg); |
| 10749 | return; |
| 10750 | } |
| 10751 | |
| 10752 | /* |
| 10753 | * Since we are applying the beacon hint to a wiphy we know its |
| 10754 | * wiphy_idx is valid |
| 10755 | */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10756 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 10757 | goto nla_put_failure; |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10758 | |
| 10759 | /* Before */ |
| 10760 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); |
| 10761 | if (!nl_freq) |
| 10762 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 10763 | if (nl80211_msg_put_channel(msg, channel_before, false)) |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10764 | goto nla_put_failure; |
| 10765 | nla_nest_end(msg, nl_freq); |
| 10766 | |
| 10767 | /* After */ |
| 10768 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); |
| 10769 | if (!nl_freq) |
| 10770 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 10771 | if (nl80211_msg_put_channel(msg, channel_after, false)) |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10772 | goto nla_put_failure; |
| 10773 | nla_nest_end(msg, nl_freq); |
| 10774 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10775 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10776 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 10777 | rcu_read_lock(); |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10778 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10779 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 10780 | rcu_read_unlock(); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10781 | |
| 10782 | return; |
| 10783 | |
| 10784 | nla_put_failure: |
| 10785 | genlmsg_cancel(msg, hdr); |
| 10786 | nlmsg_free(msg); |
| 10787 | } |
| 10788 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10789 | static void nl80211_send_remain_on_chan_event( |
| 10790 | int cmd, struct cfg80211_registered_device *rdev, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10791 | struct wireless_dev *wdev, u64 cookie, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10792 | struct ieee80211_channel *chan, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10793 | unsigned int duration, gfp_t gfp) |
| 10794 | { |
| 10795 | struct sk_buff *msg; |
| 10796 | void *hdr; |
| 10797 | |
| 10798 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 10799 | if (!msg) |
| 10800 | return; |
| 10801 | |
| 10802 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 10803 | if (!hdr) { |
| 10804 | nlmsg_free(msg); |
| 10805 | return; |
| 10806 | } |
| 10807 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10808 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10809 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 10810 | wdev->netdev->ifindex)) || |
Johannes Berg | 00f5335 | 2012-07-17 11:53:12 +0200 | [diff] [blame] | 10811 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10812 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) || |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 10813 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 10814 | NL80211_CHAN_NO_HT) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10815 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 10816 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10817 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10818 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL && |
| 10819 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) |
| 10820 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10821 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10822 | genlmsg_end(msg, hdr); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10823 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10824 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10825 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10826 | return; |
| 10827 | |
| 10828 | nla_put_failure: |
| 10829 | genlmsg_cancel(msg, hdr); |
| 10830 | nlmsg_free(msg); |
| 10831 | } |
| 10832 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10833 | void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie, |
| 10834 | struct ieee80211_channel *chan, |
| 10835 | unsigned int duration, gfp_t gfp) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10836 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10837 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 10838 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10839 | |
| 10840 | trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10841 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10842 | rdev, wdev, cookie, chan, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 10843 | duration, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10844 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10845 | EXPORT_SYMBOL(cfg80211_ready_on_channel); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10846 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10847 | void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie, |
| 10848 | struct ieee80211_channel *chan, |
| 10849 | gfp_t gfp) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10850 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10851 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 10852 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10853 | |
| 10854 | trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10855 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 10856 | rdev, wdev, cookie, chan, 0, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10857 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10858 | EXPORT_SYMBOL(cfg80211_remain_on_channel_expired); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10859 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10860 | void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr, |
| 10861 | struct station_info *sinfo, gfp_t gfp) |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 10862 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10863 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 10864 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 10865 | struct sk_buff *msg; |
| 10866 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10867 | trace_cfg80211_new_sta(dev, mac_addr, sinfo); |
| 10868 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10869 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 10870 | if (!msg) |
| 10871 | return; |
| 10872 | |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 10873 | if (nl80211_send_station(msg, 0, 0, 0, |
| 10874 | rdev, dev, mac_addr, sinfo) < 0) { |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 10875 | nlmsg_free(msg); |
| 10876 | return; |
| 10877 | } |
| 10878 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10879 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10880 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 10881 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10882 | EXPORT_SYMBOL(cfg80211_new_sta); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 10883 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10884 | 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] | 10885 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10886 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 10887 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 10888 | struct sk_buff *msg; |
| 10889 | void *hdr; |
| 10890 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10891 | trace_cfg80211_del_sta(dev, mac_addr); |
| 10892 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10893 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 10894 | if (!msg) |
| 10895 | return; |
| 10896 | |
| 10897 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION); |
| 10898 | if (!hdr) { |
| 10899 | nlmsg_free(msg); |
| 10900 | return; |
| 10901 | } |
| 10902 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10903 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 10904 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 10905 | goto nla_put_failure; |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 10906 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10907 | genlmsg_end(msg, hdr); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 10908 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10909 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10910 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 10911 | return; |
| 10912 | |
| 10913 | nla_put_failure: |
| 10914 | genlmsg_cancel(msg, hdr); |
| 10915 | nlmsg_free(msg); |
| 10916 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10917 | EXPORT_SYMBOL(cfg80211_del_sta); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 10918 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10919 | void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr, |
| 10920 | enum nl80211_connect_failed_reason reason, |
| 10921 | gfp_t gfp) |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 10922 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10923 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 10924 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 10925 | struct sk_buff *msg; |
| 10926 | void *hdr; |
| 10927 | |
| 10928 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 10929 | if (!msg) |
| 10930 | return; |
| 10931 | |
| 10932 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED); |
| 10933 | if (!hdr) { |
| 10934 | nlmsg_free(msg); |
| 10935 | return; |
| 10936 | } |
| 10937 | |
| 10938 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 10939 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 10940 | nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason)) |
| 10941 | goto nla_put_failure; |
| 10942 | |
| 10943 | genlmsg_end(msg, hdr); |
| 10944 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10945 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10946 | NL80211_MCGRP_MLME, gfp); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 10947 | return; |
| 10948 | |
| 10949 | nla_put_failure: |
| 10950 | genlmsg_cancel(msg, hdr); |
| 10951 | nlmsg_free(msg); |
| 10952 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10953 | EXPORT_SYMBOL(cfg80211_conn_failed); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 10954 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 10955 | static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, |
| 10956 | const u8 *addr, gfp_t gfp) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10957 | { |
| 10958 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 10959 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10960 | struct sk_buff *msg; |
| 10961 | void *hdr; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10962 | u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10963 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10964 | if (!nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10965 | return false; |
| 10966 | |
| 10967 | msg = nlmsg_new(100, gfp); |
| 10968 | if (!msg) |
| 10969 | return true; |
| 10970 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 10971 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10972 | if (!hdr) { |
| 10973 | nlmsg_free(msg); |
| 10974 | return true; |
| 10975 | } |
| 10976 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10977 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10978 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 10979 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 10980 | goto nla_put_failure; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10981 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 10982 | genlmsg_end(msg, hdr); |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10983 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10984 | return true; |
| 10985 | |
| 10986 | nla_put_failure: |
| 10987 | genlmsg_cancel(msg, hdr); |
| 10988 | nlmsg_free(msg); |
| 10989 | return true; |
| 10990 | } |
| 10991 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10992 | bool cfg80211_rx_spurious_frame(struct net_device *dev, |
| 10993 | const u8 *addr, gfp_t gfp) |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 10994 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10995 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10996 | bool ret; |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 10997 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10998 | trace_cfg80211_rx_spurious_frame(dev, addr); |
| 10999 | |
| 11000 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 11001 | wdev->iftype != NL80211_IFTYPE_P2P_GO)) { |
| 11002 | trace_cfg80211_return_bool(false); |
| 11003 | return false; |
| 11004 | } |
| 11005 | ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, |
| 11006 | addr, gfp); |
| 11007 | trace_cfg80211_return_bool(ret); |
| 11008 | return ret; |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 11009 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11010 | EXPORT_SYMBOL(cfg80211_rx_spurious_frame); |
| 11011 | |
| 11012 | bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev, |
| 11013 | const u8 *addr, gfp_t gfp) |
| 11014 | { |
| 11015 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11016 | bool ret; |
| 11017 | |
| 11018 | trace_cfg80211_rx_unexpected_4addr_frame(dev, addr); |
| 11019 | |
| 11020 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 11021 | wdev->iftype != NL80211_IFTYPE_P2P_GO && |
| 11022 | wdev->iftype != NL80211_IFTYPE_AP_VLAN)) { |
| 11023 | trace_cfg80211_return_bool(false); |
| 11024 | return false; |
| 11025 | } |
| 11026 | ret = __nl80211_unexpected_frame(dev, |
| 11027 | NL80211_CMD_UNEXPECTED_4ADDR_FRAME, |
| 11028 | addr, gfp); |
| 11029 | trace_cfg80211_return_bool(ret); |
| 11030 | return ret; |
| 11031 | } |
| 11032 | EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame); |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 11033 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 11034 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11035 | struct wireless_dev *wdev, u32 nlportid, |
Johannes Berg | 804483e | 2012-03-05 22:18:41 +0100 | [diff] [blame] | 11036 | int freq, int sig_dbm, |
Vladimir Kondratiev | 19504cf | 2013-08-15 14:51:28 +0300 | [diff] [blame] | 11037 | const u8 *buf, size_t len, u32 flags, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11038 | { |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11039 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11040 | struct sk_buff *msg; |
| 11041 | void *hdr; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11042 | |
| 11043 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 11044 | if (!msg) |
| 11045 | return -ENOMEM; |
| 11046 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 11047 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11048 | if (!hdr) { |
| 11049 | nlmsg_free(msg); |
| 11050 | return -ENOMEM; |
| 11051 | } |
| 11052 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11053 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11054 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 11055 | netdev->ifindex)) || |
Ilan Peer | a838490 | 2013-05-08 16:35:55 +0300 | [diff] [blame] | 11056 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11057 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
| 11058 | (sig_dbm && |
| 11059 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
Vladimir Kondratiev | 19504cf | 2013-08-15 14:51:28 +0300 | [diff] [blame] | 11060 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
| 11061 | (flags && |
| 11062 | nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11063 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11064 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11065 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11066 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11067 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11068 | |
| 11069 | nla_put_failure: |
| 11070 | genlmsg_cancel(msg, hdr); |
| 11071 | nlmsg_free(msg); |
| 11072 | return -ENOBUFS; |
| 11073 | } |
| 11074 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11075 | void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie, |
| 11076 | const u8 *buf, size_t len, bool ack, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11077 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11078 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11079 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11080 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11081 | struct sk_buff *msg; |
| 11082 | void *hdr; |
| 11083 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11084 | trace_cfg80211_mgmt_tx_status(wdev, cookie, ack); |
| 11085 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11086 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 11087 | if (!msg) |
| 11088 | return; |
| 11089 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 11090 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11091 | if (!hdr) { |
| 11092 | nlmsg_free(msg); |
| 11093 | return; |
| 11094 | } |
| 11095 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11096 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11097 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 11098 | netdev->ifindex)) || |
Ilan Peer | a838490 | 2013-05-08 16:35:55 +0300 | [diff] [blame] | 11099 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11100 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
| 11101 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || |
| 11102 | (ack && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 11103 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11104 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11105 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11106 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11107 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11108 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11109 | return; |
| 11110 | |
| 11111 | nla_put_failure: |
| 11112 | genlmsg_cancel(msg, hdr); |
| 11113 | nlmsg_free(msg); |
| 11114 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11115 | EXPORT_SYMBOL(cfg80211_mgmt_tx_status); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11116 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11117 | void cfg80211_cqm_rssi_notify(struct net_device *dev, |
| 11118 | enum nl80211_cqm_rssi_threshold_event rssi_event, |
| 11119 | gfp_t gfp) |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11120 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11121 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11122 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11123 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11124 | struct sk_buff *msg; |
| 11125 | struct nlattr *pinfoattr; |
| 11126 | void *hdr; |
| 11127 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11128 | trace_cfg80211_cqm_rssi_notify(dev, rssi_event); |
| 11129 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11130 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11131 | if (!msg) |
| 11132 | return; |
| 11133 | |
| 11134 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 11135 | if (!hdr) { |
| 11136 | nlmsg_free(msg); |
| 11137 | return; |
| 11138 | } |
| 11139 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11140 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11141 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11142 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11143 | |
| 11144 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 11145 | if (!pinfoattr) |
| 11146 | goto nla_put_failure; |
| 11147 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11148 | if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, |
| 11149 | rssi_event)) |
| 11150 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11151 | |
| 11152 | nla_nest_end(msg, pinfoattr); |
| 11153 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11154 | genlmsg_end(msg, hdr); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11155 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11156 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11157 | NL80211_MCGRP_MLME, gfp); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11158 | return; |
| 11159 | |
| 11160 | nla_put_failure: |
| 11161 | genlmsg_cancel(msg, hdr); |
| 11162 | nlmsg_free(msg); |
| 11163 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11164 | EXPORT_SYMBOL(cfg80211_cqm_rssi_notify); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11165 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11166 | static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
| 11167 | struct net_device *netdev, const u8 *bssid, |
| 11168 | const u8 *replay_ctr, gfp_t gfp) |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 11169 | { |
| 11170 | struct sk_buff *msg; |
| 11171 | struct nlattr *rekey_attr; |
| 11172 | void *hdr; |
| 11173 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11174 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 11175 | if (!msg) |
| 11176 | return; |
| 11177 | |
| 11178 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); |
| 11179 | if (!hdr) { |
| 11180 | nlmsg_free(msg); |
| 11181 | return; |
| 11182 | } |
| 11183 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11184 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11185 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 11186 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 11187 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 11188 | |
| 11189 | rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); |
| 11190 | if (!rekey_attr) |
| 11191 | goto nla_put_failure; |
| 11192 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11193 | if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
| 11194 | NL80211_REPLAY_CTR_LEN, replay_ctr)) |
| 11195 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 11196 | |
| 11197 | nla_nest_end(msg, rekey_attr); |
| 11198 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11199 | genlmsg_end(msg, hdr); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 11200 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11201 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11202 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 11203 | return; |
| 11204 | |
| 11205 | nla_put_failure: |
| 11206 | genlmsg_cancel(msg, hdr); |
| 11207 | nlmsg_free(msg); |
| 11208 | } |
| 11209 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11210 | void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid, |
| 11211 | const u8 *replay_ctr, gfp_t gfp) |
| 11212 | { |
| 11213 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11214 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11215 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11216 | |
| 11217 | trace_cfg80211_gtk_rekey_notify(dev, bssid); |
| 11218 | nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp); |
| 11219 | } |
| 11220 | EXPORT_SYMBOL(cfg80211_gtk_rekey_notify); |
| 11221 | |
| 11222 | static void |
| 11223 | nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, |
| 11224 | struct net_device *netdev, int index, |
| 11225 | const u8 *bssid, bool preauth, gfp_t gfp) |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 11226 | { |
| 11227 | struct sk_buff *msg; |
| 11228 | struct nlattr *attr; |
| 11229 | void *hdr; |
| 11230 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11231 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 11232 | if (!msg) |
| 11233 | return; |
| 11234 | |
| 11235 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); |
| 11236 | if (!hdr) { |
| 11237 | nlmsg_free(msg); |
| 11238 | return; |
| 11239 | } |
| 11240 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11241 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11242 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 11243 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 11244 | |
| 11245 | attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE); |
| 11246 | if (!attr) |
| 11247 | goto nla_put_failure; |
| 11248 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11249 | if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) || |
| 11250 | nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) || |
| 11251 | (preauth && |
| 11252 | nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH))) |
| 11253 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 11254 | |
| 11255 | nla_nest_end(msg, attr); |
| 11256 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11257 | genlmsg_end(msg, hdr); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 11258 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11259 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11260 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 11261 | return; |
| 11262 | |
| 11263 | nla_put_failure: |
| 11264 | genlmsg_cancel(msg, hdr); |
| 11265 | nlmsg_free(msg); |
| 11266 | } |
| 11267 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11268 | void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index, |
| 11269 | const u8 *bssid, bool preauth, gfp_t gfp) |
| 11270 | { |
| 11271 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11272 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11273 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11274 | |
| 11275 | trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth); |
| 11276 | nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp); |
| 11277 | } |
| 11278 | EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify); |
| 11279 | |
| 11280 | static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev, |
| 11281 | struct net_device *netdev, |
| 11282 | struct cfg80211_chan_def *chandef, |
| 11283 | gfp_t gfp) |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 11284 | { |
| 11285 | struct sk_buff *msg; |
| 11286 | void *hdr; |
| 11287 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11288 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 11289 | if (!msg) |
| 11290 | return; |
| 11291 | |
| 11292 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY); |
| 11293 | if (!hdr) { |
| 11294 | nlmsg_free(msg); |
| 11295 | return; |
| 11296 | } |
| 11297 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 11298 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 11299 | goto nla_put_failure; |
| 11300 | |
| 11301 | if (nl80211_send_chandef(msg, chandef)) |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 11302 | goto nla_put_failure; |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 11303 | |
| 11304 | genlmsg_end(msg, hdr); |
| 11305 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11306 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11307 | NL80211_MCGRP_MLME, gfp); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 11308 | return; |
| 11309 | |
| 11310 | nla_put_failure: |
| 11311 | genlmsg_cancel(msg, hdr); |
| 11312 | nlmsg_free(msg); |
| 11313 | } |
| 11314 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11315 | void cfg80211_ch_switch_notify(struct net_device *dev, |
| 11316 | struct cfg80211_chan_def *chandef) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 11317 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11318 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11319 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11320 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11321 | |
Simon Wunderlich | e487eae | 2013-11-21 18:19:51 +0100 | [diff] [blame] | 11322 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11323 | |
Simon Wunderlich | e487eae | 2013-11-21 18:19:51 +0100 | [diff] [blame] | 11324 | trace_cfg80211_ch_switch_notify(dev, chandef); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11325 | |
| 11326 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 11327 | wdev->iftype != NL80211_IFTYPE_P2P_GO && |
Chun-Yeow Yeoh | b8456a1 | 2013-10-17 15:55:02 -0700 | [diff] [blame] | 11328 | wdev->iftype != NL80211_IFTYPE_ADHOC && |
| 11329 | wdev->iftype != NL80211_IFTYPE_MESH_POINT)) |
Simon Wunderlich | e487eae | 2013-11-21 18:19:51 +0100 | [diff] [blame] | 11330 | return; |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11331 | |
Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 11332 | wdev->chandef = *chandef; |
Janusz Dziedzic | 96f55f1 | 2014-01-24 14:29:21 +0100 | [diff] [blame] | 11333 | wdev->preset_chandef = *chandef; |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11334 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11335 | } |
| 11336 | EXPORT_SYMBOL(cfg80211_ch_switch_notify); |
| 11337 | |
| 11338 | void cfg80211_cqm_txe_notify(struct net_device *dev, |
| 11339 | const u8 *peer, u32 num_packets, |
| 11340 | u32 rate, u32 intvl, gfp_t gfp) |
| 11341 | { |
| 11342 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11343 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11344 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 11345 | struct sk_buff *msg; |
| 11346 | struct nlattr *pinfoattr; |
| 11347 | void *hdr; |
| 11348 | |
| 11349 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 11350 | if (!msg) |
| 11351 | return; |
| 11352 | |
| 11353 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 11354 | if (!hdr) { |
| 11355 | nlmsg_free(msg); |
| 11356 | return; |
| 11357 | } |
| 11358 | |
| 11359 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11360 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 11361 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
| 11362 | goto nla_put_failure; |
| 11363 | |
| 11364 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 11365 | if (!pinfoattr) |
| 11366 | goto nla_put_failure; |
| 11367 | |
| 11368 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets)) |
| 11369 | goto nla_put_failure; |
| 11370 | |
| 11371 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate)) |
| 11372 | goto nla_put_failure; |
| 11373 | |
| 11374 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl)) |
| 11375 | goto nla_put_failure; |
| 11376 | |
| 11377 | nla_nest_end(msg, pinfoattr); |
| 11378 | |
| 11379 | genlmsg_end(msg, hdr); |
| 11380 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11381 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11382 | NL80211_MCGRP_MLME, gfp); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 11383 | return; |
| 11384 | |
| 11385 | nla_put_failure: |
| 11386 | genlmsg_cancel(msg, hdr); |
| 11387 | nlmsg_free(msg); |
| 11388 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11389 | EXPORT_SYMBOL(cfg80211_cqm_txe_notify); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 11390 | |
| 11391 | void |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 11392 | nl80211_radar_notify(struct cfg80211_registered_device *rdev, |
Janusz Dziedzic | d2859df | 2013-11-06 13:55:51 +0100 | [diff] [blame] | 11393 | const struct cfg80211_chan_def *chandef, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 11394 | enum nl80211_radar_event event, |
| 11395 | struct net_device *netdev, gfp_t gfp) |
| 11396 | { |
| 11397 | struct sk_buff *msg; |
| 11398 | void *hdr; |
| 11399 | |
| 11400 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 11401 | if (!msg) |
| 11402 | return; |
| 11403 | |
| 11404 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT); |
| 11405 | if (!hdr) { |
| 11406 | nlmsg_free(msg); |
| 11407 | return; |
| 11408 | } |
| 11409 | |
| 11410 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 11411 | goto nla_put_failure; |
| 11412 | |
| 11413 | /* NOP and radar events don't need a netdev parameter */ |
| 11414 | if (netdev) { |
| 11415 | struct wireless_dev *wdev = netdev->ieee80211_ptr; |
| 11416 | |
| 11417 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 11418 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 11419 | goto nla_put_failure; |
| 11420 | } |
| 11421 | |
| 11422 | if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event)) |
| 11423 | goto nla_put_failure; |
| 11424 | |
| 11425 | if (nl80211_send_chandef(msg, chandef)) |
| 11426 | goto nla_put_failure; |
| 11427 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 11428 | genlmsg_end(msg, hdr); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 11429 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11430 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11431 | NL80211_MCGRP_MLME, gfp); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 11432 | return; |
| 11433 | |
| 11434 | nla_put_failure: |
| 11435 | genlmsg_cancel(msg, hdr); |
| 11436 | nlmsg_free(msg); |
| 11437 | } |
| 11438 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11439 | void cfg80211_cqm_pktloss_notify(struct net_device *dev, |
| 11440 | const u8 *peer, u32 num_packets, gfp_t gfp) |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 11441 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11442 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11443 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11444 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 11445 | struct sk_buff *msg; |
| 11446 | struct nlattr *pinfoattr; |
| 11447 | void *hdr; |
| 11448 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11449 | trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets); |
| 11450 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11451 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 11452 | if (!msg) |
| 11453 | return; |
| 11454 | |
| 11455 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 11456 | if (!hdr) { |
| 11457 | nlmsg_free(msg); |
| 11458 | return; |
| 11459 | } |
| 11460 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11461 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11462 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11463 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
| 11464 | goto nla_put_failure; |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 11465 | |
| 11466 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 11467 | if (!pinfoattr) |
| 11468 | goto nla_put_failure; |
| 11469 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11470 | if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets)) |
| 11471 | goto nla_put_failure; |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 11472 | |
| 11473 | nla_nest_end(msg, pinfoattr); |
| 11474 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11475 | genlmsg_end(msg, hdr); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 11476 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11477 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11478 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 11479 | return; |
| 11480 | |
| 11481 | nla_put_failure: |
| 11482 | genlmsg_cancel(msg, hdr); |
| 11483 | nlmsg_free(msg); |
| 11484 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11485 | EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 11486 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11487 | void cfg80211_probe_status(struct net_device *dev, const u8 *addr, |
| 11488 | u64 cookie, bool acked, gfp_t gfp) |
| 11489 | { |
| 11490 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11491 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11492 | struct sk_buff *msg; |
| 11493 | void *hdr; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11494 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 11495 | trace_cfg80211_probe_status(dev, addr, cookie, acked); |
| 11496 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11497 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 11498 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11499 | if (!msg) |
| 11500 | return; |
| 11501 | |
| 11502 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); |
| 11503 | if (!hdr) { |
| 11504 | nlmsg_free(msg); |
| 11505 | return; |
| 11506 | } |
| 11507 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11508 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11509 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 11510 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 11511 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || |
| 11512 | (acked && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 11513 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11514 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 11515 | genlmsg_end(msg, hdr); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11516 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11517 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11518 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11519 | return; |
| 11520 | |
| 11521 | nla_put_failure: |
| 11522 | genlmsg_cancel(msg, hdr); |
| 11523 | nlmsg_free(msg); |
| 11524 | } |
| 11525 | EXPORT_SYMBOL(cfg80211_probe_status); |
| 11526 | |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11527 | void cfg80211_report_obss_beacon(struct wiphy *wiphy, |
| 11528 | const u8 *frame, size_t len, |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11529 | int freq, int sig_dbm) |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11530 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11531 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11532 | struct sk_buff *msg; |
| 11533 | void *hdr; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11534 | struct cfg80211_beacon_registration *reg; |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11535 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 11536 | trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm); |
| 11537 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11538 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 11539 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 11540 | msg = nlmsg_new(len + 100, GFP_ATOMIC); |
| 11541 | if (!msg) { |
| 11542 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 11543 | return; |
| 11544 | } |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11545 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11546 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
| 11547 | if (!hdr) |
| 11548 | goto nla_put_failure; |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11549 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11550 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11551 | (freq && |
| 11552 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || |
| 11553 | (sig_dbm && |
| 11554 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
| 11555 | nla_put(msg, NL80211_ATTR_FRAME, len, frame)) |
| 11556 | goto nla_put_failure; |
| 11557 | |
| 11558 | genlmsg_end(msg, hdr); |
| 11559 | |
| 11560 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid); |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11561 | } |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11562 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11563 | return; |
| 11564 | |
| 11565 | nla_put_failure: |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11566 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 11567 | if (hdr) |
| 11568 | genlmsg_cancel(msg, hdr); |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11569 | nlmsg_free(msg); |
| 11570 | } |
| 11571 | EXPORT_SYMBOL(cfg80211_report_obss_beacon); |
| 11572 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 11573 | #ifdef CONFIG_PM |
| 11574 | void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev, |
| 11575 | struct cfg80211_wowlan_wakeup *wakeup, |
| 11576 | gfp_t gfp) |
| 11577 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11578 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 11579 | struct sk_buff *msg; |
| 11580 | void *hdr; |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 11581 | int size = 200; |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 11582 | |
| 11583 | trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup); |
| 11584 | |
| 11585 | if (wakeup) |
| 11586 | size += wakeup->packet_present_len; |
| 11587 | |
| 11588 | msg = nlmsg_new(size, gfp); |
| 11589 | if (!msg) |
| 11590 | return; |
| 11591 | |
| 11592 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN); |
| 11593 | if (!hdr) |
| 11594 | goto free_msg; |
| 11595 | |
| 11596 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11597 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 11598 | goto free_msg; |
| 11599 | |
| 11600 | if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 11601 | wdev->netdev->ifindex)) |
| 11602 | goto free_msg; |
| 11603 | |
| 11604 | if (wakeup) { |
| 11605 | struct nlattr *reasons; |
| 11606 | |
| 11607 | reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
Johannes Berg | 7fa322c | 2013-10-25 11:16:58 +0200 | [diff] [blame] | 11608 | if (!reasons) |
| 11609 | goto free_msg; |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 11610 | |
| 11611 | if (wakeup->disconnect && |
| 11612 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) |
| 11613 | goto free_msg; |
| 11614 | if (wakeup->magic_pkt && |
| 11615 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) |
| 11616 | goto free_msg; |
| 11617 | if (wakeup->gtk_rekey_failure && |
| 11618 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) |
| 11619 | goto free_msg; |
| 11620 | if (wakeup->eap_identity_req && |
| 11621 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) |
| 11622 | goto free_msg; |
| 11623 | if (wakeup->four_way_handshake && |
| 11624 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) |
| 11625 | goto free_msg; |
| 11626 | if (wakeup->rfkill_release && |
| 11627 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)) |
| 11628 | goto free_msg; |
| 11629 | |
| 11630 | if (wakeup->pattern_idx >= 0 && |
| 11631 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 11632 | wakeup->pattern_idx)) |
| 11633 | goto free_msg; |
| 11634 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 11635 | if (wakeup->tcp_match && |
| 11636 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH)) |
| 11637 | goto free_msg; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11638 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 11639 | if (wakeup->tcp_connlost && |
| 11640 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST)) |
| 11641 | goto free_msg; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11642 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 11643 | if (wakeup->tcp_nomoretokens && |
| 11644 | nla_put_flag(msg, |
| 11645 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS)) |
| 11646 | goto free_msg; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11647 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 11648 | if (wakeup->packet) { |
| 11649 | u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211; |
| 11650 | u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN; |
| 11651 | |
| 11652 | if (!wakeup->packet_80211) { |
| 11653 | pkt_attr = |
| 11654 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023; |
| 11655 | len_attr = |
| 11656 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN; |
| 11657 | } |
| 11658 | |
| 11659 | if (wakeup->packet_len && |
| 11660 | nla_put_u32(msg, len_attr, wakeup->packet_len)) |
| 11661 | goto free_msg; |
| 11662 | |
| 11663 | if (nla_put(msg, pkt_attr, wakeup->packet_present_len, |
| 11664 | wakeup->packet)) |
| 11665 | goto free_msg; |
| 11666 | } |
| 11667 | |
| 11668 | nla_nest_end(msg, reasons); |
| 11669 | } |
| 11670 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 11671 | genlmsg_end(msg, hdr); |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 11672 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11673 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11674 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 11675 | return; |
| 11676 | |
| 11677 | free_msg: |
| 11678 | nlmsg_free(msg); |
| 11679 | } |
| 11680 | EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup); |
| 11681 | #endif |
| 11682 | |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 11683 | void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer, |
| 11684 | enum nl80211_tdls_operation oper, |
| 11685 | u16 reason_code, gfp_t gfp) |
| 11686 | { |
| 11687 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11688 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 11689 | struct sk_buff *msg; |
| 11690 | void *hdr; |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 11691 | |
| 11692 | trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper, |
| 11693 | reason_code); |
| 11694 | |
| 11695 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 11696 | if (!msg) |
| 11697 | return; |
| 11698 | |
| 11699 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER); |
| 11700 | if (!hdr) { |
| 11701 | nlmsg_free(msg); |
| 11702 | return; |
| 11703 | } |
| 11704 | |
| 11705 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11706 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 11707 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) || |
| 11708 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) || |
| 11709 | (reason_code > 0 && |
| 11710 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) |
| 11711 | goto nla_put_failure; |
| 11712 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 11713 | genlmsg_end(msg, hdr); |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 11714 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11715 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11716 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 11717 | return; |
| 11718 | |
| 11719 | nla_put_failure: |
| 11720 | genlmsg_cancel(msg, hdr); |
| 11721 | nlmsg_free(msg); |
| 11722 | } |
| 11723 | EXPORT_SYMBOL(cfg80211_tdls_oper_request); |
| 11724 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11725 | static int nl80211_netlink_notify(struct notifier_block * nb, |
| 11726 | unsigned long state, |
| 11727 | void *_notify) |
| 11728 | { |
| 11729 | struct netlink_notify *notify = _notify; |
| 11730 | struct cfg80211_registered_device *rdev; |
| 11731 | struct wireless_dev *wdev; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11732 | struct cfg80211_beacon_registration *reg, *tmp; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11733 | |
| 11734 | if (state != NETLINK_URELEASE) |
| 11735 | return NOTIFY_DONE; |
| 11736 | |
| 11737 | rcu_read_lock(); |
| 11738 | |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11739 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 11740 | bool schedule_destroy_work = false; |
| 11741 | |
| 11742 | list_for_each_entry_rcu(wdev, &rdev->wdev_list, list) { |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11743 | cfg80211_mlme_unregister_socket(wdev, notify->portid); |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11744 | |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 11745 | if (wdev->owner_nlportid == notify->portid) |
| 11746 | schedule_destroy_work = true; |
| 11747 | } |
| 11748 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11749 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 11750 | list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations, |
| 11751 | list) { |
| 11752 | if (reg->nlportid == notify->portid) { |
| 11753 | list_del(®->list); |
| 11754 | kfree(reg); |
| 11755 | break; |
| 11756 | } |
| 11757 | } |
| 11758 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 11759 | |
| 11760 | if (schedule_destroy_work) { |
| 11761 | struct cfg80211_iface_destroy *destroy; |
| 11762 | |
| 11763 | destroy = kzalloc(sizeof(*destroy), GFP_ATOMIC); |
| 11764 | if (destroy) { |
| 11765 | destroy->nlportid = notify->portid; |
| 11766 | spin_lock(&rdev->destroy_list_lock); |
| 11767 | list_add(&destroy->list, &rdev->destroy_list); |
| 11768 | spin_unlock(&rdev->destroy_list_lock); |
| 11769 | schedule_work(&rdev->destroy_work); |
| 11770 | } |
| 11771 | } |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11772 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11773 | |
| 11774 | rcu_read_unlock(); |
| 11775 | |
Zhao, Gang | 6784c7d | 2014-04-21 12:53:04 +0800 | [diff] [blame] | 11776 | return NOTIFY_OK; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11777 | } |
| 11778 | |
| 11779 | static struct notifier_block nl80211_netlink_notifier = { |
| 11780 | .notifier_call = nl80211_netlink_notify, |
| 11781 | }; |
| 11782 | |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 11783 | void cfg80211_ft_event(struct net_device *netdev, |
| 11784 | struct cfg80211_ft_event_params *ft_event) |
| 11785 | { |
| 11786 | struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11787 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 11788 | struct sk_buff *msg; |
| 11789 | void *hdr; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 11790 | |
| 11791 | trace_cfg80211_ft_event(wiphy, netdev, ft_event); |
| 11792 | |
| 11793 | if (!ft_event->target_ap) |
| 11794 | return; |
| 11795 | |
| 11796 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 11797 | if (!msg) |
| 11798 | return; |
| 11799 | |
| 11800 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT); |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 11801 | if (!hdr) |
| 11802 | goto out; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 11803 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 11804 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11805 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 11806 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap)) |
| 11807 | goto out; |
| 11808 | |
| 11809 | if (ft_event->ies && |
| 11810 | nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies)) |
| 11811 | goto out; |
| 11812 | if (ft_event->ric_ies && |
| 11813 | nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len, |
| 11814 | ft_event->ric_ies)) |
| 11815 | goto out; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 11816 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 11817 | genlmsg_end(msg, hdr); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 11818 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11819 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11820 | NL80211_MCGRP_MLME, GFP_KERNEL); |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 11821 | return; |
| 11822 | out: |
| 11823 | nlmsg_free(msg); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 11824 | } |
| 11825 | EXPORT_SYMBOL(cfg80211_ft_event); |
| 11826 | |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 11827 | void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp) |
| 11828 | { |
| 11829 | struct cfg80211_registered_device *rdev; |
| 11830 | struct sk_buff *msg; |
| 11831 | void *hdr; |
| 11832 | u32 nlportid; |
| 11833 | |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11834 | rdev = wiphy_to_rdev(wdev->wiphy); |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 11835 | if (!rdev->crit_proto_nlportid) |
| 11836 | return; |
| 11837 | |
| 11838 | nlportid = rdev->crit_proto_nlportid; |
| 11839 | rdev->crit_proto_nlportid = 0; |
| 11840 | |
| 11841 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 11842 | if (!msg) |
| 11843 | return; |
| 11844 | |
| 11845 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP); |
| 11846 | if (!hdr) |
| 11847 | goto nla_put_failure; |
| 11848 | |
| 11849 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11850 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 11851 | goto nla_put_failure; |
| 11852 | |
| 11853 | genlmsg_end(msg, hdr); |
| 11854 | |
| 11855 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
| 11856 | return; |
| 11857 | |
| 11858 | nla_put_failure: |
| 11859 | if (hdr) |
| 11860 | genlmsg_cancel(msg, hdr); |
| 11861 | nlmsg_free(msg); |
| 11862 | |
| 11863 | } |
| 11864 | EXPORT_SYMBOL(cfg80211_crit_proto_stopped); |
| 11865 | |
Johannes Berg | 348baf0 | 2014-01-24 14:06:29 +0100 | [diff] [blame] | 11866 | void nl80211_send_ap_stopped(struct wireless_dev *wdev) |
| 11867 | { |
| 11868 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11869 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 348baf0 | 2014-01-24 14:06:29 +0100 | [diff] [blame] | 11870 | struct sk_buff *msg; |
| 11871 | void *hdr; |
| 11872 | |
| 11873 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 11874 | if (!msg) |
| 11875 | return; |
| 11876 | |
| 11877 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP); |
| 11878 | if (!hdr) |
| 11879 | goto out; |
| 11880 | |
| 11881 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11882 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) || |
| 11883 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 11884 | goto out; |
| 11885 | |
| 11886 | genlmsg_end(msg, hdr); |
| 11887 | |
| 11888 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0, |
| 11889 | NL80211_MCGRP_MLME, GFP_KERNEL); |
| 11890 | return; |
| 11891 | out: |
| 11892 | nlmsg_free(msg); |
| 11893 | } |
| 11894 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11895 | /* initialisation/exit functions */ |
| 11896 | |
| 11897 | int nl80211_init(void) |
| 11898 | { |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 11899 | int err; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11900 | |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11901 | err = genl_register_family_with_ops_groups(&nl80211_fam, nl80211_ops, |
| 11902 | nl80211_mcgrps); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11903 | if (err) |
| 11904 | return err; |
| 11905 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11906 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
| 11907 | if (err) |
| 11908 | goto err_out; |
| 11909 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11910 | return 0; |
| 11911 | err_out: |
| 11912 | genl_unregister_family(&nl80211_fam); |
| 11913 | return err; |
| 11914 | } |
| 11915 | |
| 11916 | void nl80211_exit(void) |
| 11917 | { |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11918 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11919 | genl_unregister_family(&nl80211_fam); |
| 11920 | } |