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 }, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 340 | [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG }, |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 341 | [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY, |
| 342 | .len = IEEE80211_MAX_DATA_LEN }, |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 343 | [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 }, |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 344 | [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG }, |
| 345 | [NL80211_ATTR_HT_CAPABILITY_MASK] = { |
| 346 | .len = NL80211_HT_CAPABILITY_LEN |
| 347 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 348 | [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 }, |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 349 | [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 }, |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 350 | [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 }, |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 351 | [NL80211_ATTR_WDEV] = { .type = NLA_U64 }, |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 352 | [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 }, |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 353 | [NL80211_ATTR_SAE_DATA] = { .type = NLA_BINARY, }, |
Mahesh Palivela | f461be3e | 2012-10-11 08:04:52 +0000 | [diff] [blame] | 354 | [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN }, |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 355 | [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 }, |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 356 | [NL80211_ATTR_P2P_CTWINDOW] = { .type = NLA_U8 }, |
| 357 | [NL80211_ATTR_P2P_OPPPS] = { .type = NLA_U8 }, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 358 | [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 }, |
| 359 | [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED }, |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 360 | [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 }, |
| 361 | [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, }, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 362 | [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, }, |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 363 | [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG }, |
| 364 | [NL80211_ATTR_VHT_CAPABILITY_MASK] = { |
| 365 | .len = NL80211_VHT_CAPABILITY_LEN, |
| 366 | }, |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 367 | [NL80211_ATTR_MDID] = { .type = NLA_U16 }, |
| 368 | [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY, |
| 369 | .len = IEEE80211_MAX_DATA_LEN }, |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 370 | [NL80211_ATTR_PEER_AID] = { .type = NLA_U16 }, |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 371 | [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 }, |
| 372 | [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG }, |
| 373 | [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED }, |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 374 | [NL80211_ATTR_CSA_C_OFF_BEACON] = { .type = NLA_BINARY }, |
| 375 | [NL80211_ATTR_CSA_C_OFF_PRESP] = { .type = NLA_BINARY }, |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 376 | [NL80211_ATTR_STA_SUPPORTED_CHANNELS] = { .type = NLA_BINARY }, |
| 377 | [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES] = { .type = NLA_BINARY }, |
Simon Wunderlich | 5336fa8 | 2013-10-07 18:41:05 +0200 | [diff] [blame] | 378 | [NL80211_ATTR_HANDLE_DFS] = { .type = NLA_FLAG }, |
Marek Kwaczynski | 60f4a7b | 2013-12-03 10:04:59 +0100 | [diff] [blame] | 379 | [NL80211_ATTR_OPMODE_NOTIF] = { .type = NLA_U8 }, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 380 | [NL80211_ATTR_VENDOR_ID] = { .type = NLA_U32 }, |
| 381 | [NL80211_ATTR_VENDOR_SUBCMD] = { .type = NLA_U32 }, |
| 382 | [NL80211_ATTR_VENDOR_DATA] = { .type = NLA_BINARY }, |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 383 | [NL80211_ATTR_QOS_MAP] = { .type = NLA_BINARY, |
| 384 | .len = IEEE80211_QOS_MAP_LEN_MAX }, |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 385 | [NL80211_ATTR_MAC_HINT] = { .len = ETH_ALEN }, |
| 386 | [NL80211_ATTR_WIPHY_FREQ_HINT] = { .type = NLA_U32 }, |
Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 387 | [NL80211_ATTR_TDLS_PEER_CAPABILITY] = { .type = NLA_U32 }, |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 388 | [NL80211_ATTR_IFACE_SOCKET_OWNER] = { .type = NLA_FLAG }, |
Andrei Otcheretianski | 34d22ce | 2014-05-09 14:11:44 +0300 | [diff] [blame] | 389 | [NL80211_ATTR_CSA_C_OFFSETS_TX] = { .type = NLA_BINARY }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 390 | }; |
| 391 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 392 | /* policy for the key attributes */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 393 | static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 394 | [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 395 | [NL80211_KEY_IDX] = { .type = NLA_U8 }, |
| 396 | [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, |
Jouni Malinen | 8196226 | 2011-11-02 23:36:31 +0200 | [diff] [blame] | 397 | [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 398 | [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, |
| 399 | [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 400 | [NL80211_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 401 | [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
| 402 | }; |
| 403 | |
| 404 | /* policy for the key default flags */ |
| 405 | static const struct nla_policy |
| 406 | nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = { |
| 407 | [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG }, |
| 408 | [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 409 | }; |
| 410 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 411 | /* policy for WoWLAN attributes */ |
| 412 | static const struct nla_policy |
| 413 | nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = { |
| 414 | [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG }, |
| 415 | [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG }, |
| 416 | [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG }, |
| 417 | [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED }, |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 418 | [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG }, |
| 419 | [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG }, |
| 420 | [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG }, |
| 421 | [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG }, |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 422 | [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED }, |
| 423 | }; |
| 424 | |
| 425 | static const struct nla_policy |
| 426 | nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = { |
| 427 | [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 }, |
| 428 | [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 }, |
| 429 | [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN }, |
| 430 | [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 }, |
| 431 | [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 }, |
| 432 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 }, |
| 433 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = { |
| 434 | .len = sizeof(struct nl80211_wowlan_tcp_data_seq) |
| 435 | }, |
| 436 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = { |
| 437 | .len = sizeof(struct nl80211_wowlan_tcp_data_token) |
| 438 | }, |
| 439 | [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 }, |
| 440 | [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 }, |
| 441 | [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 442 | }; |
| 443 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 444 | /* policy for coalesce rule attributes */ |
| 445 | static const struct nla_policy |
| 446 | nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = { |
| 447 | [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 }, |
| 448 | [NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 }, |
| 449 | [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED }, |
| 450 | }; |
| 451 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 452 | /* policy for GTK rekey offload attributes */ |
| 453 | static const struct nla_policy |
| 454 | nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = { |
| 455 | [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN }, |
| 456 | [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN }, |
| 457 | [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN }, |
| 458 | }; |
| 459 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 460 | static const struct nla_policy |
| 461 | nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = { |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 462 | [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 463 | .len = IEEE80211_MAX_SSID_LEN }, |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 464 | [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 }, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 465 | }; |
| 466 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 467 | static int nl80211_prepare_wdev_dump(struct sk_buff *skb, |
| 468 | struct netlink_callback *cb, |
| 469 | struct cfg80211_registered_device **rdev, |
| 470 | struct wireless_dev **wdev) |
Holger Schurig | a043897 | 2009-11-11 11:30:02 +0100 | [diff] [blame] | 471 | { |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 472 | int err; |
| 473 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 474 | rtnl_lock(); |
| 475 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 476 | if (!cb->args[0]) { |
| 477 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 478 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 479 | nl80211_policy); |
| 480 | if (err) |
| 481 | goto out_unlock; |
| 482 | |
| 483 | *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk), |
| 484 | nl80211_fam.attrbuf); |
| 485 | if (IS_ERR(*wdev)) { |
| 486 | err = PTR_ERR(*wdev); |
| 487 | goto out_unlock; |
| 488 | } |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 489 | *rdev = wiphy_to_rdev((*wdev)->wiphy); |
Johannes Berg | c319d50 | 2013-07-30 22:34:28 +0200 | [diff] [blame] | 490 | /* 0 is the first index - add 1 to parse only once */ |
| 491 | cb->args[0] = (*rdev)->wiphy_idx + 1; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 492 | cb->args[1] = (*wdev)->identifier; |
| 493 | } else { |
Johannes Berg | c319d50 | 2013-07-30 22:34:28 +0200 | [diff] [blame] | 494 | /* subtract the 1 again here */ |
| 495 | struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1); |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 496 | struct wireless_dev *tmp; |
| 497 | |
| 498 | if (!wiphy) { |
| 499 | err = -ENODEV; |
| 500 | goto out_unlock; |
| 501 | } |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 502 | *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 503 | *wdev = NULL; |
| 504 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 505 | list_for_each_entry(tmp, &(*rdev)->wdev_list, list) { |
| 506 | if (tmp->identifier == cb->args[1]) { |
| 507 | *wdev = tmp; |
| 508 | break; |
| 509 | } |
| 510 | } |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 511 | |
| 512 | if (!*wdev) { |
| 513 | err = -ENODEV; |
| 514 | goto out_unlock; |
| 515 | } |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 516 | } |
| 517 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 518 | return 0; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 519 | out_unlock: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 520 | rtnl_unlock(); |
| 521 | return err; |
| 522 | } |
| 523 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 524 | static void nl80211_finish_wdev_dump(struct cfg80211_registered_device *rdev) |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 525 | { |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 526 | rtnl_unlock(); |
| 527 | } |
| 528 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 529 | /* IE validation */ |
| 530 | static bool is_valid_ie_attr(const struct nlattr *attr) |
| 531 | { |
| 532 | const u8 *pos; |
| 533 | int len; |
| 534 | |
| 535 | if (!attr) |
| 536 | return true; |
| 537 | |
| 538 | pos = nla_data(attr); |
| 539 | len = nla_len(attr); |
| 540 | |
| 541 | while (len) { |
| 542 | u8 elemlen; |
| 543 | |
| 544 | if (len < 2) |
| 545 | return false; |
| 546 | len -= 2; |
| 547 | |
| 548 | elemlen = pos[1]; |
| 549 | if (elemlen > len) |
| 550 | return false; |
| 551 | |
| 552 | len -= elemlen; |
| 553 | pos += 2 + elemlen; |
| 554 | } |
| 555 | |
| 556 | return true; |
| 557 | } |
| 558 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 559 | /* message building helper */ |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 560 | 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] | 561 | int flags, u8 cmd) |
| 562 | { |
| 563 | /* since there is no private header just add the generic one */ |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 564 | return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 565 | } |
| 566 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 567 | static int nl80211_msg_put_channel(struct sk_buff *msg, |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 568 | struct ieee80211_channel *chan, |
| 569 | bool large) |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 570 | { |
Rostislav Lisovy | ea077c1 | 2014-04-15 14:37:55 +0200 | [diff] [blame] | 571 | /* Some channels must be completely excluded from the |
| 572 | * list to protect old user-space tools from breaking |
| 573 | */ |
| 574 | if (!large && chan->flags & |
| 575 | (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ)) |
| 576 | return 0; |
| 577 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 578 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
| 579 | chan->center_freq)) |
| 580 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 581 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 582 | if ((chan->flags & IEEE80211_CHAN_DISABLED) && |
| 583 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED)) |
| 584 | goto nla_put_failure; |
Luis R. Rodriguez | 8fe02e1 | 2013-10-21 19:22:25 +0200 | [diff] [blame] | 585 | if (chan->flags & IEEE80211_CHAN_NO_IR) { |
| 586 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR)) |
| 587 | goto nla_put_failure; |
| 588 | if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS)) |
| 589 | goto nla_put_failure; |
| 590 | } |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 591 | if (chan->flags & IEEE80211_CHAN_RADAR) { |
| 592 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR)) |
| 593 | goto nla_put_failure; |
| 594 | if (large) { |
| 595 | u32 time; |
| 596 | |
| 597 | time = elapsed_jiffies_msecs(chan->dfs_state_entered); |
| 598 | |
| 599 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE, |
| 600 | chan->dfs_state)) |
| 601 | goto nla_put_failure; |
| 602 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME, |
| 603 | time)) |
| 604 | goto nla_put_failure; |
Janusz Dziedzic | 089027e | 2014-02-21 19:46:12 +0100 | [diff] [blame] | 605 | if (nla_put_u32(msg, |
| 606 | NL80211_FREQUENCY_ATTR_DFS_CAC_TIME, |
| 607 | chan->dfs_cac_ms)) |
| 608 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 609 | } |
| 610 | } |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 611 | |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 612 | if (large) { |
| 613 | if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) && |
| 614 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS)) |
| 615 | goto nla_put_failure; |
| 616 | if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) && |
| 617 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS)) |
| 618 | goto nla_put_failure; |
| 619 | if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) && |
| 620 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ)) |
| 621 | goto nla_put_failure; |
| 622 | if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) && |
| 623 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ)) |
| 624 | goto nla_put_failure; |
David Spinadel | 570dbde | 2014-02-23 09:12:59 +0200 | [diff] [blame] | 625 | if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) && |
| 626 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY)) |
| 627 | goto nla_put_failure; |
| 628 | if ((chan->flags & IEEE80211_CHAN_GO_CONCURRENT) && |
| 629 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_GO_CONCURRENT)) |
| 630 | goto nla_put_failure; |
Rostislav Lisovy | ea077c1 | 2014-04-15 14:37:55 +0200 | [diff] [blame] | 631 | if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) && |
| 632 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ)) |
| 633 | goto nla_put_failure; |
| 634 | if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) && |
| 635 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ)) |
| 636 | goto nla_put_failure; |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 637 | } |
| 638 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 639 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
| 640 | DBM_TO_MBM(chan->max_power))) |
| 641 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 642 | |
| 643 | return 0; |
| 644 | |
| 645 | nla_put_failure: |
| 646 | return -ENOBUFS; |
| 647 | } |
| 648 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 649 | /* netlink command implementations */ |
| 650 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 651 | struct key_parse { |
| 652 | struct key_params p; |
| 653 | int idx; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 654 | int type; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 655 | bool def, defmgmt; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 656 | bool def_uni, def_multi; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 657 | }; |
| 658 | |
| 659 | static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k) |
| 660 | { |
| 661 | struct nlattr *tb[NL80211_KEY_MAX + 1]; |
| 662 | int err = nla_parse_nested(tb, NL80211_KEY_MAX, key, |
| 663 | nl80211_key_policy); |
| 664 | if (err) |
| 665 | return err; |
| 666 | |
| 667 | k->def = !!tb[NL80211_KEY_DEFAULT]; |
| 668 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; |
| 669 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 670 | if (k->def) { |
| 671 | k->def_uni = true; |
| 672 | k->def_multi = true; |
| 673 | } |
| 674 | if (k->defmgmt) |
| 675 | k->def_multi = true; |
| 676 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 677 | if (tb[NL80211_KEY_IDX]) |
| 678 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); |
| 679 | |
| 680 | if (tb[NL80211_KEY_DATA]) { |
| 681 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); |
| 682 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); |
| 683 | } |
| 684 | |
| 685 | if (tb[NL80211_KEY_SEQ]) { |
| 686 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); |
| 687 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); |
| 688 | } |
| 689 | |
| 690 | if (tb[NL80211_KEY_CIPHER]) |
| 691 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); |
| 692 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 693 | if (tb[NL80211_KEY_TYPE]) { |
| 694 | k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); |
| 695 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 696 | return -EINVAL; |
| 697 | } |
| 698 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 699 | if (tb[NL80211_KEY_DEFAULT_TYPES]) { |
| 700 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
Johannes Berg | 2da8f41 | 2012-01-20 13:52:37 +0100 | [diff] [blame] | 701 | err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 702 | tb[NL80211_KEY_DEFAULT_TYPES], |
| 703 | nl80211_key_default_policy); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 704 | if (err) |
| 705 | return err; |
| 706 | |
| 707 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 708 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 709 | } |
| 710 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 711 | return 0; |
| 712 | } |
| 713 | |
| 714 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) |
| 715 | { |
| 716 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { |
| 717 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 718 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 719 | } |
| 720 | |
| 721 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { |
| 722 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 723 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 724 | } |
| 725 | |
| 726 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 727 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 728 | |
| 729 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) |
| 730 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); |
| 731 | |
| 732 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; |
| 733 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; |
| 734 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 735 | if (k->def) { |
| 736 | k->def_uni = true; |
| 737 | k->def_multi = true; |
| 738 | } |
| 739 | if (k->defmgmt) |
| 740 | k->def_multi = true; |
| 741 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 742 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 743 | k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 744 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 745 | return -EINVAL; |
| 746 | } |
| 747 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 748 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { |
| 749 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
| 750 | int err = nla_parse_nested( |
| 751 | kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 752 | info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], |
| 753 | nl80211_key_default_policy); |
| 754 | if (err) |
| 755 | return err; |
| 756 | |
| 757 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 758 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 759 | } |
| 760 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 761 | return 0; |
| 762 | } |
| 763 | |
| 764 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) |
| 765 | { |
| 766 | int err; |
| 767 | |
| 768 | memset(k, 0, sizeof(*k)); |
| 769 | k->idx = -1; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 770 | k->type = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 771 | |
| 772 | if (info->attrs[NL80211_ATTR_KEY]) |
| 773 | err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k); |
| 774 | else |
| 775 | err = nl80211_parse_key_old(info, k); |
| 776 | |
| 777 | if (err) |
| 778 | return err; |
| 779 | |
| 780 | if (k->def && k->defmgmt) |
| 781 | return -EINVAL; |
| 782 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 783 | if (k->defmgmt) { |
| 784 | if (k->def_uni || !k->def_multi) |
| 785 | return -EINVAL; |
| 786 | } |
| 787 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 788 | if (k->idx != -1) { |
| 789 | if (k->defmgmt) { |
| 790 | if (k->idx < 4 || k->idx > 5) |
| 791 | return -EINVAL; |
| 792 | } else if (k->def) { |
| 793 | if (k->idx < 0 || k->idx > 3) |
| 794 | return -EINVAL; |
| 795 | } else { |
| 796 | if (k->idx < 0 || k->idx > 5) |
| 797 | return -EINVAL; |
| 798 | } |
| 799 | } |
| 800 | |
| 801 | return 0; |
| 802 | } |
| 803 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 804 | static struct cfg80211_cached_keys * |
| 805 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 806 | struct nlattr *keys, bool *no_ht) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 807 | { |
| 808 | struct key_parse parse; |
| 809 | struct nlattr *key; |
| 810 | struct cfg80211_cached_keys *result; |
| 811 | int rem, err, def = 0; |
| 812 | |
| 813 | result = kzalloc(sizeof(*result), GFP_KERNEL); |
| 814 | if (!result) |
| 815 | return ERR_PTR(-ENOMEM); |
| 816 | |
| 817 | result->def = -1; |
| 818 | result->defmgmt = -1; |
| 819 | |
| 820 | nla_for_each_nested(key, keys, rem) { |
| 821 | memset(&parse, 0, sizeof(parse)); |
| 822 | parse.idx = -1; |
| 823 | |
| 824 | err = nl80211_parse_key_new(key, &parse); |
| 825 | if (err) |
| 826 | goto error; |
| 827 | err = -EINVAL; |
| 828 | if (!parse.p.key) |
| 829 | goto error; |
| 830 | if (parse.idx < 0 || parse.idx > 4) |
| 831 | goto error; |
| 832 | if (parse.def) { |
| 833 | if (def) |
| 834 | goto error; |
| 835 | def = 1; |
| 836 | result->def = parse.idx; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 837 | if (!parse.def_uni || !parse.def_multi) |
| 838 | goto error; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 839 | } else if (parse.defmgmt) |
| 840 | goto error; |
| 841 | err = cfg80211_validate_key_settings(rdev, &parse.p, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 842 | parse.idx, false, NULL); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 843 | if (err) |
| 844 | goto error; |
| 845 | result->params[parse.idx].cipher = parse.p.cipher; |
| 846 | result->params[parse.idx].key_len = parse.p.key_len; |
| 847 | result->params[parse.idx].key = result->data[parse.idx]; |
| 848 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 849 | |
| 850 | if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 || |
| 851 | parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) { |
| 852 | if (no_ht) |
| 853 | *no_ht = true; |
| 854 | } |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 855 | } |
| 856 | |
| 857 | return result; |
| 858 | error: |
| 859 | kfree(result); |
| 860 | return ERR_PTR(err); |
| 861 | } |
| 862 | |
| 863 | static int nl80211_key_allowed(struct wireless_dev *wdev) |
| 864 | { |
| 865 | ASSERT_WDEV_LOCK(wdev); |
| 866 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 867 | switch (wdev->iftype) { |
| 868 | case NL80211_IFTYPE_AP: |
| 869 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 870 | case NL80211_IFTYPE_P2P_GO: |
Thomas Pedersen | ff973af | 2011-05-03 16:57:12 -0700 | [diff] [blame] | 871 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 872 | break; |
| 873 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 874 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 875 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 876 | if (!wdev->current_bss) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 877 | return -ENOLINK; |
| 878 | break; |
| 879 | default: |
| 880 | return -EINVAL; |
| 881 | } |
| 882 | |
| 883 | return 0; |
| 884 | } |
| 885 | |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 886 | static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy, |
| 887 | struct nlattr *tb) |
| 888 | { |
| 889 | struct ieee80211_channel *chan; |
| 890 | |
| 891 | if (tb == NULL) |
| 892 | return NULL; |
| 893 | chan = ieee80211_get_channel(wiphy, nla_get_u32(tb)); |
| 894 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) |
| 895 | return NULL; |
| 896 | return chan; |
| 897 | } |
| 898 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 899 | static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) |
| 900 | { |
| 901 | struct nlattr *nl_modes = nla_nest_start(msg, attr); |
| 902 | int i; |
| 903 | |
| 904 | if (!nl_modes) |
| 905 | goto nla_put_failure; |
| 906 | |
| 907 | i = 0; |
| 908 | while (ifmodes) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 909 | if ((ifmodes & 1) && nla_put_flag(msg, i)) |
| 910 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 911 | ifmodes >>= 1; |
| 912 | i++; |
| 913 | } |
| 914 | |
| 915 | nla_nest_end(msg, nl_modes); |
| 916 | return 0; |
| 917 | |
| 918 | nla_put_failure: |
| 919 | return -ENOBUFS; |
| 920 | } |
| 921 | |
| 922 | static int nl80211_put_iface_combinations(struct wiphy *wiphy, |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 923 | struct sk_buff *msg, |
| 924 | bool large) |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 925 | { |
| 926 | struct nlattr *nl_combis; |
| 927 | int i, j; |
| 928 | |
| 929 | nl_combis = nla_nest_start(msg, |
| 930 | NL80211_ATTR_INTERFACE_COMBINATIONS); |
| 931 | if (!nl_combis) |
| 932 | goto nla_put_failure; |
| 933 | |
| 934 | for (i = 0; i < wiphy->n_iface_combinations; i++) { |
| 935 | const struct ieee80211_iface_combination *c; |
| 936 | struct nlattr *nl_combi, *nl_limits; |
| 937 | |
| 938 | c = &wiphy->iface_combinations[i]; |
| 939 | |
| 940 | nl_combi = nla_nest_start(msg, i + 1); |
| 941 | if (!nl_combi) |
| 942 | goto nla_put_failure; |
| 943 | |
| 944 | nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS); |
| 945 | if (!nl_limits) |
| 946 | goto nla_put_failure; |
| 947 | |
| 948 | for (j = 0; j < c->n_limits; j++) { |
| 949 | struct nlattr *nl_limit; |
| 950 | |
| 951 | nl_limit = nla_nest_start(msg, j + 1); |
| 952 | if (!nl_limit) |
| 953 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 954 | if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX, |
| 955 | c->limits[j].max)) |
| 956 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 957 | if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, |
| 958 | c->limits[j].types)) |
| 959 | goto nla_put_failure; |
| 960 | nla_nest_end(msg, nl_limit); |
| 961 | } |
| 962 | |
| 963 | nla_nest_end(msg, nl_limits); |
| 964 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 965 | if (c->beacon_int_infra_match && |
| 966 | nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH)) |
| 967 | goto nla_put_failure; |
| 968 | if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, |
| 969 | c->num_different_channels) || |
| 970 | nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM, |
| 971 | c->max_interfaces)) |
| 972 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 973 | if (large && |
Felix Fietkau | 8c48b50 | 2014-05-05 11:48:40 +0200 | [diff] [blame] | 974 | (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS, |
| 975 | c->radar_detect_widths) || |
| 976 | nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS, |
| 977 | c->radar_detect_regions))) |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 978 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 979 | |
| 980 | nla_nest_end(msg, nl_combi); |
| 981 | } |
| 982 | |
| 983 | nla_nest_end(msg, nl_combis); |
| 984 | |
| 985 | return 0; |
| 986 | nla_put_failure: |
| 987 | return -ENOBUFS; |
| 988 | } |
| 989 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 990 | #ifdef CONFIG_PM |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 991 | static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev, |
| 992 | struct sk_buff *msg) |
| 993 | { |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 994 | const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp; |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 995 | struct nlattr *nl_tcp; |
| 996 | |
| 997 | if (!tcp) |
| 998 | return 0; |
| 999 | |
| 1000 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); |
| 1001 | if (!nl_tcp) |
| 1002 | return -ENOBUFS; |
| 1003 | |
| 1004 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 1005 | tcp->data_payload_max)) |
| 1006 | return -ENOBUFS; |
| 1007 | |
| 1008 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 1009 | tcp->data_payload_max)) |
| 1010 | return -ENOBUFS; |
| 1011 | |
| 1012 | if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ)) |
| 1013 | return -ENOBUFS; |
| 1014 | |
| 1015 | if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, |
| 1016 | sizeof(*tcp->tok), tcp->tok)) |
| 1017 | return -ENOBUFS; |
| 1018 | |
| 1019 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, |
| 1020 | tcp->data_interval_max)) |
| 1021 | return -ENOBUFS; |
| 1022 | |
| 1023 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, |
| 1024 | tcp->wake_payload_max)) |
| 1025 | return -ENOBUFS; |
| 1026 | |
| 1027 | nla_nest_end(msg, nl_tcp); |
| 1028 | return 0; |
| 1029 | } |
| 1030 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1031 | static int nl80211_send_wowlan(struct sk_buff *msg, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1032 | struct cfg80211_registered_device *rdev, |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1033 | bool large) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1034 | { |
| 1035 | struct nlattr *nl_wowlan; |
| 1036 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1037 | if (!rdev->wiphy.wowlan) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1038 | return 0; |
| 1039 | |
| 1040 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); |
| 1041 | if (!nl_wowlan) |
| 1042 | return -ENOBUFS; |
| 1043 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1044 | if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1045 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1046 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1047 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1048 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1049 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1050 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1051 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1052 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1053 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1054 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1055 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1056 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1057 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1058 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1059 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 1060 | return -ENOBUFS; |
| 1061 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1062 | if (rdev->wiphy.wowlan->n_patterns) { |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 1063 | struct nl80211_pattern_support pat = { |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1064 | .max_patterns = rdev->wiphy.wowlan->n_patterns, |
| 1065 | .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len, |
| 1066 | .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len, |
| 1067 | .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1068 | }; |
| 1069 | |
| 1070 | if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 1071 | sizeof(pat), &pat)) |
| 1072 | return -ENOBUFS; |
| 1073 | } |
| 1074 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1075 | if (large && nl80211_send_wowlan_tcp_caps(rdev, msg)) |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1076 | return -ENOBUFS; |
| 1077 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1078 | nla_nest_end(msg, nl_wowlan); |
| 1079 | |
| 1080 | return 0; |
| 1081 | } |
| 1082 | #endif |
| 1083 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1084 | static int nl80211_send_coalesce(struct sk_buff *msg, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1085 | struct cfg80211_registered_device *rdev) |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1086 | { |
| 1087 | struct nl80211_coalesce_rule_support rule; |
| 1088 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1089 | if (!rdev->wiphy.coalesce) |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1090 | return 0; |
| 1091 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1092 | rule.max_rules = rdev->wiphy.coalesce->n_rules; |
| 1093 | rule.max_delay = rdev->wiphy.coalesce->max_delay; |
| 1094 | rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns; |
| 1095 | rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len; |
| 1096 | rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len; |
| 1097 | rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset; |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1098 | |
| 1099 | if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule)) |
| 1100 | return -ENOBUFS; |
| 1101 | |
| 1102 | return 0; |
| 1103 | } |
| 1104 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1105 | static int nl80211_send_band_rateinfo(struct sk_buff *msg, |
| 1106 | struct ieee80211_supported_band *sband) |
| 1107 | { |
| 1108 | struct nlattr *nl_rates, *nl_rate; |
| 1109 | struct ieee80211_rate *rate; |
| 1110 | int i; |
| 1111 | |
| 1112 | /* add HT info */ |
| 1113 | if (sband->ht_cap.ht_supported && |
| 1114 | (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET, |
| 1115 | sizeof(sband->ht_cap.mcs), |
| 1116 | &sband->ht_cap.mcs) || |
| 1117 | nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA, |
| 1118 | sband->ht_cap.cap) || |
| 1119 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, |
| 1120 | sband->ht_cap.ampdu_factor) || |
| 1121 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, |
| 1122 | sband->ht_cap.ampdu_density))) |
| 1123 | return -ENOBUFS; |
| 1124 | |
| 1125 | /* add VHT info */ |
| 1126 | if (sband->vht_cap.vht_supported && |
| 1127 | (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET, |
| 1128 | sizeof(sband->vht_cap.vht_mcs), |
| 1129 | &sband->vht_cap.vht_mcs) || |
| 1130 | nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA, |
| 1131 | sband->vht_cap.cap))) |
| 1132 | return -ENOBUFS; |
| 1133 | |
| 1134 | /* add bitrates */ |
| 1135 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); |
| 1136 | if (!nl_rates) |
| 1137 | return -ENOBUFS; |
| 1138 | |
| 1139 | for (i = 0; i < sband->n_bitrates; i++) { |
| 1140 | nl_rate = nla_nest_start(msg, i); |
| 1141 | if (!nl_rate) |
| 1142 | return -ENOBUFS; |
| 1143 | |
| 1144 | rate = &sband->bitrates[i]; |
| 1145 | if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE, |
| 1146 | rate->bitrate)) |
| 1147 | return -ENOBUFS; |
| 1148 | if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) && |
| 1149 | nla_put_flag(msg, |
| 1150 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE)) |
| 1151 | return -ENOBUFS; |
| 1152 | |
| 1153 | nla_nest_end(msg, nl_rate); |
| 1154 | } |
| 1155 | |
| 1156 | nla_nest_end(msg, nl_rates); |
| 1157 | |
| 1158 | return 0; |
| 1159 | } |
| 1160 | |
| 1161 | static int |
| 1162 | nl80211_send_mgmt_stypes(struct sk_buff *msg, |
| 1163 | const struct ieee80211_txrx_stypes *mgmt_stypes) |
| 1164 | { |
| 1165 | u16 stypes; |
| 1166 | struct nlattr *nl_ftypes, *nl_ifs; |
| 1167 | enum nl80211_iftype ift; |
| 1168 | int i; |
| 1169 | |
| 1170 | if (!mgmt_stypes) |
| 1171 | return 0; |
| 1172 | |
| 1173 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES); |
| 1174 | if (!nl_ifs) |
| 1175 | return -ENOBUFS; |
| 1176 | |
| 1177 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 1178 | nl_ftypes = nla_nest_start(msg, ift); |
| 1179 | if (!nl_ftypes) |
| 1180 | return -ENOBUFS; |
| 1181 | i = 0; |
| 1182 | stypes = mgmt_stypes[ift].tx; |
| 1183 | while (stypes) { |
| 1184 | if ((stypes & 1) && |
| 1185 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1186 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1187 | return -ENOBUFS; |
| 1188 | stypes >>= 1; |
| 1189 | i++; |
| 1190 | } |
| 1191 | nla_nest_end(msg, nl_ftypes); |
| 1192 | } |
| 1193 | |
| 1194 | nla_nest_end(msg, nl_ifs); |
| 1195 | |
| 1196 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES); |
| 1197 | if (!nl_ifs) |
| 1198 | return -ENOBUFS; |
| 1199 | |
| 1200 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 1201 | nl_ftypes = nla_nest_start(msg, ift); |
| 1202 | if (!nl_ftypes) |
| 1203 | return -ENOBUFS; |
| 1204 | i = 0; |
| 1205 | stypes = mgmt_stypes[ift].rx; |
| 1206 | while (stypes) { |
| 1207 | if ((stypes & 1) && |
| 1208 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1209 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1210 | return -ENOBUFS; |
| 1211 | stypes >>= 1; |
| 1212 | i++; |
| 1213 | } |
| 1214 | nla_nest_end(msg, nl_ftypes); |
| 1215 | } |
| 1216 | nla_nest_end(msg, nl_ifs); |
| 1217 | |
| 1218 | return 0; |
| 1219 | } |
| 1220 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1221 | struct nl80211_dump_wiphy_state { |
| 1222 | s64 filter_wiphy; |
| 1223 | long start; |
| 1224 | long split_start, band_start, chan_start; |
| 1225 | bool split; |
| 1226 | }; |
| 1227 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1228 | static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev, |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1229 | enum nl80211_commands cmd, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1230 | struct sk_buff *msg, u32 portid, u32 seq, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1231 | int flags, struct nl80211_dump_wiphy_state *state) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1232 | { |
| 1233 | void *hdr; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1234 | struct nlattr *nl_bands, *nl_band; |
| 1235 | struct nlattr *nl_freqs, *nl_freq; |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1236 | struct nlattr *nl_cmds; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1237 | enum ieee80211_band band; |
| 1238 | struct ieee80211_channel *chan; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1239 | int i; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1240 | const struct ieee80211_txrx_stypes *mgmt_stypes = |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1241 | rdev->wiphy.mgmt_stypes; |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1242 | u32 features; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1243 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1244 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1245 | if (!hdr) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1246 | return -ENOBUFS; |
| 1247 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1248 | if (WARN_ON(!state)) |
| 1249 | return -EINVAL; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1250 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1251 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1252 | nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1253 | wiphy_name(&rdev->wiphy)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1254 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1255 | cfg80211_rdev_list_generation)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1256 | goto nla_put_failure; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1257 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1258 | if (cmd != NL80211_CMD_NEW_WIPHY) |
| 1259 | goto finish; |
| 1260 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1261 | switch (state->split_start) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1262 | case 0: |
| 1263 | if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1264 | rdev->wiphy.retry_short) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1265 | nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1266 | rdev->wiphy.retry_long) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1267 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1268 | rdev->wiphy.frag_threshold) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1269 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1270 | rdev->wiphy.rts_threshold) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1271 | nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1272 | rdev->wiphy.coverage_class) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1273 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1274 | rdev->wiphy.max_scan_ssids) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1275 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1276 | rdev->wiphy.max_sched_scan_ssids) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1277 | nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1278 | rdev->wiphy.max_scan_ie_len) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1279 | nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1280 | rdev->wiphy.max_sched_scan_ie_len) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1281 | nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1282 | rdev->wiphy.max_match_sets)) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1283 | goto nla_put_failure; |
| 1284 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1285 | if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1286 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN)) |
| 1287 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1288 | if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1289 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH)) |
| 1290 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1291 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1292 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD)) |
| 1293 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1294 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1295 | nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT)) |
| 1296 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1297 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1298 | nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT)) |
| 1299 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1300 | if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1301 | nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1302 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1303 | state->split_start++; |
| 1304 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1305 | break; |
| 1306 | case 1: |
| 1307 | if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1308 | sizeof(u32) * rdev->wiphy.n_cipher_suites, |
| 1309 | rdev->wiphy.cipher_suites)) |
Mahesh Palivela | bf0c111e | 2012-06-22 07:27:46 +0000 | [diff] [blame] | 1310 | goto nla_put_failure; |
| 1311 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1312 | if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1313 | rdev->wiphy.max_num_pmkids)) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1314 | goto nla_put_failure; |
| 1315 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1316 | if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1317 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE)) |
| 1318 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1319 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1320 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1321 | rdev->wiphy.available_antennas_tx) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1322 | nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1323 | rdev->wiphy.available_antennas_rx)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1324 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1325 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1326 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1327 | nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1328 | rdev->wiphy.probe_resp_offload)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1329 | goto nla_put_failure; |
Jouni Malinen | e2f367f26 | 2008-11-21 19:01:30 +0200 | [diff] [blame] | 1330 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1331 | if ((rdev->wiphy.available_antennas_tx || |
| 1332 | rdev->wiphy.available_antennas_rx) && |
| 1333 | rdev->ops->get_antenna) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1334 | u32 tx_ant = 0, rx_ant = 0; |
| 1335 | int res; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1336 | res = rdev_get_antenna(rdev, &tx_ant, &rx_ant); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1337 | if (!res) { |
| 1338 | if (nla_put_u32(msg, |
| 1339 | NL80211_ATTR_WIPHY_ANTENNA_TX, |
| 1340 | tx_ant) || |
| 1341 | nla_put_u32(msg, |
| 1342 | NL80211_ATTR_WIPHY_ANTENNA_RX, |
| 1343 | rx_ant)) |
| 1344 | goto nla_put_failure; |
| 1345 | } |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1346 | } |
| 1347 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1348 | state->split_start++; |
| 1349 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1350 | break; |
| 1351 | case 2: |
| 1352 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1353 | rdev->wiphy.interface_modes)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1354 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1355 | state->split_start++; |
| 1356 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1357 | break; |
| 1358 | case 3: |
| 1359 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); |
| 1360 | if (!nl_bands) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1361 | goto nla_put_failure; |
| 1362 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1363 | for (band = state->band_start; |
| 1364 | band < IEEE80211_NUM_BANDS; band++) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1365 | struct ieee80211_supported_band *sband; |
| 1366 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1367 | sband = rdev->wiphy.bands[band]; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1368 | |
| 1369 | if (!sband) |
| 1370 | continue; |
| 1371 | |
| 1372 | nl_band = nla_nest_start(msg, band); |
| 1373 | if (!nl_band) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1374 | goto nla_put_failure; |
| 1375 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1376 | switch (state->chan_start) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1377 | case 0: |
| 1378 | if (nl80211_send_band_rateinfo(msg, sband)) |
| 1379 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1380 | state->chan_start++; |
| 1381 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1382 | break; |
| 1383 | default: |
| 1384 | /* add frequencies */ |
| 1385 | nl_freqs = nla_nest_start( |
| 1386 | msg, NL80211_BAND_ATTR_FREQS); |
| 1387 | if (!nl_freqs) |
| 1388 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1389 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1390 | for (i = state->chan_start - 1; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1391 | i < sband->n_channels; |
| 1392 | i++) { |
| 1393 | nl_freq = nla_nest_start(msg, i); |
| 1394 | if (!nl_freq) |
| 1395 | goto nla_put_failure; |
| 1396 | |
| 1397 | chan = &sband->channels[i]; |
| 1398 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1399 | if (nl80211_msg_put_channel( |
| 1400 | msg, chan, |
| 1401 | state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1402 | goto nla_put_failure; |
| 1403 | |
| 1404 | nla_nest_end(msg, nl_freq); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1405 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1406 | break; |
| 1407 | } |
| 1408 | if (i < sband->n_channels) |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1409 | state->chan_start = i + 2; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1410 | else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1411 | state->chan_start = 0; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1412 | nla_nest_end(msg, nl_freqs); |
| 1413 | } |
| 1414 | |
| 1415 | nla_nest_end(msg, nl_band); |
| 1416 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1417 | if (state->split) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1418 | /* start again here */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1419 | if (state->chan_start) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1420 | band--; |
| 1421 | break; |
| 1422 | } |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1423 | } |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1424 | nla_nest_end(msg, nl_bands); |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1425 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1426 | if (band < IEEE80211_NUM_BANDS) |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1427 | state->band_start = band + 1; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1428 | else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1429 | state->band_start = 0; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1430 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1431 | /* if bands & channels are done, continue outside */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1432 | if (state->band_start == 0 && state->chan_start == 0) |
| 1433 | state->split_start++; |
| 1434 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1435 | break; |
| 1436 | case 4: |
| 1437 | nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); |
| 1438 | if (!nl_cmds) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1439 | goto nla_put_failure; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1440 | |
| 1441 | i = 0; |
| 1442 | #define CMD(op, n) \ |
| 1443 | do { \ |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1444 | if (rdev->ops->op) { \ |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1445 | i++; \ |
| 1446 | if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \ |
| 1447 | goto nla_put_failure; \ |
| 1448 | } \ |
| 1449 | } while (0) |
| 1450 | |
| 1451 | CMD(add_virtual_intf, NEW_INTERFACE); |
| 1452 | CMD(change_virtual_intf, SET_INTERFACE); |
| 1453 | CMD(add_key, NEW_KEY); |
| 1454 | CMD(start_ap, START_AP); |
| 1455 | CMD(add_station, NEW_STATION); |
| 1456 | CMD(add_mpath, NEW_MPATH); |
| 1457 | CMD(update_mesh_config, SET_MESH_CONFIG); |
| 1458 | CMD(change_bss, SET_BSS); |
| 1459 | CMD(auth, AUTHENTICATE); |
| 1460 | CMD(assoc, ASSOCIATE); |
| 1461 | CMD(deauth, DEAUTHENTICATE); |
| 1462 | CMD(disassoc, DISASSOCIATE); |
| 1463 | CMD(join_ibss, JOIN_IBSS); |
| 1464 | CMD(join_mesh, JOIN_MESH); |
| 1465 | CMD(set_pmksa, SET_PMKSA); |
| 1466 | CMD(del_pmksa, DEL_PMKSA); |
| 1467 | CMD(flush_pmksa, FLUSH_PMKSA); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1468 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1469 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); |
| 1470 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); |
| 1471 | CMD(mgmt_tx, FRAME); |
| 1472 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1473 | if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1474 | i++; |
| 1475 | if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS)) |
| 1476 | goto nla_put_failure; |
| 1477 | } |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1478 | if (rdev->ops->set_monitor_channel || rdev->ops->start_ap || |
| 1479 | rdev->ops->join_mesh) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1480 | i++; |
| 1481 | if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL)) |
| 1482 | goto nla_put_failure; |
| 1483 | } |
| 1484 | CMD(set_wds_peer, SET_WDS_PEER); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1485 | if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1486 | CMD(tdls_mgmt, TDLS_MGMT); |
| 1487 | CMD(tdls_oper, TDLS_OPER); |
| 1488 | } |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1489 | if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1490 | CMD(sched_scan_start, START_SCHED_SCAN); |
| 1491 | CMD(probe_client, PROBE_CLIENT); |
| 1492 | CMD(set_noack_map, SET_NOACK_MAP); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1493 | if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1494 | i++; |
| 1495 | if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS)) |
| 1496 | goto nla_put_failure; |
| 1497 | } |
| 1498 | CMD(start_p2p_device, START_P2P_DEVICE); |
| 1499 | CMD(set_mcast_rate, SET_MCAST_RATE); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1500 | if (state->split) { |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 1501 | CMD(crit_proto_start, CRIT_PROTOCOL_START); |
| 1502 | CMD(crit_proto_stop, CRIT_PROTOCOL_STOP); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1503 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 1504 | CMD(channel_switch, CHANNEL_SWITCH); |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 1505 | } |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 1506 | CMD(set_qos_map, SET_QOS_MAP); |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1507 | |
Kalle Valo | 4745fc0 | 2011-11-17 19:06:10 +0200 | [diff] [blame] | 1508 | #ifdef CONFIG_NL80211_TESTMODE |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1509 | CMD(testmode_cmd, TESTMODE); |
Kalle Valo | 4745fc0 | 2011-11-17 19:06:10 +0200 | [diff] [blame] | 1510 | #endif |
| 1511 | |
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; |
| 3817 | if (params->aid) |
| 3818 | return -EINVAL; |
| 3819 | |
| 3820 | /* When you run into this, adjust the code below for the new flag */ |
| 3821 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); |
| 3822 | |
| 3823 | switch (statype) { |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 3824 | case CFG80211_STA_MESH_PEER_KERNEL: |
| 3825 | case CFG80211_STA_MESH_PEER_USER: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3826 | /* |
| 3827 | * No ignoring the TDLS flag here -- the userspace mesh |
| 3828 | * code doesn't have the bug of including TDLS in the |
| 3829 | * mask everywhere. |
| 3830 | */ |
| 3831 | if (params->sta_flags_mask & |
| 3832 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3833 | BIT(NL80211_STA_FLAG_MFP) | |
| 3834 | BIT(NL80211_STA_FLAG_AUTHORIZED))) |
| 3835 | return -EINVAL; |
| 3836 | break; |
| 3837 | case CFG80211_STA_TDLS_PEER_SETUP: |
| 3838 | case CFG80211_STA_TDLS_PEER_ACTIVE: |
| 3839 | if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 3840 | return -EINVAL; |
| 3841 | /* ignore since it can't change */ |
| 3842 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3843 | break; |
| 3844 | default: |
| 3845 | /* disallow mesh-specific things */ |
| 3846 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) |
| 3847 | return -EINVAL; |
| 3848 | if (params->local_pm) |
| 3849 | return -EINVAL; |
| 3850 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
| 3851 | return -EINVAL; |
| 3852 | } |
| 3853 | |
| 3854 | if (statype != CFG80211_STA_TDLS_PEER_SETUP && |
| 3855 | statype != CFG80211_STA_TDLS_PEER_ACTIVE) { |
| 3856 | /* TDLS can't be set, ... */ |
| 3857 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
| 3858 | return -EINVAL; |
| 3859 | /* |
| 3860 | * ... but don't bother the driver with it. This works around |
| 3861 | * a hostapd/wpa_supplicant issue -- it always includes the |
| 3862 | * TLDS_PEER flag in the mask even for AP mode. |
| 3863 | */ |
| 3864 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3865 | } |
| 3866 | |
| 3867 | if (statype != CFG80211_STA_TDLS_PEER_SETUP) { |
| 3868 | /* reject other things that can't change */ |
| 3869 | if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) |
| 3870 | return -EINVAL; |
| 3871 | if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY) |
| 3872 | return -EINVAL; |
| 3873 | if (params->supported_rates) |
| 3874 | return -EINVAL; |
| 3875 | if (params->ext_capab || params->ht_capa || params->vht_capa) |
| 3876 | return -EINVAL; |
| 3877 | } |
| 3878 | |
| 3879 | if (statype != CFG80211_STA_AP_CLIENT) { |
| 3880 | if (params->vlan) |
| 3881 | return -EINVAL; |
| 3882 | } |
| 3883 | |
| 3884 | switch (statype) { |
| 3885 | case CFG80211_STA_AP_MLME_CLIENT: |
| 3886 | /* Use this only for authorizing/unauthorizing a station */ |
| 3887 | if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))) |
| 3888 | return -EOPNOTSUPP; |
| 3889 | break; |
| 3890 | case CFG80211_STA_AP_CLIENT: |
| 3891 | /* accept only the listed bits */ |
| 3892 | if (params->sta_flags_mask & |
| 3893 | ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3894 | BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3895 | BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 3896 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 3897 | BIT(NL80211_STA_FLAG_WME) | |
| 3898 | BIT(NL80211_STA_FLAG_MFP))) |
| 3899 | return -EINVAL; |
| 3900 | |
| 3901 | /* but authenticated/associated only if driver handles it */ |
| 3902 | if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
| 3903 | params->sta_flags_mask & |
| 3904 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3905 | BIT(NL80211_STA_FLAG_ASSOCIATED))) |
| 3906 | return -EINVAL; |
| 3907 | break; |
| 3908 | case CFG80211_STA_IBSS: |
| 3909 | case CFG80211_STA_AP_STA: |
| 3910 | /* reject any changes other than AUTHORIZED */ |
| 3911 | if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) |
| 3912 | return -EINVAL; |
| 3913 | break; |
| 3914 | case CFG80211_STA_TDLS_PEER_SETUP: |
| 3915 | /* reject any changes other than AUTHORIZED or WME */ |
| 3916 | if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3917 | BIT(NL80211_STA_FLAG_WME))) |
| 3918 | return -EINVAL; |
| 3919 | /* force (at least) rates when authorizing */ |
| 3920 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) && |
| 3921 | !params->supported_rates) |
| 3922 | return -EINVAL; |
| 3923 | break; |
| 3924 | case CFG80211_STA_TDLS_PEER_ACTIVE: |
| 3925 | /* reject any changes */ |
| 3926 | return -EINVAL; |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 3927 | case CFG80211_STA_MESH_PEER_KERNEL: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3928 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
| 3929 | return -EINVAL; |
| 3930 | break; |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 3931 | case CFG80211_STA_MESH_PEER_USER: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3932 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) |
| 3933 | return -EINVAL; |
| 3934 | break; |
| 3935 | } |
| 3936 | |
| 3937 | return 0; |
| 3938 | } |
| 3939 | EXPORT_SYMBOL(cfg80211_check_station_change); |
| 3940 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3941 | /* |
Felix Fietkau | c258d2d | 2009-11-11 17:23:31 +0100 | [diff] [blame] | 3942 | * 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] | 3943 | */ |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3944 | static struct net_device *get_vlan(struct genl_info *info, |
| 3945 | struct cfg80211_registered_device *rdev) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3946 | { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3947 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3948 | struct net_device *v; |
| 3949 | int ret; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3950 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3951 | if (!vlanattr) |
| 3952 | return NULL; |
| 3953 | |
| 3954 | v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); |
| 3955 | if (!v) |
| 3956 | return ERR_PTR(-ENODEV); |
| 3957 | |
| 3958 | if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { |
| 3959 | ret = -EINVAL; |
| 3960 | goto error; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3961 | } |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3962 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3963 | if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
| 3964 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3965 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { |
| 3966 | ret = -EINVAL; |
| 3967 | goto error; |
| 3968 | } |
| 3969 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3970 | if (!netif_running(v)) { |
| 3971 | ret = -ENETDOWN; |
| 3972 | goto error; |
| 3973 | } |
| 3974 | |
| 3975 | return v; |
| 3976 | error: |
| 3977 | dev_put(v); |
| 3978 | return ERR_PTR(ret); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3979 | } |
| 3980 | |
Johannes Berg | 94e860f | 2014-01-20 23:58:15 +0100 | [diff] [blame] | 3981 | static const struct nla_policy |
| 3982 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = { |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3983 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, |
| 3984 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, |
| 3985 | }; |
| 3986 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 3987 | static int nl80211_parse_sta_wme(struct genl_info *info, |
| 3988 | struct station_parameters *params) |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3989 | { |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3990 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; |
| 3991 | struct nlattr *nla; |
| 3992 | int err; |
| 3993 | |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3994 | /* parse WME attributes if present */ |
| 3995 | if (!info->attrs[NL80211_ATTR_STA_WME]) |
| 3996 | return 0; |
| 3997 | |
| 3998 | nla = info->attrs[NL80211_ATTR_STA_WME]; |
| 3999 | err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla, |
| 4000 | nl80211_sta_wme_policy); |
| 4001 | if (err) |
| 4002 | return err; |
| 4003 | |
| 4004 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) |
| 4005 | params->uapsd_queues = nla_get_u8( |
| 4006 | tb[NL80211_STA_WME_UAPSD_QUEUES]); |
| 4007 | if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) |
| 4008 | return -EINVAL; |
| 4009 | |
| 4010 | if (tb[NL80211_STA_WME_MAX_SP]) |
| 4011 | params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); |
| 4012 | |
| 4013 | if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) |
| 4014 | return -EINVAL; |
| 4015 | |
| 4016 | params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; |
| 4017 | |
| 4018 | return 0; |
| 4019 | } |
| 4020 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 4021 | static int nl80211_parse_sta_channel_info(struct genl_info *info, |
| 4022 | struct station_parameters *params) |
| 4023 | { |
| 4024 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) { |
| 4025 | params->supported_channels = |
| 4026 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); |
| 4027 | params->supported_channels_len = |
| 4028 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); |
| 4029 | /* |
| 4030 | * Need to include at least one (first channel, number of |
| 4031 | * channels) tuple for each subband, and must have proper |
| 4032 | * tuples for the rest of the data as well. |
| 4033 | */ |
| 4034 | if (params->supported_channels_len < 2) |
| 4035 | return -EINVAL; |
| 4036 | if (params->supported_channels_len % 2) |
| 4037 | return -EINVAL; |
| 4038 | } |
| 4039 | |
| 4040 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) { |
| 4041 | params->supported_oper_classes = |
| 4042 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); |
| 4043 | params->supported_oper_classes_len = |
| 4044 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); |
| 4045 | /* |
| 4046 | * The value of the Length field of the Supported Operating |
| 4047 | * Classes element is between 2 and 253. |
| 4048 | */ |
| 4049 | if (params->supported_oper_classes_len < 2 || |
| 4050 | params->supported_oper_classes_len > 253) |
| 4051 | return -EINVAL; |
| 4052 | } |
| 4053 | return 0; |
| 4054 | } |
| 4055 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4056 | static int nl80211_set_station_tdls(struct genl_info *info, |
| 4057 | struct station_parameters *params) |
| 4058 | { |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 4059 | int err; |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4060 | /* Dummy STA entry gets updated once the peer capabilities are known */ |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 4061 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
| 4062 | params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4063 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 4064 | params->ht_capa = |
| 4065 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
| 4066 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 4067 | params->vht_capa = |
| 4068 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 4069 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 4070 | err = nl80211_parse_sta_channel_info(info, params); |
| 4071 | if (err) |
| 4072 | return err; |
| 4073 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4074 | return nl80211_parse_sta_wme(info, params); |
| 4075 | } |
| 4076 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4077 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
| 4078 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4079 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4080 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4081 | struct station_parameters params; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4082 | u8 *mac_addr; |
| 4083 | int err; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4084 | |
| 4085 | memset(¶ms, 0, sizeof(params)); |
| 4086 | |
| 4087 | params.listen_interval = -1; |
| 4088 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4089 | if (!rdev->ops->change_station) |
| 4090 | return -EOPNOTSUPP; |
| 4091 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4092 | if (info->attrs[NL80211_ATTR_STA_AID]) |
| 4093 | return -EINVAL; |
| 4094 | |
| 4095 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4096 | return -EINVAL; |
| 4097 | |
| 4098 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4099 | |
| 4100 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { |
| 4101 | params.supported_rates = |
| 4102 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4103 | params.supported_rates_len = |
| 4104 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4105 | } |
| 4106 | |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 4107 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
| 4108 | params.capability = |
| 4109 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); |
| 4110 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; |
| 4111 | } |
| 4112 | |
| 4113 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { |
| 4114 | params.ext_capab = |
| 4115 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4116 | params.ext_capab_len = |
| 4117 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4118 | } |
| 4119 | |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 4120 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
Johannes Berg | ba23d20 | 2012-12-27 17:32:09 +0100 | [diff] [blame] | 4121 | return -EINVAL; |
Jouni Malinen | 36aedc90 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 4122 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 4123 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4124 | return -EINVAL; |
| 4125 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4126 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4127 | params.plink_action = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4128 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 4129 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) |
| 4130 | return -EINVAL; |
| 4131 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4132 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4133 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) { |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 4134 | params.plink_state = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4135 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
| 4136 | if (params.plink_state >= NUM_NL80211_PLINK_STATES) |
| 4137 | return -EINVAL; |
| 4138 | params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE; |
| 4139 | } |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 4140 | |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4141 | if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) { |
| 4142 | enum nl80211_mesh_power_mode pm = nla_get_u32( |
| 4143 | info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]); |
| 4144 | |
| 4145 | if (pm <= NL80211_MESH_POWER_UNKNOWN || |
| 4146 | pm > NL80211_MESH_POWER_MAX) |
| 4147 | return -EINVAL; |
| 4148 | |
| 4149 | params.local_pm = pm; |
| 4150 | } |
| 4151 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4152 | /* Include parameters for TDLS peer (will check later) */ |
| 4153 | err = nl80211_set_station_tdls(info, ¶ms); |
| 4154 | if (err) |
| 4155 | return err; |
| 4156 | |
| 4157 | params.vlan = get_vlan(info, rdev); |
| 4158 | if (IS_ERR(params.vlan)) |
| 4159 | return PTR_ERR(params.vlan); |
| 4160 | |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4161 | switch (dev->ieee80211_ptr->iftype) { |
| 4162 | case NL80211_IFTYPE_AP: |
| 4163 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4164 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4165 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4166 | case NL80211_IFTYPE_STATION: |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 4167 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4168 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4169 | break; |
| 4170 | default: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4171 | err = -EOPNOTSUPP; |
| 4172 | goto out_put_vlan; |
Johannes Berg | 034d655 | 2009-05-27 10:35:29 +0200 | [diff] [blame] | 4173 | } |
| 4174 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4175 | /* driver will call cfg80211_check_station_change() */ |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4176 | err = rdev_change_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4177 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4178 | out_put_vlan: |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4179 | if (params.vlan) |
| 4180 | dev_put(params.vlan); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4181 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4182 | return err; |
| 4183 | } |
| 4184 | |
| 4185 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) |
| 4186 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4187 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4188 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4189 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4190 | struct station_parameters params; |
| 4191 | u8 *mac_addr = NULL; |
| 4192 | |
| 4193 | memset(¶ms, 0, sizeof(params)); |
| 4194 | |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4195 | if (!rdev->ops->add_station) |
| 4196 | return -EOPNOTSUPP; |
| 4197 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4198 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4199 | return -EINVAL; |
| 4200 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4201 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 4202 | return -EINVAL; |
| 4203 | |
| 4204 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) |
| 4205 | return -EINVAL; |
| 4206 | |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 4207 | if (!info->attrs[NL80211_ATTR_STA_AID] && |
| 4208 | !info->attrs[NL80211_ATTR_PEER_AID]) |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 4209 | return -EINVAL; |
| 4210 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4211 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4212 | params.supported_rates = |
| 4213 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4214 | params.supported_rates_len = |
| 4215 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4216 | params.listen_interval = |
| 4217 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 4218 | |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4219 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 4220 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4221 | else |
| 4222 | 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] | 4223 | if (!params.aid || params.aid > IEEE80211_MAX_AID) |
| 4224 | return -EINVAL; |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 4225 | |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 4226 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
| 4227 | params.capability = |
| 4228 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); |
| 4229 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; |
| 4230 | } |
| 4231 | |
| 4232 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { |
| 4233 | params.ext_capab = |
| 4234 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4235 | params.ext_capab_len = |
| 4236 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4237 | } |
| 4238 | |
Jouni Malinen | 36aedc90 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 4239 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 4240 | params.ht_capa = |
| 4241 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4242 | |
Mahesh Palivela | f461be3e | 2012-10-11 08:04:52 +0000 | [diff] [blame] | 4243 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 4244 | params.vht_capa = |
| 4245 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 4246 | |
Marek Kwaczynski | 60f4a7b | 2013-12-03 10:04:59 +0100 | [diff] [blame] | 4247 | if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) { |
| 4248 | params.opmode_notif_used = true; |
| 4249 | params.opmode_notif = |
| 4250 | nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]); |
| 4251 | } |
| 4252 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4253 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 4254 | params.plink_action = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4255 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 4256 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) |
| 4257 | return -EINVAL; |
| 4258 | } |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 4259 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 4260 | err = nl80211_parse_sta_channel_info(info, ¶ms); |
| 4261 | if (err) |
| 4262 | return err; |
| 4263 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4264 | err = nl80211_parse_sta_wme(info, ¶ms); |
| 4265 | if (err) |
| 4266 | return err; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4267 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 4268 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4269 | return -EINVAL; |
| 4270 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4271 | /* When you run into this, adjust the code below for the new flag */ |
| 4272 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); |
| 4273 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4274 | switch (dev->ieee80211_ptr->iftype) { |
| 4275 | case NL80211_IFTYPE_AP: |
| 4276 | case NL80211_IFTYPE_AP_VLAN: |
| 4277 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4278 | /* ignore WME attributes if iface/sta is not capable */ |
| 4279 | if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) || |
| 4280 | !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) |
| 4281 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4282 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4283 | /* TDLS peers cannot be added */ |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4284 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
| 4285 | info->attrs[NL80211_ATTR_PEER_AID]) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 4286 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4287 | /* but don't bother the driver with it */ |
| 4288 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4289 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4290 | /* allow authenticated/associated only if driver handles it */ |
| 4291 | if (!(rdev->wiphy.features & |
| 4292 | NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
| 4293 | params.sta_flags_mask & |
| 4294 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 4295 | BIT(NL80211_STA_FLAG_ASSOCIATED))) |
| 4296 | return -EINVAL; |
| 4297 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4298 | /* must be last in here for error handling */ |
| 4299 | params.vlan = get_vlan(info, rdev); |
| 4300 | if (IS_ERR(params.vlan)) |
| 4301 | return PTR_ERR(params.vlan); |
| 4302 | break; |
| 4303 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4304 | /* ignore uAPSD data */ |
| 4305 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
| 4306 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4307 | /* associated is disallowed */ |
| 4308 | if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) |
| 4309 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4310 | /* TDLS peers cannot be added */ |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4311 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
| 4312 | info->attrs[NL80211_ATTR_PEER_AID]) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 4313 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4314 | break; |
| 4315 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 93d08f0 | 2013-03-04 09:29:46 +0100 | [diff] [blame] | 4316 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4317 | /* ignore uAPSD data */ |
| 4318 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
| 4319 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4320 | /* these are disallowed */ |
| 4321 | if (params.sta_flags_mask & |
| 4322 | (BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 4323 | BIT(NL80211_STA_FLAG_AUTHENTICATED))) |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4324 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4325 | /* Only TDLS peers can be added */ |
| 4326 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 4327 | return -EINVAL; |
| 4328 | /* Can only add if TDLS ... */ |
| 4329 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) |
| 4330 | return -EOPNOTSUPP; |
| 4331 | /* ... with external setup is supported */ |
| 4332 | if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) |
| 4333 | return -EOPNOTSUPP; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4334 | /* |
| 4335 | * Older wpa_supplicant versions always mark the TDLS peer |
| 4336 | * as authorized, but it shouldn't yet be. |
| 4337 | */ |
| 4338 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED); |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4339 | break; |
| 4340 | default: |
| 4341 | return -EOPNOTSUPP; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4342 | } |
| 4343 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4344 | /* be aware of params.vlan when changing code here */ |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4345 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4346 | err = rdev_add_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4347 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4348 | if (params.vlan) |
| 4349 | dev_put(params.vlan); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4350 | return err; |
| 4351 | } |
| 4352 | |
| 4353 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) |
| 4354 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4355 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4356 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4357 | u8 *mac_addr = NULL; |
| 4358 | |
| 4359 | if (info->attrs[NL80211_ATTR_MAC]) |
| 4360 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4361 | |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 4362 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Marco Porsch | d5d9de0 | 2010-03-30 10:00:16 +0200 | [diff] [blame] | 4363 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4364 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4365 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4366 | return -EINVAL; |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 4367 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4368 | if (!rdev->ops->del_station) |
| 4369 | return -EOPNOTSUPP; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4370 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4371 | return rdev_del_station(rdev, dev, mac_addr); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4372 | } |
| 4373 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4374 | 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] | 4375 | int flags, struct net_device *dev, |
| 4376 | u8 *dst, u8 *next_hop, |
| 4377 | struct mpath_info *pinfo) |
| 4378 | { |
| 4379 | void *hdr; |
| 4380 | struct nlattr *pinfoattr; |
| 4381 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4382 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4383 | if (!hdr) |
| 4384 | return -1; |
| 4385 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4386 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 4387 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || |
| 4388 | nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) || |
| 4389 | nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation)) |
| 4390 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 4391 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4392 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
| 4393 | if (!pinfoattr) |
| 4394 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4395 | if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) && |
| 4396 | nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN, |
| 4397 | pinfo->frame_qlen)) |
| 4398 | goto nla_put_failure; |
| 4399 | if (((pinfo->filled & MPATH_INFO_SN) && |
| 4400 | nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) || |
| 4401 | ((pinfo->filled & MPATH_INFO_METRIC) && |
| 4402 | nla_put_u32(msg, NL80211_MPATH_INFO_METRIC, |
| 4403 | pinfo->metric)) || |
| 4404 | ((pinfo->filled & MPATH_INFO_EXPTIME) && |
| 4405 | nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME, |
| 4406 | pinfo->exptime)) || |
| 4407 | ((pinfo->filled & MPATH_INFO_FLAGS) && |
| 4408 | nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS, |
| 4409 | pinfo->flags)) || |
| 4410 | ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) && |
| 4411 | nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, |
| 4412 | pinfo->discovery_timeout)) || |
| 4413 | ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) && |
| 4414 | nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, |
| 4415 | pinfo->discovery_retries))) |
| 4416 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4417 | |
| 4418 | nla_nest_end(msg, pinfoattr); |
| 4419 | |
| 4420 | return genlmsg_end(msg, hdr); |
| 4421 | |
| 4422 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 4423 | genlmsg_cancel(msg, hdr); |
| 4424 | return -EMSGSIZE; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4425 | } |
| 4426 | |
| 4427 | static int nl80211_dump_mpath(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4428 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4429 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4430 | struct mpath_info pinfo; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4431 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4432 | struct wireless_dev *wdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4433 | u8 dst[ETH_ALEN]; |
| 4434 | u8 next_hop[ETH_ALEN]; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4435 | int path_idx = cb->args[2]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4436 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4437 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4438 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4439 | if (err) |
| 4440 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4441 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4442 | if (!rdev->ops->dump_mpath) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4443 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4444 | goto out_err; |
| 4445 | } |
| 4446 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4447 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4448 | err = -EOPNOTSUPP; |
Roel Kluin | 0448b5f | 2009-08-22 21:15:49 +0200 | [diff] [blame] | 4449 | goto out_err; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4450 | } |
| 4451 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4452 | while (1) { |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4453 | err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4454 | next_hop, &pinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4455 | if (err == -ENOENT) |
| 4456 | break; |
| 4457 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4458 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4459 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4460 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4461 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4462 | wdev->netdev, dst, next_hop, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4463 | &pinfo) < 0) |
| 4464 | goto out; |
| 4465 | |
| 4466 | path_idx++; |
| 4467 | } |
| 4468 | |
| 4469 | |
| 4470 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4471 | cb->args[2] = path_idx; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4472 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4473 | out_err: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4474 | nl80211_finish_wdev_dump(rdev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4475 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4476 | } |
| 4477 | |
| 4478 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4479 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4480 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4481 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4482 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4483 | struct mpath_info pinfo; |
| 4484 | struct sk_buff *msg; |
| 4485 | u8 *dst = NULL; |
| 4486 | u8 next_hop[ETH_ALEN]; |
| 4487 | |
| 4488 | memset(&pinfo, 0, sizeof(pinfo)); |
| 4489 | |
| 4490 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4491 | return -EINVAL; |
| 4492 | |
| 4493 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4494 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4495 | if (!rdev->ops->get_mpath) |
| 4496 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4497 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4498 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4499 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4500 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4501 | err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4502 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4503 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4504 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4505 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4506 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4507 | return -ENOMEM; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4508 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4509 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4510 | dev, dst, next_hop, &pinfo) < 0) { |
| 4511 | nlmsg_free(msg); |
| 4512 | return -ENOBUFS; |
| 4513 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4514 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4515 | return genlmsg_reply(msg, info); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4516 | } |
| 4517 | |
| 4518 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4519 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4520 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4521 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4522 | u8 *dst = NULL; |
| 4523 | u8 *next_hop = NULL; |
| 4524 | |
| 4525 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4526 | return -EINVAL; |
| 4527 | |
| 4528 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 4529 | return -EINVAL; |
| 4530 | |
| 4531 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4532 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 4533 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4534 | if (!rdev->ops->change_mpath) |
| 4535 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4536 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4537 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4538 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4539 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4540 | return rdev_change_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4541 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4542 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4543 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4544 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4545 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4546 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4547 | u8 *dst = NULL; |
| 4548 | u8 *next_hop = NULL; |
| 4549 | |
| 4550 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4551 | return -EINVAL; |
| 4552 | |
| 4553 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 4554 | return -EINVAL; |
| 4555 | |
| 4556 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4557 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 4558 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4559 | if (!rdev->ops->add_mpath) |
| 4560 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4561 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4562 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4563 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4564 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4565 | return rdev_add_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4566 | } |
| 4567 | |
| 4568 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4569 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4570 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4571 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4572 | u8 *dst = NULL; |
| 4573 | |
| 4574 | if (info->attrs[NL80211_ATTR_MAC]) |
| 4575 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4576 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4577 | if (!rdev->ops->del_mpath) |
| 4578 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4579 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4580 | return rdev_del_mpath(rdev, dev, dst); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4581 | } |
| 4582 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4583 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
| 4584 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4585 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4586 | struct net_device *dev = info->user_ptr[1]; |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 4587 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4588 | struct bss_parameters params; |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 4589 | int err; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4590 | |
| 4591 | memset(¶ms, 0, sizeof(params)); |
| 4592 | /* default to not changing parameters */ |
| 4593 | params.use_cts_prot = -1; |
| 4594 | params.use_short_preamble = -1; |
| 4595 | params.use_short_slot_time = -1; |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 4596 | params.ap_isolate = -1; |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 4597 | params.ht_opmode = -1; |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 4598 | params.p2p_ctwindow = -1; |
| 4599 | params.p2p_opp_ps = -1; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4600 | |
| 4601 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) |
| 4602 | params.use_cts_prot = |
| 4603 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); |
| 4604 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) |
| 4605 | params.use_short_preamble = |
| 4606 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); |
| 4607 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) |
| 4608 | params.use_short_slot_time = |
| 4609 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 4610 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 4611 | params.basic_rates = |
| 4612 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 4613 | params.basic_rates_len = |
| 4614 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 4615 | } |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 4616 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
| 4617 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 4618 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
| 4619 | params.ht_opmode = |
| 4620 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4621 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 4622 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 4623 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4624 | return -EINVAL; |
| 4625 | params.p2p_ctwindow = |
| 4626 | nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
| 4627 | if (params.p2p_ctwindow < 0) |
| 4628 | return -EINVAL; |
| 4629 | if (params.p2p_ctwindow != 0 && |
| 4630 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 4631 | return -EINVAL; |
| 4632 | } |
| 4633 | |
| 4634 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 4635 | u8 tmp; |
| 4636 | |
| 4637 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4638 | return -EINVAL; |
| 4639 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
| 4640 | if (tmp > 1) |
| 4641 | return -EINVAL; |
| 4642 | params.p2p_opp_ps = tmp; |
| 4643 | if (params.p2p_opp_ps && |
| 4644 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 4645 | return -EINVAL; |
| 4646 | } |
| 4647 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4648 | if (!rdev->ops->change_bss) |
| 4649 | return -EOPNOTSUPP; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4650 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4651 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4652 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4653 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4654 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 4655 | wdev_lock(wdev); |
| 4656 | err = rdev_change_bss(rdev, dev, ¶ms); |
| 4657 | wdev_unlock(wdev); |
| 4658 | |
| 4659 | return err; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4660 | } |
| 4661 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 4662 | 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] | 4663 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
| 4664 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, |
| 4665 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, |
| 4666 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, |
| 4667 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, |
| 4668 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, |
Janusz Dziedzic | 089027e | 2014-02-21 19:46:12 +0100 | [diff] [blame] | 4669 | [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 }, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4670 | }; |
| 4671 | |
| 4672 | static int parse_reg_rule(struct nlattr *tb[], |
| 4673 | struct ieee80211_reg_rule *reg_rule) |
| 4674 | { |
| 4675 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; |
| 4676 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; |
| 4677 | |
| 4678 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) |
| 4679 | return -EINVAL; |
| 4680 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) |
| 4681 | return -EINVAL; |
| 4682 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) |
| 4683 | return -EINVAL; |
Janusz Dziedzic | b0dfd2e | 2014-02-20 13:52:16 +0100 | [diff] [blame] | 4684 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) |
| 4685 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4686 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) |
| 4687 | return -EINVAL; |
| 4688 | |
| 4689 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); |
| 4690 | |
| 4691 | freq_range->start_freq_khz = |
| 4692 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); |
| 4693 | freq_range->end_freq_khz = |
| 4694 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); |
Janusz Dziedzic | b0dfd2e | 2014-02-20 13:52:16 +0100 | [diff] [blame] | 4695 | freq_range->max_bandwidth_khz = |
| 4696 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4697 | |
| 4698 | power_rule->max_eirp = |
| 4699 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); |
| 4700 | |
| 4701 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) |
| 4702 | power_rule->max_antenna_gain = |
| 4703 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); |
| 4704 | |
Janusz Dziedzic | 089027e | 2014-02-21 19:46:12 +0100 | [diff] [blame] | 4705 | if (tb[NL80211_ATTR_DFS_CAC_TIME]) |
| 4706 | reg_rule->dfs_cac_ms = |
| 4707 | nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]); |
| 4708 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4709 | return 0; |
| 4710 | } |
| 4711 | |
| 4712 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 4713 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4714 | char *data = NULL; |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4715 | enum nl80211_user_reg_hint_type user_reg_hint_type; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4716 | |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 4717 | /* |
| 4718 | * You should only get this when cfg80211 hasn't yet initialized |
| 4719 | * completely when built-in to the kernel right between the time |
| 4720 | * window between nl80211_init() and regulatory_init(), if that is |
| 4721 | * even possible. |
| 4722 | */ |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4723 | if (unlikely(!rcu_access_pointer(cfg80211_regdomain))) |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 4724 | return -EINPROGRESS; |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 4725 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4726 | if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]) |
| 4727 | user_reg_hint_type = |
| 4728 | nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]); |
| 4729 | else |
| 4730 | user_reg_hint_type = NL80211_USER_REG_HINT_USER; |
| 4731 | |
| 4732 | switch (user_reg_hint_type) { |
| 4733 | case NL80211_USER_REG_HINT_USER: |
| 4734 | case NL80211_USER_REG_HINT_CELL_BASE: |
Ilan Peer | 52616f2 | 2014-02-25 16:26:00 +0200 | [diff] [blame] | 4735 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 4736 | return -EINVAL; |
| 4737 | |
| 4738 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 4739 | return regulatory_hint_user(data, user_reg_hint_type); |
| 4740 | case NL80211_USER_REG_HINT_INDOOR: |
| 4741 | return regulatory_hint_indoor_user(); |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4742 | default: |
| 4743 | return -EINVAL; |
| 4744 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4745 | } |
| 4746 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4747 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4748 | struct genl_info *info) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4749 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4750 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4751 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4752 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 4753 | struct mesh_config cur_params; |
| 4754 | int err = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4755 | void *hdr; |
| 4756 | struct nlattr *pinfoattr; |
| 4757 | struct sk_buff *msg; |
| 4758 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4759 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4760 | return -EOPNOTSUPP; |
| 4761 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4762 | if (!rdev->ops->get_mesh_config) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4763 | return -EOPNOTSUPP; |
Jouni Malinen | f3f9258 | 2009-03-20 17:57:36 +0200 | [diff] [blame] | 4764 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4765 | wdev_lock(wdev); |
| 4766 | /* If not connected, get default parameters */ |
| 4767 | if (!wdev->mesh_id_len) |
| 4768 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); |
| 4769 | else |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4770 | err = rdev_get_mesh_config(rdev, dev, &cur_params); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4771 | wdev_unlock(wdev); |
| 4772 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4773 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4774 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4775 | |
| 4776 | /* Draw up a netlink message to send back */ |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4777 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4778 | if (!msg) |
| 4779 | return -ENOMEM; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4780 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4781 | NL80211_CMD_GET_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4782 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4783 | goto out; |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4784 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4785 | if (!pinfoattr) |
| 4786 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4787 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 4788 | nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 4789 | cur_params.dot11MeshRetryTimeout) || |
| 4790 | nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 4791 | cur_params.dot11MeshConfirmTimeout) || |
| 4792 | nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 4793 | cur_params.dot11MeshHoldingTimeout) || |
| 4794 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 4795 | cur_params.dot11MeshMaxPeerLinks) || |
| 4796 | nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES, |
| 4797 | cur_params.dot11MeshMaxRetries) || |
| 4798 | nla_put_u8(msg, NL80211_MESHCONF_TTL, |
| 4799 | cur_params.dot11MeshTTL) || |
| 4800 | nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL, |
| 4801 | cur_params.element_ttl) || |
| 4802 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 4803 | cur_params.auto_open_plinks) || |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 4804 | nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 4805 | cur_params.dot11MeshNbrOffsetMaxNeighbor) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4806 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 4807 | cur_params.dot11MeshHWMPmaxPREQretries) || |
| 4808 | nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 4809 | cur_params.path_refresh_time) || |
| 4810 | nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 4811 | cur_params.min_discovery_timeout) || |
| 4812 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 4813 | cur_params.dot11MeshHWMPactivePathTimeout) || |
| 4814 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 4815 | cur_params.dot11MeshHWMPpreqMinInterval) || |
| 4816 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
| 4817 | cur_params.dot11MeshHWMPperrMinInterval) || |
| 4818 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 4819 | cur_params.dot11MeshHWMPnetDiameterTraversalTime) || |
| 4820 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 4821 | cur_params.dot11MeshHWMPRootMode) || |
| 4822 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
| 4823 | cur_params.dot11MeshHWMPRannInterval) || |
| 4824 | nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
| 4825 | cur_params.dot11MeshGateAnnouncementProtocol) || |
| 4826 | nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, |
| 4827 | cur_params.dot11MeshForwarding) || |
| 4828 | nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, |
Ashok Nagarajan | 70c33ea | 2012-04-30 14:20:32 -0700 | [diff] [blame] | 4829 | cur_params.rssi_threshold) || |
| 4830 | nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4831 | cur_params.ht_opmode) || |
| 4832 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 4833 | cur_params.dot11MeshHWMPactivePathToRootTimeout) || |
| 4834 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4835 | cur_params.dot11MeshHWMProotInterval) || |
| 4836 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4837 | cur_params.dot11MeshHWMPconfirmationInterval) || |
| 4838 | nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE, |
| 4839 | cur_params.power_mode) || |
| 4840 | nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW, |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 4841 | cur_params.dot11MeshAwakeWindowDuration) || |
| 4842 | nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT, |
| 4843 | cur_params.plink_timeout)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4844 | goto nla_put_failure; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4845 | nla_nest_end(msg, pinfoattr); |
| 4846 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4847 | return genlmsg_reply(msg, info); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4848 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4849 | nla_put_failure: |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4850 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4851 | out: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 4852 | nlmsg_free(msg); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4853 | return -ENOBUFS; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4854 | } |
| 4855 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 4856 | 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] | 4857 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
| 4858 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, |
| 4859 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, |
| 4860 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, |
| 4861 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, |
| 4862 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 4863 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4864 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 4865 | [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4866 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
| 4867 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, |
| 4868 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, |
| 4869 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, |
| 4870 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 4871 | [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4872 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
Javier Cardona | 699403d | 2011-08-09 16:45:09 -0700 | [diff] [blame] | 4873 | [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 }, |
Javier Cardona | 0507e15 | 2011-08-09 16:45:10 -0700 | [diff] [blame] | 4874 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 }, |
Javier Cardona | 16dd726 | 2011-08-09 16:45:11 -0700 | [diff] [blame] | 4875 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | 94f9065 | 2012-01-21 01:02:16 +0800 | [diff] [blame] | 4876 | [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4877 | [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 }, |
| 4878 | [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4879 | [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 }, |
| 4880 | [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4881 | [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 }, |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4882 | [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 }, |
| 4883 | [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 }, |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 4884 | [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4885 | }; |
| 4886 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4887 | static const struct nla_policy |
| 4888 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 4889 | [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4890 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
| 4891 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 4892 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
Colleen Twitty | 6e16d90 | 2013-05-08 11:45:59 -0700 | [diff] [blame] | 4893 | [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 }, |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 4894 | [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG }, |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4895 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4896 | .len = IEEE80211_MAX_DATA_LEN }, |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 4897 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4898 | }; |
| 4899 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4900 | static int nl80211_parse_mesh_config(struct genl_info *info, |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4901 | struct mesh_config *cfg, |
| 4902 | u32 *mask_out) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4903 | { |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4904 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4905 | u32 mask = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4906 | |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4907 | #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \ |
| 4908 | do { \ |
| 4909 | if (tb[attr]) { \ |
| 4910 | if (fn(tb[attr]) < min || fn(tb[attr]) > max) \ |
| 4911 | return -EINVAL; \ |
| 4912 | cfg->param = fn(tb[attr]); \ |
| 4913 | mask |= (1 << (attr - 1)); \ |
| 4914 | } \ |
| 4915 | } while (0) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4916 | |
| 4917 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4918 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4919 | return -EINVAL; |
| 4920 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4921 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4922 | nl80211_meshconf_params_policy)) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4923 | return -EINVAL; |
| 4924 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4925 | /* This makes sure that there aren't more than 32 mesh config |
| 4926 | * parameters (otherwise our bitfield scheme would not work.) */ |
| 4927 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); |
| 4928 | |
| 4929 | /* Fill in the params struct */ |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4930 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4931 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 4932 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4933 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4934 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 4935 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4936 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4937 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 4938 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4939 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4940 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 4941 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4942 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4943 | mask, NL80211_MESHCONF_MAX_RETRIES, |
| 4944 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4945 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4946 | mask, NL80211_MESHCONF_TTL, nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4947 | 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] | 4948 | mask, NL80211_MESHCONF_ELEMENT_TTL, |
| 4949 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4950 | 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] | 4951 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 4952 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4953 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, |
| 4954 | 1, 255, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4955 | NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 4956 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4957 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4958 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 4959 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4960 | 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] | 4961 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 4962 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4963 | 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] | 4964 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 4965 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4966 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
| 4967 | 1, 65535, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4968 | NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 4969 | nla_get_u32); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4970 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4971 | 1, 65535, mask, |
| 4972 | NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4973 | nla_get_u16); |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 4974 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4975 | 1, 65535, mask, |
| 4976 | NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4977 | nla_get_u16); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4978 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4979 | dot11MeshHWMPnetDiameterTraversalTime, |
| 4980 | 1, 65535, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4981 | NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 4982 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4983 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4, |
| 4984 | mask, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 4985 | nla_get_u8); |
| 4986 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535, |
| 4987 | mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4988 | nla_get_u16); |
Rui Paulo | 63c5723 | 2009-11-09 23:46:57 +0000 | [diff] [blame] | 4989 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4990 | dot11MeshGateAnnouncementProtocol, 0, 1, |
| 4991 | mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4992 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4993 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4994 | mask, NL80211_MESHCONF_FORWARDING, |
| 4995 | nla_get_u8); |
Chun-Yeow Yeoh | 83374fe | 2013-07-11 18:24:03 +0800 | [diff] [blame] | 4996 | 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] | 4997 | mask, NL80211_MESHCONF_RSSI_THRESHOLD, |
Chun-Yeow Yeoh | 83374fe | 2013-07-11 18:24:03 +0800 | [diff] [blame] | 4998 | nla_get_s32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4999 | 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] | 5000 | mask, NL80211_MESHCONF_HT_OPMODE, |
| 5001 | nla_get_u16); |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 5002 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5003 | 1, 65535, mask, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 5004 | NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 5005 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5006 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 5007 | mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
| 5008 | nla_get_u16); |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 5009 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5010 | dot11MeshHWMPconfirmationInterval, |
| 5011 | 1, 65535, mask, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 5012 | NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
| 5013 | nla_get_u16); |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 5014 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode, |
| 5015 | NL80211_MESH_POWER_ACTIVE, |
| 5016 | NL80211_MESH_POWER_MAX, |
| 5017 | mask, NL80211_MESHCONF_POWER_MODE, |
| 5018 | nla_get_u32); |
| 5019 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration, |
| 5020 | 0, 65535, mask, |
| 5021 | NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16); |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 5022 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 1, 0xffffffff, |
| 5023 | mask, NL80211_MESHCONF_PLINK_TIMEOUT, |
| 5024 | nla_get_u32); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5025 | if (mask_out) |
| 5026 | *mask_out = mask; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5027 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5028 | return 0; |
| 5029 | |
| 5030 | #undef FILL_IN_MESH_PARAM_IF_SET |
| 5031 | } |
| 5032 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5033 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
| 5034 | struct mesh_setup *setup) |
| 5035 | { |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 5036 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5037 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
| 5038 | |
| 5039 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) |
| 5040 | return -EINVAL; |
| 5041 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, |
| 5042 | info->attrs[NL80211_ATTR_MESH_SETUP], |
| 5043 | nl80211_mesh_setup_params_policy)) |
| 5044 | return -EINVAL; |
| 5045 | |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 5046 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC]) |
| 5047 | setup->sync_method = |
| 5048 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ? |
| 5049 | IEEE80211_SYNC_METHOD_VENDOR : |
| 5050 | IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET; |
| 5051 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5052 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
| 5053 | setup->path_sel_proto = |
| 5054 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? |
| 5055 | IEEE80211_PATH_PROTOCOL_VENDOR : |
| 5056 | IEEE80211_PATH_PROTOCOL_HWMP; |
| 5057 | |
| 5058 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) |
| 5059 | setup->path_metric = |
| 5060 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? |
| 5061 | IEEE80211_PATH_METRIC_VENDOR : |
| 5062 | IEEE80211_PATH_METRIC_AIRTIME; |
| 5063 | |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 5064 | |
| 5065 | if (tb[NL80211_MESH_SETUP_IE]) { |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5066 | struct nlattr *ieattr = |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 5067 | tb[NL80211_MESH_SETUP_IE]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5068 | if (!is_valid_ie_attr(ieattr)) |
| 5069 | return -EINVAL; |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 5070 | setup->ie = nla_data(ieattr); |
| 5071 | setup->ie_len = nla_len(ieattr); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5072 | } |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 5073 | if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] && |
| 5074 | !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM)) |
| 5075 | return -EINVAL; |
| 5076 | setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]); |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 5077 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
| 5078 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 5079 | if (setup->is_secure) |
| 5080 | setup->user_mpm = true; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5081 | |
Colleen Twitty | 6e16d90 | 2013-05-08 11:45:59 -0700 | [diff] [blame] | 5082 | if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) { |
| 5083 | if (!setup->user_mpm) |
| 5084 | return -EINVAL; |
| 5085 | setup->auth_id = |
| 5086 | nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]); |
| 5087 | } |
| 5088 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5089 | return 0; |
| 5090 | } |
| 5091 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5092 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5093 | struct genl_info *info) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5094 | { |
| 5095 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5096 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5097 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5098 | struct mesh_config cfg; |
| 5099 | u32 mask; |
| 5100 | int err; |
| 5101 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5102 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 5103 | return -EOPNOTSUPP; |
| 5104 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5105 | if (!rdev->ops->update_mesh_config) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5106 | return -EOPNOTSUPP; |
| 5107 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5108 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5109 | if (err) |
| 5110 | return err; |
| 5111 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5112 | wdev_lock(wdev); |
| 5113 | if (!wdev->mesh_id_len) |
| 5114 | err = -ENOLINK; |
| 5115 | |
| 5116 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5117 | err = rdev_update_mesh_config(rdev, dev, mask, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5118 | |
| 5119 | wdev_unlock(wdev); |
| 5120 | |
| 5121 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5122 | } |
| 5123 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5124 | static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info) |
| 5125 | { |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5126 | const struct ieee80211_regdomain *regdom; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5127 | struct sk_buff *msg; |
| 5128 | void *hdr = NULL; |
| 5129 | struct nlattr *nl_reg_rules; |
| 5130 | unsigned int i; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5131 | |
| 5132 | if (!cfg80211_regdomain) |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5133 | return -EINVAL; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5134 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 5135 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5136 | if (!msg) |
| 5137 | return -ENOBUFS; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5138 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5139 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5140 | NL80211_CMD_GET_REG); |
| 5141 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 5142 | goto put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5143 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 5144 | if (reg_last_request_cell_base() && |
| 5145 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, |
| 5146 | NL80211_USER_REG_HINT_CELL_BASE)) |
| 5147 | goto nla_put_failure; |
| 5148 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5149 | rcu_read_lock(); |
| 5150 | regdom = rcu_dereference(cfg80211_regdomain); |
| 5151 | |
| 5152 | if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) || |
| 5153 | (regdom->dfs_region && |
| 5154 | nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region))) |
| 5155 | goto nla_put_failure_rcu; |
| 5156 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5157 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
| 5158 | if (!nl_reg_rules) |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5159 | goto nla_put_failure_rcu; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5160 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5161 | for (i = 0; i < regdom->n_reg_rules; i++) { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5162 | struct nlattr *nl_reg_rule; |
| 5163 | const struct ieee80211_reg_rule *reg_rule; |
| 5164 | const struct ieee80211_freq_range *freq_range; |
| 5165 | const struct ieee80211_power_rule *power_rule; |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 5166 | unsigned int max_bandwidth_khz; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5167 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5168 | reg_rule = ®dom->reg_rules[i]; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5169 | freq_range = ®_rule->freq_range; |
| 5170 | power_rule = ®_rule->power_rule; |
| 5171 | |
| 5172 | nl_reg_rule = nla_nest_start(msg, i); |
| 5173 | if (!nl_reg_rule) |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5174 | goto nla_put_failure_rcu; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5175 | |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 5176 | max_bandwidth_khz = freq_range->max_bandwidth_khz; |
| 5177 | if (!max_bandwidth_khz) |
| 5178 | max_bandwidth_khz = reg_get_max_bandwidth(regdom, |
| 5179 | reg_rule); |
| 5180 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5181 | if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
| 5182 | reg_rule->flags) || |
| 5183 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START, |
| 5184 | freq_range->start_freq_khz) || |
| 5185 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END, |
| 5186 | freq_range->end_freq_khz) || |
| 5187 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 5188 | max_bandwidth_khz) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5189 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
| 5190 | power_rule->max_antenna_gain) || |
| 5191 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, |
Janusz Dziedzic | 089027e | 2014-02-21 19:46:12 +0100 | [diff] [blame] | 5192 | power_rule->max_eirp) || |
| 5193 | nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME, |
| 5194 | reg_rule->dfs_cac_ms)) |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5195 | goto nla_put_failure_rcu; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5196 | |
| 5197 | nla_nest_end(msg, nl_reg_rule); |
| 5198 | } |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5199 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5200 | |
| 5201 | nla_nest_end(msg, nl_reg_rules); |
| 5202 | |
| 5203 | genlmsg_end(msg, hdr); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5204 | return genlmsg_reply(msg, info); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5205 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5206 | nla_put_failure_rcu: |
| 5207 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5208 | nla_put_failure: |
| 5209 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 5210 | put_failure: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 5211 | nlmsg_free(msg); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5212 | return -EMSGSIZE; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5213 | } |
| 5214 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5215 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 5216 | { |
| 5217 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; |
| 5218 | struct nlattr *nl_reg_rule; |
| 5219 | char *alpha2 = NULL; |
| 5220 | int rem_reg_rules = 0, r = 0; |
| 5221 | u32 num_rules = 0, rule_idx = 0, size_of_regd; |
Luis R. Rodriguez | 4c7d398 | 2013-11-13 18:54:02 +0100 | [diff] [blame] | 5222 | enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5223 | struct ieee80211_regdomain *rd = NULL; |
| 5224 | |
| 5225 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 5226 | return -EINVAL; |
| 5227 | |
| 5228 | if (!info->attrs[NL80211_ATTR_REG_RULES]) |
| 5229 | return -EINVAL; |
| 5230 | |
| 5231 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 5232 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 5233 | if (info->attrs[NL80211_ATTR_DFS_REGION]) |
| 5234 | dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); |
| 5235 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5236 | 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] | 5237 | rem_reg_rules) { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5238 | num_rules++; |
| 5239 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) |
Luis R. Rodriguez | 4776c6e | 2009-05-13 17:04:39 -0400 | [diff] [blame] | 5240 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5241 | } |
| 5242 | |
Luis R. Rodriguez | e438768 | 2013-11-05 09:18:01 -0800 | [diff] [blame] | 5243 | if (!reg_is_valid_request(alpha2)) |
| 5244 | return -EINVAL; |
| 5245 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5246 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 5247 | num_rules * sizeof(struct ieee80211_reg_rule); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5248 | |
| 5249 | rd = kzalloc(size_of_regd, GFP_KERNEL); |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 5250 | if (!rd) |
| 5251 | return -ENOMEM; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5252 | |
| 5253 | rd->n_reg_rules = num_rules; |
| 5254 | rd->alpha2[0] = alpha2[0]; |
| 5255 | rd->alpha2[1] = alpha2[1]; |
| 5256 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 5257 | /* |
| 5258 | * Disable DFS master mode if the DFS region was |
| 5259 | * not supported or known on this kernel. |
| 5260 | */ |
| 5261 | if (reg_supported_dfs_region(dfs_region)) |
| 5262 | rd->dfs_region = dfs_region; |
| 5263 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5264 | 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] | 5265 | rem_reg_rules) { |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 5266 | r = nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, |
| 5267 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), |
| 5268 | reg_rule_policy); |
| 5269 | if (r) |
| 5270 | goto bad_reg; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5271 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
| 5272 | if (r) |
| 5273 | goto bad_reg; |
| 5274 | |
| 5275 | rule_idx++; |
| 5276 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 5277 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
| 5278 | r = -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5279 | goto bad_reg; |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 5280 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5281 | } |
| 5282 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5283 | r = set_regdom(rd); |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 5284 | /* set_regdom took ownership */ |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 5285 | rd = NULL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5286 | |
Johannes Berg | d2372b3 | 2008-10-24 20:32:20 +0200 | [diff] [blame] | 5287 | bad_reg: |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5288 | kfree(rd); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 5289 | return r; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5290 | } |
| 5291 | |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5292 | static int validate_scan_freqs(struct nlattr *freqs) |
| 5293 | { |
| 5294 | struct nlattr *attr1, *attr2; |
| 5295 | int n_channels = 0, tmp1, tmp2; |
| 5296 | |
| 5297 | nla_for_each_nested(attr1, freqs, tmp1) { |
| 5298 | n_channels++; |
| 5299 | /* |
| 5300 | * Some hardware has a limited channel list for |
| 5301 | * scanning, and it is pretty much nonsensical |
| 5302 | * to scan for a channel twice, so disallow that |
| 5303 | * and don't require drivers to check that the |
| 5304 | * channel list they get isn't longer than what |
| 5305 | * they can scan, as long as they can scan all |
| 5306 | * the channels they registered at once. |
| 5307 | */ |
| 5308 | nla_for_each_nested(attr2, freqs, tmp2) |
| 5309 | if (attr1 != attr2 && |
| 5310 | nla_get_u32(attr1) == nla_get_u32(attr2)) |
| 5311 | return 0; |
| 5312 | } |
| 5313 | |
| 5314 | return n_channels; |
| 5315 | } |
| 5316 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5317 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
| 5318 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5319 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 5320 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5321 | struct cfg80211_scan_request *request; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5322 | struct nlattr *attr; |
| 5323 | struct wiphy *wiphy; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5324 | int err, tmp, n_ssids = 0, n_channels, i; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5325 | size_t ie_len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5326 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5327 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5328 | return -EINVAL; |
| 5329 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5330 | wiphy = &rdev->wiphy; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5331 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5332 | if (!rdev->ops->scan) |
| 5333 | return -EOPNOTSUPP; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5334 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 5335 | if (rdev->scan_req || rdev->scan_msg) { |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5336 | err = -EBUSY; |
| 5337 | goto unlock; |
| 5338 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5339 | |
| 5340 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5341 | n_channels = validate_scan_freqs( |
| 5342 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5343 | if (!n_channels) { |
| 5344 | err = -EINVAL; |
| 5345 | goto unlock; |
| 5346 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5347 | } else { |
Ilan Peer | bdfbec2 | 2014-01-09 11:37:23 +0200 | [diff] [blame] | 5348 | n_channels = ieee80211_get_num_supported_channels(wiphy); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5349 | } |
| 5350 | |
| 5351 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 5352 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) |
| 5353 | n_ssids++; |
| 5354 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5355 | if (n_ssids > wiphy->max_scan_ssids) { |
| 5356 | err = -EINVAL; |
| 5357 | goto unlock; |
| 5358 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5359 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5360 | if (info->attrs[NL80211_ATTR_IE]) |
| 5361 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5362 | else |
| 5363 | ie_len = 0; |
| 5364 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5365 | if (ie_len > wiphy->max_scan_ie_len) { |
| 5366 | err = -EINVAL; |
| 5367 | goto unlock; |
| 5368 | } |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 5369 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5370 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 5371 | + sizeof(*request->ssids) * n_ssids |
| 5372 | + sizeof(*request->channels) * n_channels |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5373 | + ie_len, GFP_KERNEL); |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5374 | if (!request) { |
| 5375 | err = -ENOMEM; |
| 5376 | goto unlock; |
| 5377 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5378 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5379 | if (n_ssids) |
Johannes Berg | 5ba6353 | 2009-08-07 17:54:07 +0200 | [diff] [blame] | 5380 | request->ssids = (void *)&request->channels[n_channels]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5381 | request->n_ssids = n_ssids; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5382 | if (ie_len) { |
| 5383 | if (request->ssids) |
| 5384 | request->ie = (void *)(request->ssids + n_ssids); |
| 5385 | else |
| 5386 | request->ie = (void *)(request->channels + n_channels); |
| 5387 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5388 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5389 | i = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5390 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 5391 | /* user specified, bail out if channel not found */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5392 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5393 | struct ieee80211_channel *chan; |
| 5394 | |
| 5395 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 5396 | |
| 5397 | if (!chan) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5398 | err = -EINVAL; |
| 5399 | goto out_free; |
| 5400 | } |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5401 | |
| 5402 | /* ignore disabled channels */ |
| 5403 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5404 | continue; |
| 5405 | |
| 5406 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5407 | i++; |
| 5408 | } |
| 5409 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5410 | enum ieee80211_band band; |
| 5411 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5412 | /* all channels */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5413 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 5414 | int j; |
| 5415 | if (!wiphy->bands[band]) |
| 5416 | continue; |
| 5417 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5418 | struct ieee80211_channel *chan; |
| 5419 | |
| 5420 | chan = &wiphy->bands[band]->channels[j]; |
| 5421 | |
| 5422 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5423 | continue; |
| 5424 | |
| 5425 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5426 | i++; |
| 5427 | } |
| 5428 | } |
| 5429 | } |
| 5430 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5431 | if (!i) { |
| 5432 | err = -EINVAL; |
| 5433 | goto out_free; |
| 5434 | } |
| 5435 | |
| 5436 | request->n_channels = i; |
| 5437 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5438 | i = 0; |
| 5439 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 5440 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5441 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5442 | err = -EINVAL; |
| 5443 | goto out_free; |
| 5444 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5445 | request->ssids[i].ssid_len = nla_len(attr); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5446 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5447 | i++; |
| 5448 | } |
| 5449 | } |
| 5450 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5451 | if (info->attrs[NL80211_ATTR_IE]) { |
| 5452 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Johannes Berg | de95a54 | 2009-04-01 11:58:36 +0200 | [diff] [blame] | 5453 | memcpy((void *)request->ie, |
| 5454 | nla_data(info->attrs[NL80211_ATTR_IE]), |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5455 | request->ie_len); |
| 5456 | } |
| 5457 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5458 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) |
Johannes Berg | a401d2b | 2011-07-20 00:52:16 +0200 | [diff] [blame] | 5459 | if (wiphy->bands[i]) |
| 5460 | request->rates[i] = |
| 5461 | (1 << wiphy->bands[i]->n_bitrates) - 1; |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5462 | |
| 5463 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { |
| 5464 | nla_for_each_nested(attr, |
| 5465 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], |
| 5466 | tmp) { |
| 5467 | enum ieee80211_band band = nla_type(attr); |
| 5468 | |
Dan Carpenter | 8440462 | 2011-07-29 11:52:18 +0300 | [diff] [blame] | 5469 | if (band < 0 || band >= IEEE80211_NUM_BANDS) { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5470 | err = -EINVAL; |
| 5471 | goto out_free; |
| 5472 | } |
Felix Fietkau | 1b09cd8 | 2013-11-20 19:40:41 +0100 | [diff] [blame] | 5473 | |
| 5474 | if (!wiphy->bands[band]) |
| 5475 | continue; |
| 5476 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5477 | err = ieee80211_get_ratemask(wiphy->bands[band], |
| 5478 | nla_data(attr), |
| 5479 | nla_len(attr), |
| 5480 | &request->rates[band]); |
| 5481 | if (err) |
| 5482 | goto out_free; |
| 5483 | } |
| 5484 | } |
| 5485 | |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5486 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5487 | request->flags = nla_get_u32( |
| 5488 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); |
Johannes Berg | 00c3a6e | 2013-10-26 17:14:38 +0200 | [diff] [blame] | 5489 | if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 5490 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) { |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5491 | err = -EOPNOTSUPP; |
| 5492 | goto out_free; |
| 5493 | } |
| 5494 | } |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5495 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 5496 | request->no_cck = |
| 5497 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 5498 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 5499 | request->wdev = wdev; |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5500 | request->wiphy = &rdev->wiphy; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 5501 | request->scan_start = jiffies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5502 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5503 | rdev->scan_req = request; |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5504 | err = rdev_scan(rdev, request); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5505 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5506 | if (!err) { |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 5507 | nl80211_send_scan_start(rdev, wdev); |
| 5508 | if (wdev->netdev) |
| 5509 | dev_hold(wdev->netdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5510 | } else { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5511 | out_free: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5512 | rdev->scan_req = NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5513 | kfree(request); |
| 5514 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 5515 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5516 | unlock: |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5517 | return err; |
| 5518 | } |
| 5519 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5520 | static int nl80211_start_sched_scan(struct sk_buff *skb, |
| 5521 | struct genl_info *info) |
| 5522 | { |
| 5523 | struct cfg80211_sched_scan_request *request; |
| 5524 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5525 | struct net_device *dev = info->user_ptr[1]; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5526 | struct nlattr *attr; |
| 5527 | struct wiphy *wiphy; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5528 | 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] | 5529 | u32 interval; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5530 | enum ieee80211_band band; |
| 5531 | size_t ie_len; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5532 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 5533 | s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5534 | |
| 5535 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 5536 | !rdev->ops->sched_scan_start) |
| 5537 | return -EOPNOTSUPP; |
| 5538 | |
| 5539 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5540 | return -EINVAL; |
| 5541 | |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 5542 | if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
| 5543 | return -EINVAL; |
| 5544 | |
| 5545 | interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); |
| 5546 | if (interval == 0) |
| 5547 | return -EINVAL; |
| 5548 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5549 | wiphy = &rdev->wiphy; |
| 5550 | |
| 5551 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 5552 | n_channels = validate_scan_freqs( |
| 5553 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
| 5554 | if (!n_channels) |
| 5555 | return -EINVAL; |
| 5556 | } else { |
Ilan Peer | bdfbec2 | 2014-01-09 11:37:23 +0200 | [diff] [blame] | 5557 | n_channels = ieee80211_get_num_supported_channels(wiphy); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5558 | } |
| 5559 | |
| 5560 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 5561 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 5562 | tmp) |
| 5563 | n_ssids++; |
| 5564 | |
Luciano Coelho | 93b6aa6 | 2011-07-13 14:57:28 +0300 | [diff] [blame] | 5565 | if (n_ssids > wiphy->max_sched_scan_ssids) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5566 | return -EINVAL; |
| 5567 | |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 5568 | /* |
| 5569 | * First, count the number of 'real' matchsets. Due to an issue with |
| 5570 | * the old implementation, matchsets containing only the RSSI attribute |
| 5571 | * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default' |
| 5572 | * RSSI for all matchsets, rather than their own matchset for reporting |
| 5573 | * all APs with a strong RSSI. This is needed to be compatible with |
| 5574 | * older userspace that treated a matchset with only the RSSI as the |
| 5575 | * global RSSI for all other matchsets - if there are other matchsets. |
| 5576 | */ |
| 5577 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5578 | nla_for_each_nested(attr, |
| 5579 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 5580 | tmp) { |
| 5581 | struct nlattr *rssi; |
| 5582 | |
| 5583 | err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
| 5584 | nla_data(attr), nla_len(attr), |
| 5585 | nl80211_match_policy); |
| 5586 | if (err) |
| 5587 | return err; |
| 5588 | /* add other standalone attributes here */ |
| 5589 | if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]) { |
| 5590 | n_match_sets++; |
| 5591 | continue; |
| 5592 | } |
| 5593 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; |
| 5594 | if (rssi) |
| 5595 | default_match_rssi = nla_get_s32(rssi); |
| 5596 | } |
| 5597 | } |
| 5598 | |
| 5599 | /* However, if there's no other matchset, add the RSSI one */ |
| 5600 | if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF) |
| 5601 | n_match_sets = 1; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5602 | |
| 5603 | if (n_match_sets > wiphy->max_match_sets) |
| 5604 | return -EINVAL; |
| 5605 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5606 | if (info->attrs[NL80211_ATTR_IE]) |
| 5607 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5608 | else |
| 5609 | ie_len = 0; |
| 5610 | |
Luciano Coelho | 5a865ba | 2011-07-13 14:57:29 +0300 | [diff] [blame] | 5611 | if (ie_len > wiphy->max_sched_scan_ie_len) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5612 | return -EINVAL; |
| 5613 | |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 5614 | if (rdev->sched_scan_req) { |
| 5615 | err = -EINPROGRESS; |
| 5616 | goto out; |
| 5617 | } |
| 5618 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5619 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 5620 | + sizeof(*request->ssids) * n_ssids |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5621 | + sizeof(*request->match_sets) * n_match_sets |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 5622 | + sizeof(*request->channels) * n_channels |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5623 | + ie_len, GFP_KERNEL); |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 5624 | if (!request) { |
| 5625 | err = -ENOMEM; |
| 5626 | goto out; |
| 5627 | } |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5628 | |
| 5629 | if (n_ssids) |
| 5630 | request->ssids = (void *)&request->channels[n_channels]; |
| 5631 | request->n_ssids = n_ssids; |
| 5632 | if (ie_len) { |
| 5633 | if (request->ssids) |
| 5634 | request->ie = (void *)(request->ssids + n_ssids); |
| 5635 | else |
| 5636 | request->ie = (void *)(request->channels + n_channels); |
| 5637 | } |
| 5638 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5639 | if (n_match_sets) { |
| 5640 | if (request->ie) |
| 5641 | request->match_sets = (void *)(request->ie + ie_len); |
| 5642 | else if (request->ssids) |
| 5643 | request->match_sets = |
| 5644 | (void *)(request->ssids + n_ssids); |
| 5645 | else |
| 5646 | request->match_sets = |
| 5647 | (void *)(request->channels + n_channels); |
| 5648 | } |
| 5649 | request->n_match_sets = n_match_sets; |
| 5650 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5651 | i = 0; |
| 5652 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 5653 | /* user specified, bail out if channel not found */ |
| 5654 | nla_for_each_nested(attr, |
| 5655 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], |
| 5656 | tmp) { |
| 5657 | struct ieee80211_channel *chan; |
| 5658 | |
| 5659 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 5660 | |
| 5661 | if (!chan) { |
| 5662 | err = -EINVAL; |
| 5663 | goto out_free; |
| 5664 | } |
| 5665 | |
| 5666 | /* ignore disabled channels */ |
| 5667 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5668 | continue; |
| 5669 | |
| 5670 | request->channels[i] = chan; |
| 5671 | i++; |
| 5672 | } |
| 5673 | } else { |
| 5674 | /* all channels */ |
| 5675 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 5676 | int j; |
| 5677 | if (!wiphy->bands[band]) |
| 5678 | continue; |
| 5679 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
| 5680 | struct ieee80211_channel *chan; |
| 5681 | |
| 5682 | chan = &wiphy->bands[band]->channels[j]; |
| 5683 | |
| 5684 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5685 | continue; |
| 5686 | |
| 5687 | request->channels[i] = chan; |
| 5688 | i++; |
| 5689 | } |
| 5690 | } |
| 5691 | } |
| 5692 | |
| 5693 | if (!i) { |
| 5694 | err = -EINVAL; |
| 5695 | goto out_free; |
| 5696 | } |
| 5697 | |
| 5698 | request->n_channels = i; |
| 5699 | |
| 5700 | i = 0; |
| 5701 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 5702 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 5703 | tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5704 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5705 | err = -EINVAL; |
| 5706 | goto out_free; |
| 5707 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5708 | request->ssids[i].ssid_len = nla_len(attr); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5709 | memcpy(request->ssids[i].ssid, nla_data(attr), |
| 5710 | nla_len(attr)); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5711 | i++; |
| 5712 | } |
| 5713 | } |
| 5714 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5715 | i = 0; |
| 5716 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
| 5717 | nla_for_each_nested(attr, |
| 5718 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
| 5719 | tmp) { |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 5720 | struct nlattr *ssid, *rssi; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5721 | |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 5722 | err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
| 5723 | nla_data(attr), nla_len(attr), |
| 5724 | nl80211_match_policy); |
| 5725 | if (err) |
| 5726 | goto out_free; |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 5727 | ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5728 | if (ssid) { |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 5729 | if (WARN_ON(i >= n_match_sets)) { |
| 5730 | /* this indicates a programming error, |
| 5731 | * the loop above should have verified |
| 5732 | * things properly |
| 5733 | */ |
| 5734 | err = -EINVAL; |
| 5735 | goto out_free; |
| 5736 | } |
| 5737 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5738 | if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) { |
| 5739 | err = -EINVAL; |
| 5740 | goto out_free; |
| 5741 | } |
| 5742 | memcpy(request->match_sets[i].ssid.ssid, |
| 5743 | nla_data(ssid), nla_len(ssid)); |
| 5744 | request->match_sets[i].ssid.ssid_len = |
| 5745 | nla_len(ssid); |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 5746 | /* special attribute - old implemenation w/a */ |
| 5747 | request->match_sets[i].rssi_thold = |
| 5748 | default_match_rssi; |
| 5749 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; |
| 5750 | if (rssi) |
| 5751 | request->match_sets[i].rssi_thold = |
| 5752 | nla_get_s32(rssi); |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5753 | } |
| 5754 | i++; |
| 5755 | } |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 5756 | |
| 5757 | /* there was no other matchset, so the RSSI one is alone */ |
| 5758 | if (i == 0) |
| 5759 | request->match_sets[0].rssi_thold = default_match_rssi; |
| 5760 | |
| 5761 | request->min_rssi_thold = INT_MAX; |
| 5762 | for (i = 0; i < n_match_sets; i++) |
| 5763 | request->min_rssi_thold = |
| 5764 | min(request->match_sets[i].rssi_thold, |
| 5765 | request->min_rssi_thold); |
| 5766 | } else { |
| 5767 | request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5768 | } |
| 5769 | |
Johannes Berg | 9900e48 | 2014-02-04 21:01:25 +0100 | [diff] [blame] | 5770 | if (ie_len) { |
| 5771 | request->ie_len = ie_len; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5772 | memcpy((void *)request->ie, |
| 5773 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 5774 | request->ie_len); |
| 5775 | } |
| 5776 | |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5777 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5778 | request->flags = nla_get_u32( |
| 5779 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); |
Johannes Berg | 00c3a6e | 2013-10-26 17:14:38 +0200 | [diff] [blame] | 5780 | if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 5781 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) { |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5782 | err = -EOPNOTSUPP; |
| 5783 | goto out_free; |
| 5784 | } |
| 5785 | } |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5786 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5787 | request->dev = dev; |
| 5788 | request->wiphy = &rdev->wiphy; |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 5789 | request->interval = interval; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 5790 | request->scan_start = jiffies; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5791 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5792 | err = rdev_sched_scan_start(rdev, dev, request); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5793 | if (!err) { |
| 5794 | rdev->sched_scan_req = request; |
| 5795 | nl80211_send_sched_scan(rdev, dev, |
| 5796 | NL80211_CMD_START_SCHED_SCAN); |
| 5797 | goto out; |
| 5798 | } |
| 5799 | |
| 5800 | out_free: |
| 5801 | kfree(request); |
| 5802 | out: |
| 5803 | return err; |
| 5804 | } |
| 5805 | |
| 5806 | static int nl80211_stop_sched_scan(struct sk_buff *skb, |
| 5807 | struct genl_info *info) |
| 5808 | { |
| 5809 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5810 | |
| 5811 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 5812 | !rdev->ops->sched_scan_stop) |
| 5813 | return -EOPNOTSUPP; |
| 5814 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5815 | return __cfg80211_stop_sched_scan(rdev, false); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5816 | } |
| 5817 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5818 | static int nl80211_start_radar_detection(struct sk_buff *skb, |
| 5819 | struct genl_info *info) |
| 5820 | { |
| 5821 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5822 | struct net_device *dev = info->user_ptr[1]; |
| 5823 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 5824 | struct cfg80211_chan_def chandef; |
Luis R. Rodriguez | 55f7435 | 2013-11-25 20:56:10 +0100 | [diff] [blame] | 5825 | enum nl80211_dfs_regions dfs_region; |
Janusz Dziedzic | 31559f3 | 2014-02-21 19:46:13 +0100 | [diff] [blame] | 5826 | unsigned int cac_time_ms; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5827 | int err; |
| 5828 | |
Luis R. Rodriguez | 55f7435 | 2013-11-25 20:56:10 +0100 | [diff] [blame] | 5829 | dfs_region = reg_get_dfs_region(wdev->wiphy); |
| 5830 | if (dfs_region == NL80211_DFS_UNSET) |
| 5831 | return -EINVAL; |
| 5832 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5833 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 5834 | if (err) |
| 5835 | return err; |
| 5836 | |
Simon Wunderlich | ff311bc | 2013-09-03 19:43:18 +0200 | [diff] [blame] | 5837 | if (netif_carrier_ok(dev)) |
| 5838 | return -EBUSY; |
| 5839 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5840 | if (wdev->cac_started) |
| 5841 | return -EBUSY; |
| 5842 | |
Luciano Coelho | 2beb6dab | 2014-02-18 11:40:36 +0200 | [diff] [blame] | 5843 | err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, |
Luciano Coelho | 00ec75f | 2014-05-15 13:05:39 +0300 | [diff] [blame] | 5844 | wdev->iftype); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5845 | if (err < 0) |
| 5846 | return err; |
| 5847 | |
| 5848 | if (err == 0) |
| 5849 | return -EINVAL; |
| 5850 | |
Janusz Dziedzic | fe7c3a1 | 2013-11-05 14:48:48 +0100 | [diff] [blame] | 5851 | if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef)) |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5852 | return -EINVAL; |
| 5853 | |
| 5854 | if (!rdev->ops->start_radar_detection) |
| 5855 | return -EOPNOTSUPP; |
| 5856 | |
Janusz Dziedzic | 31559f3 | 2014-02-21 19:46:13 +0100 | [diff] [blame] | 5857 | cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef); |
| 5858 | if (WARN_ON(!cac_time_ms)) |
| 5859 | cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS; |
| 5860 | |
| 5861 | err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef, |
| 5862 | cac_time_ms); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5863 | if (!err) { |
Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 5864 | wdev->chandef = chandef; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5865 | wdev->cac_started = true; |
| 5866 | wdev->cac_start_time = jiffies; |
Janusz Dziedzic | 31559f3 | 2014-02-21 19:46:13 +0100 | [diff] [blame] | 5867 | wdev->cac_time_ms = cac_time_ms; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5868 | } |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5869 | return err; |
| 5870 | } |
| 5871 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5872 | static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info) |
| 5873 | { |
| 5874 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5875 | struct net_device *dev = info->user_ptr[1]; |
| 5876 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 5877 | struct cfg80211_csa_settings params; |
| 5878 | /* csa_attrs is defined static to avoid waste of stack size - this |
| 5879 | * function is called under RTNL lock, so this should not be a problem. |
| 5880 | */ |
| 5881 | static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1]; |
| 5882 | u8 radar_detect_width = 0; |
| 5883 | int err; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5884 | bool need_new_beacon = false; |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 5885 | int len, i; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5886 | |
| 5887 | if (!rdev->ops->channel_switch || |
| 5888 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)) |
| 5889 | return -EOPNOTSUPP; |
| 5890 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5891 | switch (dev->ieee80211_ptr->iftype) { |
| 5892 | case NL80211_IFTYPE_AP: |
| 5893 | case NL80211_IFTYPE_P2P_GO: |
| 5894 | need_new_beacon = true; |
| 5895 | |
| 5896 | /* useless if AP is not running */ |
| 5897 | if (!wdev->beacon_interval) |
Johannes Berg | 1ff79df | 2014-01-22 10:05:27 +0100 | [diff] [blame] | 5898 | return -ENOTCONN; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5899 | break; |
| 5900 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | 1ff79df | 2014-01-22 10:05:27 +0100 | [diff] [blame] | 5901 | if (!wdev->ssid_len) |
| 5902 | return -ENOTCONN; |
| 5903 | break; |
Chun-Yeow Yeoh | c6da674 | 2013-10-14 19:08:28 -0700 | [diff] [blame] | 5904 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 1ff79df | 2014-01-22 10:05:27 +0100 | [diff] [blame] | 5905 | if (!wdev->mesh_id_len) |
| 5906 | return -ENOTCONN; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5907 | break; |
| 5908 | default: |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5909 | return -EOPNOTSUPP; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5910 | } |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5911 | |
| 5912 | memset(¶ms, 0, sizeof(params)); |
| 5913 | |
| 5914 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 5915 | !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]) |
| 5916 | return -EINVAL; |
| 5917 | |
| 5918 | /* only important for AP, IBSS and mesh create IEs internally */ |
Andrei Otcheretianski | d0a361a | 2013-10-17 10:52:17 +0200 | [diff] [blame] | 5919 | if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES]) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5920 | return -EINVAL; |
| 5921 | |
| 5922 | params.count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]); |
| 5923 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5924 | if (!need_new_beacon) |
| 5925 | goto skip_beacons; |
| 5926 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5927 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon_after); |
| 5928 | if (err) |
| 5929 | return err; |
| 5930 | |
| 5931 | err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX, |
| 5932 | info->attrs[NL80211_ATTR_CSA_IES], |
| 5933 | nl80211_policy); |
| 5934 | if (err) |
| 5935 | return err; |
| 5936 | |
| 5937 | err = nl80211_parse_beacon(csa_attrs, ¶ms.beacon_csa); |
| 5938 | if (err) |
| 5939 | return err; |
| 5940 | |
| 5941 | if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]) |
| 5942 | return -EINVAL; |
| 5943 | |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 5944 | len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); |
| 5945 | if (!len || (len % sizeof(u16))) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5946 | return -EINVAL; |
| 5947 | |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 5948 | params.n_counter_offsets_beacon = len / sizeof(u16); |
| 5949 | if (rdev->wiphy.max_num_csa_counters && |
| 5950 | (params.n_counter_offsets_beacon > |
| 5951 | rdev->wiphy.max_num_csa_counters)) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5952 | return -EINVAL; |
| 5953 | |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 5954 | params.counter_offsets_beacon = |
| 5955 | nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); |
| 5956 | |
| 5957 | /* sanity checks - counters should fit and be the same */ |
| 5958 | for (i = 0; i < params.n_counter_offsets_beacon; i++) { |
| 5959 | u16 offset = params.counter_offsets_beacon[i]; |
| 5960 | |
| 5961 | if (offset >= params.beacon_csa.tail_len) |
| 5962 | return -EINVAL; |
| 5963 | |
| 5964 | if (params.beacon_csa.tail[offset] != params.count) |
| 5965 | return -EINVAL; |
| 5966 | } |
| 5967 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5968 | if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) { |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 5969 | len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); |
| 5970 | if (!len || (len % sizeof(u16))) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5971 | return -EINVAL; |
| 5972 | |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 5973 | params.n_counter_offsets_presp = len / sizeof(u16); |
| 5974 | if (rdev->wiphy.max_num_csa_counters && |
| 5975 | (params.n_counter_offsets_beacon > |
| 5976 | rdev->wiphy.max_num_csa_counters)) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5977 | return -EINVAL; |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 5978 | |
| 5979 | params.counter_offsets_presp = |
| 5980 | nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); |
| 5981 | |
| 5982 | /* sanity checks - counters should fit and be the same */ |
| 5983 | for (i = 0; i < params.n_counter_offsets_presp; i++) { |
| 5984 | u16 offset = params.counter_offsets_presp[i]; |
| 5985 | |
| 5986 | if (offset >= params.beacon_csa.probe_resp_len) |
| 5987 | return -EINVAL; |
| 5988 | |
| 5989 | if (params.beacon_csa.probe_resp[offset] != |
| 5990 | params.count) |
| 5991 | return -EINVAL; |
| 5992 | } |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5993 | } |
| 5994 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5995 | skip_beacons: |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5996 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
| 5997 | if (err) |
| 5998 | return err; |
| 5999 | |
Ilan Peer | 174e0cd | 2014-02-23 09:13:01 +0200 | [diff] [blame] | 6000 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, ¶ms.chandef, |
| 6001 | wdev->iftype)) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6002 | return -EINVAL; |
| 6003 | |
Luciano Coelho | 2beb6dab | 2014-02-18 11:40:36 +0200 | [diff] [blame] | 6004 | err = cfg80211_chandef_dfs_required(wdev->wiphy, |
| 6005 | ¶ms.chandef, |
| 6006 | wdev->iftype); |
| 6007 | if (err < 0) |
| 6008 | return err; |
| 6009 | |
| 6010 | if (err > 0) { |
| 6011 | radar_detect_width = BIT(params.chandef.width); |
| 6012 | params.radar_required = true; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6013 | } |
| 6014 | |
Luciano Coelho | 73de86a | 2014-02-13 11:31:59 +0200 | [diff] [blame] | 6015 | /* TODO: I left this here for now. With channel switch, the |
| 6016 | * verification is a bit more complicated, because we only do |
| 6017 | * it later when the channel switch really happens. |
| 6018 | */ |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6019 | err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype, |
| 6020 | params.chandef.chan, |
| 6021 | CHAN_MODE_SHARED, |
| 6022 | radar_detect_width); |
| 6023 | if (err) |
| 6024 | return err; |
| 6025 | |
| 6026 | if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX]) |
| 6027 | params.block_tx = true; |
| 6028 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 6029 | wdev_lock(wdev); |
| 6030 | err = rdev_channel_switch(rdev, dev, ¶ms); |
| 6031 | wdev_unlock(wdev); |
| 6032 | |
| 6033 | return err; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6034 | } |
| 6035 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 6036 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
| 6037 | u32 seq, int flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6038 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6039 | struct wireless_dev *wdev, |
| 6040 | struct cfg80211_internal_bss *intbss) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6041 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6042 | struct cfg80211_bss *res = &intbss->pub; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 6043 | const struct cfg80211_bss_ies *ies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6044 | void *hdr; |
| 6045 | struct nlattr *bss; |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 6046 | bool tsf = false; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6047 | |
| 6048 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6049 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6050 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6051 | NL80211_CMD_NEW_SCAN_RESULTS); |
| 6052 | if (!hdr) |
| 6053 | return -1; |
| 6054 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 6055 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
| 6056 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6057 | if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation)) |
| 6058 | goto nla_put_failure; |
| 6059 | if (wdev->netdev && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6060 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex)) |
| 6061 | goto nla_put_failure; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6062 | if (nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 6063 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6064 | |
| 6065 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); |
| 6066 | if (!bss) |
| 6067 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6068 | if ((!is_zero_ether_addr(res->bssid) && |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 6069 | nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6070 | goto nla_put_failure; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 6071 | |
| 6072 | rcu_read_lock(); |
| 6073 | ies = rcu_dereference(res->ies); |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 6074 | if (ies) { |
| 6075 | if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf)) |
| 6076 | goto fail_unlock_rcu; |
| 6077 | tsf = true; |
| 6078 | if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS, |
| 6079 | ies->len, ies->data)) |
| 6080 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 6081 | } |
| 6082 | ies = rcu_dereference(res->beacon_ies); |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 6083 | if (ies) { |
| 6084 | if (!tsf && nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf)) |
| 6085 | goto fail_unlock_rcu; |
| 6086 | if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES, |
| 6087 | ies->len, ies->data)) |
| 6088 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 6089 | } |
| 6090 | rcu_read_unlock(); |
| 6091 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6092 | if (res->beacon_interval && |
| 6093 | nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval)) |
| 6094 | goto nla_put_failure; |
| 6095 | if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) || |
| 6096 | nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) || |
Simon Wunderlich | dcd6eac | 2013-07-08 16:55:49 +0200 | [diff] [blame] | 6097 | nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6098 | nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO, |
| 6099 | jiffies_to_msecs(jiffies - intbss->ts))) |
| 6100 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6101 | |
Johannes Berg | 77965c9 | 2009-02-18 18:45:06 +0100 | [diff] [blame] | 6102 | switch (rdev->wiphy.signal_type) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6103 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6104 | if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal)) |
| 6105 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6106 | break; |
| 6107 | case CFG80211_SIGNAL_TYPE_UNSPEC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6108 | if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal)) |
| 6109 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6110 | break; |
| 6111 | default: |
| 6112 | break; |
| 6113 | } |
| 6114 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6115 | switch (wdev->iftype) { |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6116 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6117 | case NL80211_IFTYPE_STATION: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6118 | if (intbss == wdev->current_bss && |
| 6119 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 6120 | NL80211_BSS_STATUS_ASSOCIATED)) |
| 6121 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6122 | break; |
| 6123 | case NL80211_IFTYPE_ADHOC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6124 | if (intbss == wdev->current_bss && |
| 6125 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 6126 | NL80211_BSS_STATUS_IBSS_JOINED)) |
| 6127 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6128 | break; |
| 6129 | default: |
| 6130 | break; |
| 6131 | } |
| 6132 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6133 | nla_nest_end(msg, bss); |
| 6134 | |
| 6135 | return genlmsg_end(msg, hdr); |
| 6136 | |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 6137 | fail_unlock_rcu: |
| 6138 | rcu_read_unlock(); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6139 | nla_put_failure: |
| 6140 | genlmsg_cancel(msg, hdr); |
| 6141 | return -EMSGSIZE; |
| 6142 | } |
| 6143 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6144 | 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] | 6145 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6146 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6147 | struct cfg80211_internal_bss *scan; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6148 | struct wireless_dev *wdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6149 | int start = cb->args[2], idx = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6150 | int err; |
| 6151 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6152 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 6153 | if (err) |
| 6154 | return err; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6155 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6156 | wdev_lock(wdev); |
| 6157 | spin_lock_bh(&rdev->bss_lock); |
| 6158 | cfg80211_bss_expire(rdev); |
| 6159 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 6160 | cb->seq = rdev->bss_generation; |
| 6161 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6162 | list_for_each_entry(scan, &rdev->bss_list, list) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6163 | if (++idx <= start) |
| 6164 | continue; |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 6165 | if (nl80211_send_bss(skb, cb, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6166 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6167 | rdev, wdev, scan) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6168 | idx--; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 6169 | break; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6170 | } |
| 6171 | } |
| 6172 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6173 | spin_unlock_bh(&rdev->bss_lock); |
| 6174 | wdev_unlock(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6175 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6176 | cb->args[2] = idx; |
| 6177 | nl80211_finish_wdev_dump(rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6178 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 6179 | return skb->len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6180 | } |
| 6181 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6182 | 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] | 6183 | int flags, struct net_device *dev, |
| 6184 | struct survey_info *survey) |
| 6185 | { |
| 6186 | void *hdr; |
| 6187 | struct nlattr *infoattr; |
| 6188 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6189 | hdr = nl80211hdr_put(msg, portid, seq, flags, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6190 | NL80211_CMD_NEW_SURVEY_RESULTS); |
| 6191 | if (!hdr) |
| 6192 | return -ENOMEM; |
| 6193 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6194 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
| 6195 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6196 | |
| 6197 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); |
| 6198 | if (!infoattr) |
| 6199 | goto nla_put_failure; |
| 6200 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6201 | if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY, |
| 6202 | survey->channel->center_freq)) |
| 6203 | goto nla_put_failure; |
| 6204 | |
| 6205 | if ((survey->filled & SURVEY_INFO_NOISE_DBM) && |
| 6206 | nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise)) |
| 6207 | goto nla_put_failure; |
| 6208 | if ((survey->filled & SURVEY_INFO_IN_USE) && |
| 6209 | nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE)) |
| 6210 | goto nla_put_failure; |
| 6211 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) && |
| 6212 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME, |
| 6213 | survey->channel_time)) |
| 6214 | goto nla_put_failure; |
| 6215 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) && |
| 6216 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY, |
| 6217 | survey->channel_time_busy)) |
| 6218 | goto nla_put_failure; |
| 6219 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) && |
| 6220 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY, |
| 6221 | survey->channel_time_ext_busy)) |
| 6222 | goto nla_put_failure; |
| 6223 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) && |
| 6224 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX, |
| 6225 | survey->channel_time_rx)) |
| 6226 | goto nla_put_failure; |
| 6227 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) && |
| 6228 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX, |
| 6229 | survey->channel_time_tx)) |
| 6230 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6231 | |
| 6232 | nla_nest_end(msg, infoattr); |
| 6233 | |
| 6234 | return genlmsg_end(msg, hdr); |
| 6235 | |
| 6236 | nla_put_failure: |
| 6237 | genlmsg_cancel(msg, hdr); |
| 6238 | return -EMSGSIZE; |
| 6239 | } |
| 6240 | |
| 6241 | static int nl80211_dump_survey(struct sk_buff *skb, |
| 6242 | struct netlink_callback *cb) |
| 6243 | { |
| 6244 | struct survey_info survey; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 6245 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6246 | struct wireless_dev *wdev; |
| 6247 | int survey_idx = cb->args[2]; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6248 | int res; |
| 6249 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 6250 | res = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 6251 | if (res) |
| 6252 | return res; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6253 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6254 | if (!wdev->netdev) { |
| 6255 | res = -EINVAL; |
| 6256 | goto out_err; |
| 6257 | } |
| 6258 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 6259 | if (!rdev->ops->dump_survey) { |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6260 | res = -EOPNOTSUPP; |
| 6261 | goto out_err; |
| 6262 | } |
| 6263 | |
| 6264 | while (1) { |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 6265 | struct ieee80211_channel *chan; |
| 6266 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 6267 | res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6268 | if (res == -ENOENT) |
| 6269 | break; |
| 6270 | if (res) |
| 6271 | goto out_err; |
| 6272 | |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 6273 | /* Survey without a channel doesn't make sense */ |
| 6274 | if (!survey.channel) { |
| 6275 | res = -EINVAL; |
| 6276 | goto out; |
| 6277 | } |
| 6278 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 6279 | chan = ieee80211_get_channel(&rdev->wiphy, |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 6280 | survey.channel->center_freq); |
| 6281 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) { |
| 6282 | survey_idx++; |
| 6283 | continue; |
| 6284 | } |
| 6285 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6286 | if (nl80211_send_survey(skb, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6287 | NETLINK_CB(cb->skb).portid, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6288 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6289 | wdev->netdev, &survey) < 0) |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6290 | goto out; |
| 6291 | survey_idx++; |
| 6292 | } |
| 6293 | |
| 6294 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6295 | cb->args[2] = survey_idx; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6296 | res = skb->len; |
| 6297 | out_err: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 6298 | nl80211_finish_wdev_dump(rdev); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6299 | return res; |
| 6300 | } |
| 6301 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6302 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
| 6303 | { |
| 6304 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | |
| 6305 | NL80211_WPA_VERSION_2)); |
| 6306 | } |
| 6307 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6308 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
| 6309 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6310 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6311 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6312 | struct ieee80211_channel *chan; |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 6313 | const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL; |
| 6314 | int err, ssid_len, ie_len = 0, sae_data_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6315 | enum nl80211_auth_type auth_type; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6316 | struct key_parse key; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6317 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6318 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6319 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6320 | return -EINVAL; |
| 6321 | |
| 6322 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6323 | return -EINVAL; |
| 6324 | |
Jouni Malinen | 1778092 | 2009-03-27 20:52:47 +0200 | [diff] [blame] | 6325 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
| 6326 | return -EINVAL; |
| 6327 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6328 | if (!info->attrs[NL80211_ATTR_SSID]) |
| 6329 | return -EINVAL; |
| 6330 | |
| 6331 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 6332 | return -EINVAL; |
| 6333 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6334 | err = nl80211_parse_key(info, &key); |
| 6335 | if (err) |
| 6336 | return err; |
| 6337 | |
| 6338 | if (key.idx >= 0) { |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 6339 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
| 6340 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6341 | if (!key.p.key || !key.p.key_len) |
| 6342 | return -EINVAL; |
| 6343 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || |
| 6344 | key.p.key_len != WLAN_KEY_LEN_WEP40) && |
| 6345 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || |
| 6346 | key.p.key_len != WLAN_KEY_LEN_WEP104)) |
| 6347 | return -EINVAL; |
| 6348 | if (key.idx > 4) |
| 6349 | return -EINVAL; |
| 6350 | } else { |
| 6351 | key.p.key_len = 0; |
| 6352 | key.p.key = NULL; |
| 6353 | } |
| 6354 | |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 6355 | if (key.idx >= 0) { |
| 6356 | int i; |
| 6357 | bool ok = false; |
| 6358 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { |
| 6359 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { |
| 6360 | ok = true; |
| 6361 | break; |
| 6362 | } |
| 6363 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6364 | if (!ok) |
| 6365 | return -EINVAL; |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 6366 | } |
| 6367 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6368 | if (!rdev->ops->auth) |
| 6369 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6370 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6371 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6372 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6373 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6374 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6375 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 6376 | chan = nl80211_get_valid_chan(&rdev->wiphy, |
| 6377 | info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 6378 | if (!chan) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6379 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6380 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6381 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 6382 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 6383 | |
| 6384 | if (info->attrs[NL80211_ATTR_IE]) { |
| 6385 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6386 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 6387 | } |
| 6388 | |
| 6389 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 6390 | if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6391 | return -EINVAL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6392 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 6393 | if (auth_type == NL80211_AUTHTYPE_SAE && |
| 6394 | !info->attrs[NL80211_ATTR_SAE_DATA]) |
| 6395 | return -EINVAL; |
| 6396 | |
| 6397 | if (info->attrs[NL80211_ATTR_SAE_DATA]) { |
| 6398 | if (auth_type != NL80211_AUTHTYPE_SAE) |
| 6399 | return -EINVAL; |
| 6400 | sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]); |
| 6401 | sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]); |
| 6402 | /* need to include at least Auth Transaction and Status Code */ |
| 6403 | if (sae_data_len < 4) |
| 6404 | return -EINVAL; |
| 6405 | } |
| 6406 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6407 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 6408 | |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 6409 | /* |
| 6410 | * Since we no longer track auth state, ignore |
| 6411 | * requests to only change local state. |
| 6412 | */ |
| 6413 | if (local_state_change) |
| 6414 | return 0; |
| 6415 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6416 | wdev_lock(dev->ieee80211_ptr); |
| 6417 | err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, |
| 6418 | ssid, ssid_len, ie, ie_len, |
| 6419 | key.p.key, key.p.key_len, key.idx, |
| 6420 | sae_data, sae_data_len); |
| 6421 | wdev_unlock(dev->ieee80211_ptr); |
| 6422 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6423 | } |
| 6424 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 6425 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 6426 | struct genl_info *info, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 6427 | struct cfg80211_crypto_settings *settings, |
| 6428 | int cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6429 | { |
Johannes Berg | c0b2bbd | 2009-07-25 16:54:36 +0200 | [diff] [blame] | 6430 | memset(settings, 0, sizeof(*settings)); |
| 6431 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6432 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
| 6433 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 6434 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
| 6435 | u16 proto; |
| 6436 | proto = nla_get_u16( |
| 6437 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); |
| 6438 | settings->control_port_ethertype = cpu_to_be16(proto); |
| 6439 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 6440 | proto != ETH_P_PAE) |
| 6441 | return -EINVAL; |
| 6442 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) |
| 6443 | settings->control_port_no_encrypt = true; |
| 6444 | } else |
| 6445 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); |
| 6446 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6447 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
| 6448 | void *data; |
| 6449 | int len, i; |
| 6450 | |
| 6451 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 6452 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 6453 | settings->n_ciphers_pairwise = len / sizeof(u32); |
| 6454 | |
| 6455 | if (len % sizeof(u32)) |
| 6456 | return -EINVAL; |
| 6457 | |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 6458 | if (settings->n_ciphers_pairwise > cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6459 | return -EINVAL; |
| 6460 | |
| 6461 | memcpy(settings->ciphers_pairwise, data, len); |
| 6462 | |
| 6463 | for (i = 0; i < settings->n_ciphers_pairwise; i++) |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 6464 | if (!cfg80211_supported_cipher_suite( |
| 6465 | &rdev->wiphy, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6466 | settings->ciphers_pairwise[i])) |
| 6467 | return -EINVAL; |
| 6468 | } |
| 6469 | |
| 6470 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { |
| 6471 | settings->cipher_group = |
| 6472 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 6473 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
| 6474 | settings->cipher_group)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6475 | return -EINVAL; |
| 6476 | } |
| 6477 | |
| 6478 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { |
| 6479 | settings->wpa_versions = |
| 6480 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); |
| 6481 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) |
| 6482 | return -EINVAL; |
| 6483 | } |
| 6484 | |
| 6485 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { |
| 6486 | void *data; |
Jouni Malinen | 6d30240 | 2011-09-21 18:11:33 +0300 | [diff] [blame] | 6487 | int len; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6488 | |
| 6489 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 6490 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 6491 | settings->n_akm_suites = len / sizeof(u32); |
| 6492 | |
| 6493 | if (len % sizeof(u32)) |
| 6494 | return -EINVAL; |
| 6495 | |
Jouni Malinen | 1b9ca02 | 2011-09-21 16:13:07 +0300 | [diff] [blame] | 6496 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) |
| 6497 | return -EINVAL; |
| 6498 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6499 | memcpy(settings->akm_suites, data, len); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6500 | } |
| 6501 | |
| 6502 | return 0; |
| 6503 | } |
| 6504 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6505 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
| 6506 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6507 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6508 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 6509 | struct ieee80211_channel *chan; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6510 | struct cfg80211_assoc_request req = {}; |
| 6511 | const u8 *bssid, *ssid; |
| 6512 | int err, ssid_len = 0; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6513 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6514 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6515 | return -EINVAL; |
| 6516 | |
| 6517 | if (!info->attrs[NL80211_ATTR_MAC] || |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6518 | !info->attrs[NL80211_ATTR_SSID] || |
| 6519 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6520 | return -EINVAL; |
| 6521 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6522 | if (!rdev->ops->assoc) |
| 6523 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6524 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6525 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6526 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6527 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6528 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6529 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6530 | |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 6531 | chan = nl80211_get_valid_chan(&rdev->wiphy, |
| 6532 | info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 6533 | if (!chan) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6534 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6535 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6536 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 6537 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6538 | |
| 6539 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6540 | req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6541 | req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6542 | } |
| 6543 | |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 6544 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 6545 | enum nl80211_mfp mfp = |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 6546 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 6547 | if (mfp == NL80211_MFP_REQUIRED) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6548 | req.use_mfp = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6549 | else if (mfp != NL80211_MFP_NO) |
| 6550 | return -EINVAL; |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 6551 | } |
| 6552 | |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 6553 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6554 | req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 6555 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6556 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6557 | req.flags |= ASSOC_REQ_DISABLE_HT; |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6558 | |
| 6559 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6560 | memcpy(&req.ht_capa_mask, |
| 6561 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 6562 | sizeof(req.ht_capa_mask)); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6563 | |
| 6564 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6565 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6566 | return -EINVAL; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6567 | memcpy(&req.ht_capa, |
| 6568 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 6569 | sizeof(req.ht_capa)); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6570 | } |
| 6571 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6572 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6573 | req.flags |= ASSOC_REQ_DISABLE_VHT; |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6574 | |
| 6575 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6576 | memcpy(&req.vht_capa_mask, |
| 6577 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), |
| 6578 | sizeof(req.vht_capa_mask)); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6579 | |
| 6580 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6581 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6582 | return -EINVAL; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6583 | memcpy(&req.vht_capa, |
| 6584 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), |
| 6585 | sizeof(req.vht_capa)); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6586 | } |
| 6587 | |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6588 | err = nl80211_crypto_settings(rdev, info, &req.crypto, 1); |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6589 | if (!err) { |
| 6590 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6591 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, |
| 6592 | ssid, ssid_len, &req); |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6593 | wdev_unlock(dev->ieee80211_ptr); |
| 6594 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6595 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6596 | return err; |
| 6597 | } |
| 6598 | |
| 6599 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) |
| 6600 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6601 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6602 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6603 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6604 | int ie_len = 0, err; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6605 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6606 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6607 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6608 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6609 | return -EINVAL; |
| 6610 | |
| 6611 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6612 | return -EINVAL; |
| 6613 | |
| 6614 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 6615 | return -EINVAL; |
| 6616 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6617 | if (!rdev->ops->deauth) |
| 6618 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6619 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6620 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6621 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6622 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6623 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6624 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6625 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6626 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 6627 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6628 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6629 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 6630 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6631 | |
| 6632 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6633 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6634 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6635 | } |
| 6636 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6637 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 6638 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6639 | wdev_lock(dev->ieee80211_ptr); |
| 6640 | err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, |
| 6641 | local_state_change); |
| 6642 | wdev_unlock(dev->ieee80211_ptr); |
| 6643 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6644 | } |
| 6645 | |
| 6646 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) |
| 6647 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6648 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6649 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6650 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6651 | int ie_len = 0, err; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6652 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6653 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6654 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6655 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6656 | return -EINVAL; |
| 6657 | |
| 6658 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6659 | return -EINVAL; |
| 6660 | |
| 6661 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 6662 | return -EINVAL; |
| 6663 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6664 | if (!rdev->ops->disassoc) |
| 6665 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6666 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6667 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6668 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6669 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6670 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6671 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6672 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6673 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 6674 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6675 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6676 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 6677 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6678 | |
| 6679 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6680 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6681 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6682 | } |
| 6683 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6684 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 6685 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6686 | wdev_lock(dev->ieee80211_ptr); |
| 6687 | err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, |
| 6688 | local_state_change); |
| 6689 | wdev_unlock(dev->ieee80211_ptr); |
| 6690 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6691 | } |
| 6692 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 6693 | static bool |
| 6694 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, |
| 6695 | int mcast_rate[IEEE80211_NUM_BANDS], |
| 6696 | int rateval) |
| 6697 | { |
| 6698 | struct wiphy *wiphy = &rdev->wiphy; |
| 6699 | bool found = false; |
| 6700 | int band, i; |
| 6701 | |
| 6702 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 6703 | struct ieee80211_supported_band *sband; |
| 6704 | |
| 6705 | sband = wiphy->bands[band]; |
| 6706 | if (!sband) |
| 6707 | continue; |
| 6708 | |
| 6709 | for (i = 0; i < sband->n_bitrates; i++) { |
| 6710 | if (sband->bitrates[i].bitrate == rateval) { |
| 6711 | mcast_rate[band] = i + 1; |
| 6712 | found = true; |
| 6713 | break; |
| 6714 | } |
| 6715 | } |
| 6716 | } |
| 6717 | |
| 6718 | return found; |
| 6719 | } |
| 6720 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6721 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
| 6722 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6723 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6724 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6725 | struct cfg80211_ibss_params ibss; |
| 6726 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6727 | struct cfg80211_cached_keys *connkeys = NULL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6728 | int err; |
| 6729 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 6730 | memset(&ibss, 0, sizeof(ibss)); |
| 6731 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6732 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6733 | return -EINVAL; |
| 6734 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6735 | if (!info->attrs[NL80211_ATTR_SSID] || |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6736 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 6737 | return -EINVAL; |
| 6738 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 6739 | ibss.beacon_interval = 100; |
| 6740 | |
| 6741 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 6742 | ibss.beacon_interval = |
| 6743 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 6744 | if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000) |
| 6745 | return -EINVAL; |
| 6746 | } |
| 6747 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6748 | if (!rdev->ops->join_ibss) |
| 6749 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6750 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6751 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 6752 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6753 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 6754 | wiphy = &rdev->wiphy; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6755 | |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 6756 | if (info->attrs[NL80211_ATTR_MAC]) { |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6757 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 6758 | |
| 6759 | if (!is_valid_ether_addr(ibss.bssid)) |
| 6760 | return -EINVAL; |
| 6761 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6762 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 6763 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 6764 | |
| 6765 | if (info->attrs[NL80211_ATTR_IE]) { |
| 6766 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6767 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 6768 | } |
| 6769 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6770 | err = nl80211_parse_chandef(rdev, info, &ibss.chandef); |
| 6771 | if (err) |
| 6772 | return err; |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 6773 | |
Ilan Peer | 174e0cd | 2014-02-23 09:13:01 +0200 | [diff] [blame] | 6774 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef, |
| 6775 | NL80211_IFTYPE_ADHOC)) |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 6776 | return -EINVAL; |
| 6777 | |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 6778 | switch (ibss.chandef.width) { |
Simon Wunderlich | bf37264 | 2013-07-08 16:55:58 +0200 | [diff] [blame] | 6779 | case NL80211_CHAN_WIDTH_5: |
| 6780 | case NL80211_CHAN_WIDTH_10: |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 6781 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 6782 | break; |
| 6783 | case NL80211_CHAN_WIDTH_20: |
| 6784 | case NL80211_CHAN_WIDTH_40: |
| 6785 | if (rdev->wiphy.features & NL80211_FEATURE_HT_IBSS) |
| 6786 | break; |
| 6787 | default: |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 6788 | return -EINVAL; |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 6789 | } |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 6790 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6791 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6792 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6793 | |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 6794 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 6795 | u8 *rates = |
| 6796 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 6797 | int n_rates = |
| 6798 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 6799 | struct ieee80211_supported_band *sband = |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6800 | wiphy->bands[ibss.chandef.chan->band]; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 6801 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 6802 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 6803 | &ibss.basic_rates); |
| 6804 | if (err) |
| 6805 | return err; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 6806 | } |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 6807 | |
Simon Wunderlich | 803768f | 2013-06-28 10:39:58 +0200 | [diff] [blame] | 6808 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 6809 | memcpy(&ibss.ht_capa_mask, |
| 6810 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 6811 | sizeof(ibss.ht_capa_mask)); |
| 6812 | |
| 6813 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
| 6814 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 6815 | return -EINVAL; |
| 6816 | memcpy(&ibss.ht_capa, |
| 6817 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 6818 | sizeof(ibss.ht_capa)); |
| 6819 | } |
| 6820 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 6821 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 6822 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, |
| 6823 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 6824 | return -EINVAL; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 6825 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6826 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6827 | bool no_ht = false; |
| 6828 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6829 | connkeys = nl80211_parse_connkeys(rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6830 | info->attrs[NL80211_ATTR_KEYS], |
| 6831 | &no_ht); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6832 | if (IS_ERR(connkeys)) |
| 6833 | return PTR_ERR(connkeys); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6834 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 6835 | if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) && |
| 6836 | no_ht) { |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6837 | kfree(connkeys); |
| 6838 | return -EINVAL; |
| 6839 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6840 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6841 | |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 6842 | ibss.control_port = |
| 6843 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]); |
| 6844 | |
Simon Wunderlich | 5336fa8 | 2013-10-07 18:41:05 +0200 | [diff] [blame] | 6845 | ibss.userspace_handles_dfs = |
| 6846 | nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]); |
| 6847 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6848 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6849 | if (err) |
| 6850 | kfree(connkeys); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6851 | return err; |
| 6852 | } |
| 6853 | |
| 6854 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) |
| 6855 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6856 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6857 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6858 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6859 | if (!rdev->ops->leave_ibss) |
| 6860 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6861 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6862 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 6863 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6864 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6865 | return cfg80211_leave_ibss(rdev, dev, false); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6866 | } |
| 6867 | |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 6868 | static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info) |
| 6869 | { |
| 6870 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6871 | struct net_device *dev = info->user_ptr[1]; |
| 6872 | int mcast_rate[IEEE80211_NUM_BANDS]; |
| 6873 | u32 nla_rate; |
| 6874 | int err; |
| 6875 | |
| 6876 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
| 6877 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 6878 | return -EOPNOTSUPP; |
| 6879 | |
| 6880 | if (!rdev->ops->set_mcast_rate) |
| 6881 | return -EOPNOTSUPP; |
| 6882 | |
| 6883 | memset(mcast_rate, 0, sizeof(mcast_rate)); |
| 6884 | |
| 6885 | if (!info->attrs[NL80211_ATTR_MCAST_RATE]) |
| 6886 | return -EINVAL; |
| 6887 | |
| 6888 | nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]); |
| 6889 | if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate)) |
| 6890 | return -EINVAL; |
| 6891 | |
| 6892 | err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate); |
| 6893 | |
| 6894 | return err; |
| 6895 | } |
| 6896 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 6897 | static struct sk_buff * |
| 6898 | __cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev, |
| 6899 | int approxlen, u32 portid, u32 seq, |
| 6900 | enum nl80211_commands cmd, |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 6901 | enum nl80211_attrs attr, |
| 6902 | const struct nl80211_vendor_cmd_info *info, |
| 6903 | gfp_t gfp) |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 6904 | { |
| 6905 | struct sk_buff *skb; |
| 6906 | void *hdr; |
| 6907 | struct nlattr *data; |
| 6908 | |
| 6909 | skb = nlmsg_new(approxlen + 100, gfp); |
| 6910 | if (!skb) |
| 6911 | return NULL; |
| 6912 | |
| 6913 | hdr = nl80211hdr_put(skb, portid, seq, 0, cmd); |
| 6914 | if (!hdr) { |
| 6915 | kfree_skb(skb); |
| 6916 | return NULL; |
| 6917 | } |
| 6918 | |
| 6919 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 6920 | goto nla_put_failure; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 6921 | |
| 6922 | if (info) { |
| 6923 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID, |
| 6924 | info->vendor_id)) |
| 6925 | goto nla_put_failure; |
| 6926 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD, |
| 6927 | info->subcmd)) |
| 6928 | goto nla_put_failure; |
| 6929 | } |
| 6930 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 6931 | data = nla_nest_start(skb, attr); |
| 6932 | |
| 6933 | ((void **)skb->cb)[0] = rdev; |
| 6934 | ((void **)skb->cb)[1] = hdr; |
| 6935 | ((void **)skb->cb)[2] = data; |
| 6936 | |
| 6937 | return skb; |
| 6938 | |
| 6939 | nla_put_failure: |
| 6940 | kfree_skb(skb); |
| 6941 | return NULL; |
| 6942 | } |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 6943 | |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 6944 | struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy, |
| 6945 | enum nl80211_commands cmd, |
| 6946 | enum nl80211_attrs attr, |
| 6947 | int vendor_event_idx, |
| 6948 | int approxlen, gfp_t gfp) |
| 6949 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 6950 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 6951 | const struct nl80211_vendor_cmd_info *info; |
| 6952 | |
| 6953 | switch (cmd) { |
| 6954 | case NL80211_CMD_TESTMODE: |
| 6955 | if (WARN_ON(vendor_event_idx != -1)) |
| 6956 | return NULL; |
| 6957 | info = NULL; |
| 6958 | break; |
| 6959 | case NL80211_CMD_VENDOR: |
| 6960 | if (WARN_ON(vendor_event_idx < 0 || |
| 6961 | vendor_event_idx >= wiphy->n_vendor_events)) |
| 6962 | return NULL; |
| 6963 | info = &wiphy->vendor_events[vendor_event_idx]; |
| 6964 | break; |
| 6965 | default: |
| 6966 | WARN_ON(1); |
| 6967 | return NULL; |
| 6968 | } |
| 6969 | |
| 6970 | return __cfg80211_alloc_vendor_skb(rdev, approxlen, 0, 0, |
| 6971 | cmd, attr, info, gfp); |
| 6972 | } |
| 6973 | EXPORT_SYMBOL(__cfg80211_alloc_event_skb); |
| 6974 | |
| 6975 | void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp) |
| 6976 | { |
| 6977 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 6978 | void *hdr = ((void **)skb->cb)[1]; |
| 6979 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 6980 | enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE; |
| 6981 | |
| 6982 | nla_nest_end(skb, data); |
| 6983 | genlmsg_end(skb, hdr); |
| 6984 | |
| 6985 | if (data->nla_type == NL80211_ATTR_VENDOR_DATA) |
| 6986 | mcgrp = NL80211_MCGRP_VENDOR; |
| 6987 | |
| 6988 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0, |
| 6989 | mcgrp, gfp); |
| 6990 | } |
| 6991 | EXPORT_SYMBOL(__cfg80211_send_event_skb); |
| 6992 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6993 | #ifdef CONFIG_NL80211_TESTMODE |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6994 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
| 6995 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6996 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 6997 | struct wireless_dev *wdev = |
| 6998 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6999 | int err; |
| 7000 | |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 7001 | if (!rdev->ops->testmode_cmd) |
| 7002 | return -EOPNOTSUPP; |
| 7003 | |
| 7004 | if (IS_ERR(wdev)) { |
| 7005 | err = PTR_ERR(wdev); |
| 7006 | if (err != -EINVAL) |
| 7007 | return err; |
| 7008 | wdev = NULL; |
| 7009 | } else if (wdev->wiphy != &rdev->wiphy) { |
| 7010 | return -EINVAL; |
| 7011 | } |
| 7012 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7013 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
| 7014 | return -EINVAL; |
| 7015 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 7016 | rdev->cur_cmd_info = info; |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 7017 | err = rdev_testmode_cmd(rdev, wdev, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7018 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
| 7019 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 7020 | rdev->cur_cmd_info = NULL; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7021 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7022 | return err; |
| 7023 | } |
| 7024 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7025 | static int nl80211_testmode_dump(struct sk_buff *skb, |
| 7026 | struct netlink_callback *cb) |
| 7027 | { |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 7028 | struct cfg80211_registered_device *rdev; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7029 | int err; |
| 7030 | long phy_idx; |
| 7031 | void *data = NULL; |
| 7032 | int data_len = 0; |
| 7033 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 7034 | rtnl_lock(); |
| 7035 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7036 | if (cb->args[0]) { |
| 7037 | /* |
| 7038 | * 0 is a valid index, but not valid for args[0], |
| 7039 | * so we need to offset by 1. |
| 7040 | */ |
| 7041 | phy_idx = cb->args[0] - 1; |
| 7042 | } else { |
| 7043 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 7044 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 7045 | nl80211_policy); |
| 7046 | if (err) |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 7047 | goto out_err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 7048 | |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 7049 | rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), |
| 7050 | nl80211_fam.attrbuf); |
| 7051 | if (IS_ERR(rdev)) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 7052 | err = PTR_ERR(rdev); |
| 7053 | goto out_err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 7054 | } |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 7055 | phy_idx = rdev->wiphy_idx; |
| 7056 | rdev = NULL; |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 7057 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7058 | if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]) |
| 7059 | cb->args[1] = |
| 7060 | (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]; |
| 7061 | } |
| 7062 | |
| 7063 | if (cb->args[1]) { |
| 7064 | data = nla_data((void *)cb->args[1]); |
| 7065 | data_len = nla_len((void *)cb->args[1]); |
| 7066 | } |
| 7067 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 7068 | rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
| 7069 | if (!rdev) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 7070 | err = -ENOENT; |
| 7071 | goto out_err; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7072 | } |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7073 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 7074 | if (!rdev->ops->testmode_dump) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7075 | err = -EOPNOTSUPP; |
| 7076 | goto out_err; |
| 7077 | } |
| 7078 | |
| 7079 | while (1) { |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7080 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7081 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 7082 | NL80211_CMD_TESTMODE); |
| 7083 | struct nlattr *tmdata; |
| 7084 | |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 7085 | if (!hdr) |
| 7086 | break; |
| 7087 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7088 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7089 | genlmsg_cancel(skb, hdr); |
| 7090 | break; |
| 7091 | } |
| 7092 | |
| 7093 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 7094 | if (!tmdata) { |
| 7095 | genlmsg_cancel(skb, hdr); |
| 7096 | break; |
| 7097 | } |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7098 | err = rdev_testmode_dump(rdev, skb, cb, data, data_len); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7099 | nla_nest_end(skb, tmdata); |
| 7100 | |
| 7101 | if (err == -ENOBUFS || err == -ENOENT) { |
| 7102 | genlmsg_cancel(skb, hdr); |
| 7103 | break; |
| 7104 | } else if (err) { |
| 7105 | genlmsg_cancel(skb, hdr); |
| 7106 | goto out_err; |
| 7107 | } |
| 7108 | |
| 7109 | genlmsg_end(skb, hdr); |
| 7110 | } |
| 7111 | |
| 7112 | err = skb->len; |
| 7113 | /* see above */ |
| 7114 | cb->args[0] = phy_idx + 1; |
| 7115 | out_err: |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 7116 | rtnl_unlock(); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7117 | return err; |
| 7118 | } |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7119 | #endif |
| 7120 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7121 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
| 7122 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7123 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7124 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7125 | struct cfg80211_connect_params connect; |
| 7126 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7127 | struct cfg80211_cached_keys *connkeys = NULL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7128 | int err; |
| 7129 | |
| 7130 | memset(&connect, 0, sizeof(connect)); |
| 7131 | |
| 7132 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 7133 | return -EINVAL; |
| 7134 | |
| 7135 | if (!info->attrs[NL80211_ATTR_SSID] || |
| 7136 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 7137 | return -EINVAL; |
| 7138 | |
| 7139 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 7140 | connect.auth_type = |
| 7141 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 7142 | if (!nl80211_valid_auth_type(rdev, connect.auth_type, |
| 7143 | NL80211_CMD_CONNECT)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7144 | return -EINVAL; |
| 7145 | } else |
| 7146 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 7147 | |
| 7148 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; |
| 7149 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 7150 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 7151 | NL80211_MAX_NR_CIPHER_SUITES); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7152 | if (err) |
| 7153 | return err; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7154 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7155 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7156 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7157 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7158 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 7159 | wiphy = &rdev->wiphy; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7160 | |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 7161 | connect.bg_scan_period = -1; |
| 7162 | if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] && |
| 7163 | (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) { |
| 7164 | connect.bg_scan_period = |
| 7165 | nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]); |
| 7166 | } |
| 7167 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7168 | if (info->attrs[NL80211_ATTR_MAC]) |
| 7169 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 7170 | else if (info->attrs[NL80211_ATTR_MAC_HINT]) |
| 7171 | connect.bssid_hint = |
| 7172 | nla_data(info->attrs[NL80211_ATTR_MAC_HINT]); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7173 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 7174 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 7175 | |
| 7176 | if (info->attrs[NL80211_ATTR_IE]) { |
| 7177 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 7178 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 7179 | } |
| 7180 | |
Jouni Malinen | cee00a9 | 2013-01-15 17:15:57 +0200 | [diff] [blame] | 7181 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
| 7182 | connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
| 7183 | if (connect.mfp != NL80211_MFP_REQUIRED && |
| 7184 | connect.mfp != NL80211_MFP_NO) |
| 7185 | return -EINVAL; |
| 7186 | } else { |
| 7187 | connect.mfp = NL80211_MFP_NO; |
| 7188 | } |
| 7189 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7190 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 7191 | connect.channel = nl80211_get_valid_chan( |
| 7192 | wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 7193 | if (!connect.channel) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7194 | return -EINVAL; |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 7195 | } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) { |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 7196 | connect.channel_hint = nl80211_get_valid_chan( |
| 7197 | wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]); |
| 7198 | if (!connect.channel_hint) |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 7199 | return -EINVAL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7200 | } |
| 7201 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7202 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
| 7203 | connkeys = nl80211_parse_connkeys(rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 7204 | info->attrs[NL80211_ATTR_KEYS], NULL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7205 | if (IS_ERR(connkeys)) |
| 7206 | return PTR_ERR(connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7207 | } |
| 7208 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 7209 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
| 7210 | connect.flags |= ASSOC_REQ_DISABLE_HT; |
| 7211 | |
| 7212 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 7213 | memcpy(&connect.ht_capa_mask, |
| 7214 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 7215 | sizeof(connect.ht_capa_mask)); |
| 7216 | |
| 7217 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 7218 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) { |
| 7219 | kfree(connkeys); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 7220 | return -EINVAL; |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 7221 | } |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 7222 | memcpy(&connect.ht_capa, |
| 7223 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 7224 | sizeof(connect.ht_capa)); |
| 7225 | } |
| 7226 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 7227 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
| 7228 | connect.flags |= ASSOC_REQ_DISABLE_VHT; |
| 7229 | |
| 7230 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
| 7231 | memcpy(&connect.vht_capa_mask, |
| 7232 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), |
| 7233 | sizeof(connect.vht_capa_mask)); |
| 7234 | |
| 7235 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { |
| 7236 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) { |
| 7237 | kfree(connkeys); |
| 7238 | return -EINVAL; |
| 7239 | } |
| 7240 | memcpy(&connect.vht_capa, |
| 7241 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), |
| 7242 | sizeof(connect.vht_capa)); |
| 7243 | } |
| 7244 | |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7245 | wdev_lock(dev->ieee80211_ptr); |
| 7246 | err = cfg80211_connect(rdev, dev, &connect, connkeys, NULL); |
| 7247 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7248 | if (err) |
| 7249 | kfree(connkeys); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7250 | return err; |
| 7251 | } |
| 7252 | |
| 7253 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) |
| 7254 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7255 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7256 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7257 | u16 reason; |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7258 | int ret; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7259 | |
| 7260 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 7261 | reason = WLAN_REASON_DEAUTH_LEAVING; |
| 7262 | else |
| 7263 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 7264 | |
| 7265 | if (reason == 0) |
| 7266 | return -EINVAL; |
| 7267 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7268 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7269 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7270 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7271 | |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7272 | wdev_lock(dev->ieee80211_ptr); |
| 7273 | ret = cfg80211_disconnect(rdev, dev, reason, true); |
| 7274 | wdev_unlock(dev->ieee80211_ptr); |
| 7275 | return ret; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7276 | } |
| 7277 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7278 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
| 7279 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7280 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7281 | struct net *net; |
| 7282 | int err; |
| 7283 | u32 pid; |
| 7284 | |
| 7285 | if (!info->attrs[NL80211_ATTR_PID]) |
| 7286 | return -EINVAL; |
| 7287 | |
| 7288 | pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); |
| 7289 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7290 | net = get_net_ns_by_pid(pid); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7291 | if (IS_ERR(net)) |
| 7292 | return PTR_ERR(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7293 | |
| 7294 | err = 0; |
| 7295 | |
| 7296 | /* check if anything to do */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7297 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
| 7298 | err = cfg80211_switch_netns(rdev, net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7299 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7300 | put_net(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7301 | return err; |
| 7302 | } |
| 7303 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7304 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 7305 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7306 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7307 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
| 7308 | struct cfg80211_pmksa *pmksa) = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7309 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7310 | struct cfg80211_pmksa pmksa; |
| 7311 | |
| 7312 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); |
| 7313 | |
| 7314 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 7315 | return -EINVAL; |
| 7316 | |
| 7317 | if (!info->attrs[NL80211_ATTR_PMKID]) |
| 7318 | return -EINVAL; |
| 7319 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7320 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
| 7321 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 7322 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7323 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7324 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7325 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7326 | |
| 7327 | switch (info->genlhdr->cmd) { |
| 7328 | case NL80211_CMD_SET_PMKSA: |
| 7329 | rdev_ops = rdev->ops->set_pmksa; |
| 7330 | break; |
| 7331 | case NL80211_CMD_DEL_PMKSA: |
| 7332 | rdev_ops = rdev->ops->del_pmksa; |
| 7333 | break; |
| 7334 | default: |
| 7335 | WARN_ON(1); |
| 7336 | break; |
| 7337 | } |
| 7338 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7339 | if (!rdev_ops) |
| 7340 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7341 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7342 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7343 | } |
| 7344 | |
| 7345 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 7346 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7347 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7348 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7349 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7350 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7351 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7352 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7353 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7354 | if (!rdev->ops->flush_pmksa) |
| 7355 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7356 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7357 | return rdev_flush_pmksa(rdev, dev); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7358 | } |
| 7359 | |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7360 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) |
| 7361 | { |
| 7362 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7363 | struct net_device *dev = info->user_ptr[1]; |
| 7364 | u8 action_code, dialog_token; |
Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 7365 | u32 peer_capability = 0; |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7366 | u16 status_code; |
| 7367 | u8 *peer; |
| 7368 | |
| 7369 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 7370 | !rdev->ops->tdls_mgmt) |
| 7371 | return -EOPNOTSUPP; |
| 7372 | |
| 7373 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || |
| 7374 | !info->attrs[NL80211_ATTR_STATUS_CODE] || |
| 7375 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || |
| 7376 | !info->attrs[NL80211_ATTR_IE] || |
| 7377 | !info->attrs[NL80211_ATTR_MAC]) |
| 7378 | return -EINVAL; |
| 7379 | |
| 7380 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 7381 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); |
| 7382 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); |
| 7383 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); |
Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 7384 | if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]) |
| 7385 | peer_capability = |
| 7386 | nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7387 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7388 | return rdev_tdls_mgmt(rdev, dev, peer, action_code, |
Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 7389 | dialog_token, status_code, peer_capability, |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7390 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 7391 | nla_len(info->attrs[NL80211_ATTR_IE])); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7392 | } |
| 7393 | |
| 7394 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) |
| 7395 | { |
| 7396 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7397 | struct net_device *dev = info->user_ptr[1]; |
| 7398 | enum nl80211_tdls_operation operation; |
| 7399 | u8 *peer; |
| 7400 | |
| 7401 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 7402 | !rdev->ops->tdls_oper) |
| 7403 | return -EOPNOTSUPP; |
| 7404 | |
| 7405 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || |
| 7406 | !info->attrs[NL80211_ATTR_MAC]) |
| 7407 | return -EINVAL; |
| 7408 | |
| 7409 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); |
| 7410 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 7411 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7412 | return rdev_tdls_oper(rdev, dev, peer, operation); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7413 | } |
| 7414 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7415 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
| 7416 | struct genl_info *info) |
| 7417 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7418 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7419 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7420 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7421 | struct sk_buff *msg; |
| 7422 | void *hdr; |
| 7423 | u64 cookie; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7424 | u32 duration; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7425 | int err; |
| 7426 | |
| 7427 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 7428 | !info->attrs[NL80211_ATTR_DURATION]) |
| 7429 | return -EINVAL; |
| 7430 | |
| 7431 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
| 7432 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 7433 | if (!rdev->ops->remain_on_channel || |
| 7434 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7435 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7436 | |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 7437 | /* |
| 7438 | * We should be on that channel for at least a minimum amount of |
| 7439 | * time (10ms) but no longer than the driver supports. |
| 7440 | */ |
| 7441 | if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 7442 | duration > rdev->wiphy.max_remain_on_channel_duration) |
| 7443 | return -EINVAL; |
| 7444 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7445 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 7446 | if (err) |
| 7447 | return err; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7448 | |
| 7449 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7450 | if (!msg) |
| 7451 | return -ENOMEM; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7452 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7453 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7454 | NL80211_CMD_REMAIN_ON_CHANNEL); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 7455 | if (!hdr) { |
| 7456 | err = -ENOBUFS; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7457 | goto free_msg; |
| 7458 | } |
| 7459 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7460 | err = rdev_remain_on_channel(rdev, wdev, chandef.chan, |
| 7461 | duration, &cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7462 | |
| 7463 | if (err) |
| 7464 | goto free_msg; |
| 7465 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7466 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 7467 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7468 | |
| 7469 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7470 | |
| 7471 | return genlmsg_reply(msg, info); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7472 | |
| 7473 | nla_put_failure: |
| 7474 | err = -ENOBUFS; |
| 7475 | free_msg: |
| 7476 | nlmsg_free(msg); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7477 | return err; |
| 7478 | } |
| 7479 | |
| 7480 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, |
| 7481 | struct genl_info *info) |
| 7482 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7483 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7484 | struct wireless_dev *wdev = info->user_ptr[1]; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7485 | u64 cookie; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7486 | |
| 7487 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 7488 | return -EINVAL; |
| 7489 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7490 | if (!rdev->ops->cancel_remain_on_channel) |
| 7491 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7492 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7493 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 7494 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7495 | return rdev_cancel_remain_on_channel(rdev, wdev, cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7496 | } |
| 7497 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7498 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
| 7499 | u8 *rates, u8 rates_len) |
| 7500 | { |
| 7501 | u8 i; |
| 7502 | u32 mask = 0; |
| 7503 | |
| 7504 | for (i = 0; i < rates_len; i++) { |
| 7505 | int rate = (rates[i] & 0x7f) * 5; |
| 7506 | int ridx; |
| 7507 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { |
| 7508 | struct ieee80211_rate *srate = |
| 7509 | &sband->bitrates[ridx]; |
| 7510 | if (rate == srate->bitrate) { |
| 7511 | mask |= 1 << ridx; |
| 7512 | break; |
| 7513 | } |
| 7514 | } |
| 7515 | if (ridx == sband->n_bitrates) |
| 7516 | return 0; /* rate not found */ |
| 7517 | } |
| 7518 | |
| 7519 | return mask; |
| 7520 | } |
| 7521 | |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7522 | static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, |
| 7523 | u8 *rates, u8 rates_len, |
| 7524 | u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) |
| 7525 | { |
| 7526 | u8 i; |
| 7527 | |
| 7528 | memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); |
| 7529 | |
| 7530 | for (i = 0; i < rates_len; i++) { |
| 7531 | int ridx, rbit; |
| 7532 | |
| 7533 | ridx = rates[i] / 8; |
| 7534 | rbit = BIT(rates[i] % 8); |
| 7535 | |
| 7536 | /* check validity */ |
Dan Carpenter | 910570b5 | 2012-02-01 10:42:11 +0300 | [diff] [blame] | 7537 | if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7538 | return false; |
| 7539 | |
| 7540 | /* check availability */ |
| 7541 | if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) |
| 7542 | mcs[ridx] |= rbit; |
| 7543 | else |
| 7544 | return false; |
| 7545 | } |
| 7546 | |
| 7547 | return true; |
| 7548 | } |
| 7549 | |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 7550 | static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map) |
| 7551 | { |
| 7552 | u16 mcs_mask = 0; |
| 7553 | |
| 7554 | switch (vht_mcs_map) { |
| 7555 | case IEEE80211_VHT_MCS_NOT_SUPPORTED: |
| 7556 | break; |
| 7557 | case IEEE80211_VHT_MCS_SUPPORT_0_7: |
| 7558 | mcs_mask = 0x00FF; |
| 7559 | break; |
| 7560 | case IEEE80211_VHT_MCS_SUPPORT_0_8: |
| 7561 | mcs_mask = 0x01FF; |
| 7562 | break; |
| 7563 | case IEEE80211_VHT_MCS_SUPPORT_0_9: |
| 7564 | mcs_mask = 0x03FF; |
| 7565 | break; |
| 7566 | default: |
| 7567 | break; |
| 7568 | } |
| 7569 | |
| 7570 | return mcs_mask; |
| 7571 | } |
| 7572 | |
| 7573 | static void vht_build_mcs_mask(u16 vht_mcs_map, |
| 7574 | u16 vht_mcs_mask[NL80211_VHT_NSS_MAX]) |
| 7575 | { |
| 7576 | u8 nss; |
| 7577 | |
| 7578 | for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) { |
| 7579 | vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03); |
| 7580 | vht_mcs_map >>= 2; |
| 7581 | } |
| 7582 | } |
| 7583 | |
| 7584 | static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband, |
| 7585 | struct nl80211_txrate_vht *txrate, |
| 7586 | u16 mcs[NL80211_VHT_NSS_MAX]) |
| 7587 | { |
| 7588 | u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); |
| 7589 | u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {}; |
| 7590 | u8 i; |
| 7591 | |
| 7592 | if (!sband->vht_cap.vht_supported) |
| 7593 | return false; |
| 7594 | |
| 7595 | memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX); |
| 7596 | |
| 7597 | /* Build vht_mcs_mask from VHT capabilities */ |
| 7598 | vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask); |
| 7599 | |
| 7600 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) { |
| 7601 | if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i]) |
| 7602 | mcs[i] = txrate->mcs[i]; |
| 7603 | else |
| 7604 | return false; |
| 7605 | } |
| 7606 | |
| 7607 | return true; |
| 7608 | } |
| 7609 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 7610 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7611 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
| 7612 | .len = NL80211_MAX_SUPP_RATES }, |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 7613 | [NL80211_TXRATE_HT] = { .type = NLA_BINARY, |
| 7614 | .len = NL80211_MAX_SUPP_HT_RATES }, |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 7615 | [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)}, |
Janusz Dziedzic | 0b9323f | 2014-01-08 08:46:02 +0100 | [diff] [blame] | 7616 | [NL80211_TXRATE_GI] = { .type = NLA_U8 }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7617 | }; |
| 7618 | |
| 7619 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, |
| 7620 | struct genl_info *info) |
| 7621 | { |
| 7622 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7623 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7624 | struct cfg80211_bitrate_mask mask; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7625 | int rem, i; |
| 7626 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7627 | struct nlattr *tx_rates; |
| 7628 | struct ieee80211_supported_band *sband; |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 7629 | u16 vht_tx_mcs_map; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7630 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7631 | if (!rdev->ops->set_bitrate_mask) |
| 7632 | return -EOPNOTSUPP; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7633 | |
| 7634 | memset(&mask, 0, sizeof(mask)); |
| 7635 | /* Default to all rates enabled */ |
| 7636 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) { |
| 7637 | sband = rdev->wiphy.bands[i]; |
Janusz Dziedzic | 7869303 | 2013-12-03 09:50:44 +0100 | [diff] [blame] | 7638 | |
| 7639 | if (!sband) |
| 7640 | continue; |
| 7641 | |
| 7642 | mask.control[i].legacy = (1 << sband->n_bitrates) - 1; |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 7643 | memcpy(mask.control[i].ht_mcs, |
Janusz Dziedzic | 7869303 | 2013-12-03 09:50:44 +0100 | [diff] [blame] | 7644 | sband->ht_cap.mcs.rx_mask, |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 7645 | sizeof(mask.control[i].ht_mcs)); |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 7646 | |
| 7647 | if (!sband->vht_cap.vht_supported) |
| 7648 | continue; |
| 7649 | |
| 7650 | vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); |
| 7651 | 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] | 7652 | } |
| 7653 | |
Janusz Dziedzic | b9243ab | 2013-12-05 10:02:14 +0100 | [diff] [blame] | 7654 | /* if no rates are given set it back to the defaults */ |
| 7655 | if (!info->attrs[NL80211_ATTR_TX_RATES]) |
| 7656 | goto out; |
| 7657 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7658 | /* |
| 7659 | * The nested attribute uses enum nl80211_band as the index. This maps |
| 7660 | * directly to the enum ieee80211_band values used in cfg80211. |
| 7661 | */ |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7662 | 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] | 7663 | 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] | 7664 | enum ieee80211_band band = nla_type(tx_rates); |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 7665 | int err; |
| 7666 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7667 | if (band < 0 || band >= IEEE80211_NUM_BANDS) |
| 7668 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7669 | sband = rdev->wiphy.bands[band]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7670 | if (sband == NULL) |
| 7671 | return -EINVAL; |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 7672 | err = nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), |
| 7673 | nla_len(tx_rates), nl80211_txattr_policy); |
| 7674 | if (err) |
| 7675 | return err; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7676 | if (tb[NL80211_TXRATE_LEGACY]) { |
| 7677 | mask.control[band].legacy = rateset_to_mask( |
| 7678 | sband, |
| 7679 | nla_data(tb[NL80211_TXRATE_LEGACY]), |
| 7680 | nla_len(tb[NL80211_TXRATE_LEGACY])); |
Bala Shanmugam | 218d2e2 | 2012-04-20 19:12:58 +0530 | [diff] [blame] | 7681 | if ((mask.control[band].legacy == 0) && |
| 7682 | nla_len(tb[NL80211_TXRATE_LEGACY])) |
| 7683 | return -EINVAL; |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7684 | } |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 7685 | if (tb[NL80211_TXRATE_HT]) { |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7686 | if (!ht_rateset_to_mask( |
| 7687 | sband, |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 7688 | nla_data(tb[NL80211_TXRATE_HT]), |
| 7689 | nla_len(tb[NL80211_TXRATE_HT]), |
| 7690 | mask.control[band].ht_mcs)) |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7691 | return -EINVAL; |
| 7692 | } |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 7693 | if (tb[NL80211_TXRATE_VHT]) { |
| 7694 | if (!vht_set_mcs_mask( |
| 7695 | sband, |
| 7696 | nla_data(tb[NL80211_TXRATE_VHT]), |
| 7697 | mask.control[band].vht_mcs)) |
| 7698 | return -EINVAL; |
| 7699 | } |
Janusz Dziedzic | 0b9323f | 2014-01-08 08:46:02 +0100 | [diff] [blame] | 7700 | if (tb[NL80211_TXRATE_GI]) { |
| 7701 | mask.control[band].gi = |
| 7702 | nla_get_u8(tb[NL80211_TXRATE_GI]); |
| 7703 | if (mask.control[band].gi > NL80211_TXRATE_FORCE_LGI) |
| 7704 | return -EINVAL; |
| 7705 | } |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7706 | |
| 7707 | if (mask.control[band].legacy == 0) { |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 7708 | /* don't allow empty legacy rates if HT or VHT |
| 7709 | * are not even supported. |
| 7710 | */ |
| 7711 | if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported || |
| 7712 | rdev->wiphy.bands[band]->vht_cap.vht_supported)) |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7713 | return -EINVAL; |
| 7714 | |
| 7715 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 7716 | if (mask.control[band].ht_mcs[i]) |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 7717 | goto out; |
| 7718 | |
| 7719 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) |
| 7720 | if (mask.control[band].vht_mcs[i]) |
| 7721 | goto out; |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7722 | |
| 7723 | /* legacy and mcs rates may not be both empty */ |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 7724 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7725 | } |
| 7726 | } |
| 7727 | |
Janusz Dziedzic | b9243ab | 2013-12-05 10:02:14 +0100 | [diff] [blame] | 7728 | out: |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7729 | return rdev_set_bitrate_mask(rdev, dev, NULL, &mask); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7730 | } |
| 7731 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7732 | 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] | 7733 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7734 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7735 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7736 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7737 | |
| 7738 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) |
| 7739 | return -EINVAL; |
| 7740 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7741 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
| 7742 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7743 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7744 | switch (wdev->iftype) { |
| 7745 | case NL80211_IFTYPE_STATION: |
| 7746 | case NL80211_IFTYPE_ADHOC: |
| 7747 | case NL80211_IFTYPE_P2P_CLIENT: |
| 7748 | case NL80211_IFTYPE_AP: |
| 7749 | case NL80211_IFTYPE_AP_VLAN: |
| 7750 | case NL80211_IFTYPE_MESH_POINT: |
| 7751 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7752 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7753 | break; |
| 7754 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7755 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7756 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7757 | |
| 7758 | /* not much point in registering if we can't reply */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7759 | if (!rdev->ops->mgmt_tx) |
| 7760 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7761 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7762 | return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7763 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
| 7764 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7765 | } |
| 7766 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7767 | 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] | 7768 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7769 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7770 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7771 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7772 | int err; |
Johannes Berg | d64d373 | 2011-11-10 09:44:46 +0100 | [diff] [blame] | 7773 | void *hdr = NULL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7774 | u64 cookie; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7775 | struct sk_buff *msg = NULL; |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7776 | struct cfg80211_mgmt_tx_params params = { |
| 7777 | .dont_wait_for_ack = |
| 7778 | info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK], |
| 7779 | }; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7780 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7781 | if (!info->attrs[NL80211_ATTR_FRAME]) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7782 | return -EINVAL; |
| 7783 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7784 | if (!rdev->ops->mgmt_tx) |
| 7785 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7786 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7787 | switch (wdev->iftype) { |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 7788 | case NL80211_IFTYPE_P2P_DEVICE: |
| 7789 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 7790 | return -EINVAL; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7791 | case NL80211_IFTYPE_STATION: |
| 7792 | case NL80211_IFTYPE_ADHOC: |
| 7793 | case NL80211_IFTYPE_P2P_CLIENT: |
| 7794 | case NL80211_IFTYPE_AP: |
| 7795 | case NL80211_IFTYPE_AP_VLAN: |
| 7796 | case NL80211_IFTYPE_MESH_POINT: |
| 7797 | case NL80211_IFTYPE_P2P_GO: |
| 7798 | break; |
| 7799 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7800 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7801 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7802 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7803 | if (info->attrs[NL80211_ATTR_DURATION]) { |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 7804 | if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7805 | return -EINVAL; |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7806 | params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 7807 | |
| 7808 | /* |
| 7809 | * We should wait on the channel for at least a minimum amount |
| 7810 | * of time (10ms) but no longer than the driver supports. |
| 7811 | */ |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7812 | if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 7813 | params.wait > rdev->wiphy.max_remain_on_channel_duration) |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 7814 | return -EINVAL; |
| 7815 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7816 | } |
| 7817 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7818 | params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7819 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7820 | if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 7821 | return -EINVAL; |
| 7822 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7823 | 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] | 7824 | |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 7825 | /* get the channel if any has been specified, otherwise pass NULL to |
| 7826 | * the driver. The latter will use the current one |
| 7827 | */ |
| 7828 | chandef.chan = NULL; |
| 7829 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 7830 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 7831 | if (err) |
| 7832 | return err; |
| 7833 | } |
| 7834 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7835 | if (!chandef.chan && params.offchan) |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 7836 | return -EINVAL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7837 | |
Andrei Otcheretianski | 34d22ce | 2014-05-09 14:11:44 +0300 | [diff] [blame] | 7838 | params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]); |
| 7839 | params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]); |
| 7840 | |
| 7841 | if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) { |
| 7842 | int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]); |
| 7843 | int i; |
| 7844 | |
| 7845 | if (len % sizeof(u16)) |
| 7846 | return -EINVAL; |
| 7847 | |
| 7848 | params.n_csa_offsets = len / sizeof(u16); |
| 7849 | params.csa_offsets = |
| 7850 | nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]); |
| 7851 | |
| 7852 | /* check that all the offsets fit the frame */ |
| 7853 | for (i = 0; i < params.n_csa_offsets; i++) { |
| 7854 | if (params.csa_offsets[i] >= params.len) |
| 7855 | return -EINVAL; |
| 7856 | } |
| 7857 | } |
| 7858 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7859 | if (!params.dont_wait_for_ack) { |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7860 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 7861 | if (!msg) |
| 7862 | return -ENOMEM; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7863 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7864 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7865 | NL80211_CMD_FRAME); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 7866 | if (!hdr) { |
| 7867 | err = -ENOBUFS; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7868 | goto free_msg; |
| 7869 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7870 | } |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7871 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7872 | params.chan = chandef.chan; |
| 7873 | err = cfg80211_mlme_mgmt_tx(rdev, wdev, ¶ms, &cookie); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7874 | if (err) |
| 7875 | goto free_msg; |
| 7876 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7877 | if (msg) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7878 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 7879 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7880 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7881 | genlmsg_end(msg, hdr); |
| 7882 | return genlmsg_reply(msg, info); |
| 7883 | } |
| 7884 | |
| 7885 | return 0; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7886 | |
| 7887 | nla_put_failure: |
| 7888 | err = -ENOBUFS; |
| 7889 | free_msg: |
| 7890 | nlmsg_free(msg); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7891 | return err; |
| 7892 | } |
| 7893 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7894 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
| 7895 | { |
| 7896 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7897 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7898 | u64 cookie; |
| 7899 | |
| 7900 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 7901 | return -EINVAL; |
| 7902 | |
| 7903 | if (!rdev->ops->mgmt_tx_cancel_wait) |
| 7904 | return -EOPNOTSUPP; |
| 7905 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7906 | switch (wdev->iftype) { |
| 7907 | case NL80211_IFTYPE_STATION: |
| 7908 | case NL80211_IFTYPE_ADHOC: |
| 7909 | case NL80211_IFTYPE_P2P_CLIENT: |
| 7910 | case NL80211_IFTYPE_AP: |
| 7911 | case NL80211_IFTYPE_AP_VLAN: |
| 7912 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7913 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7914 | break; |
| 7915 | default: |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7916 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7917 | } |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7918 | |
| 7919 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 7920 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7921 | return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie); |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7922 | } |
| 7923 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7924 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
| 7925 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7926 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7927 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7928 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7929 | u8 ps_state; |
| 7930 | bool state; |
| 7931 | int err; |
| 7932 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7933 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
| 7934 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7935 | |
| 7936 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); |
| 7937 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7938 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
| 7939 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7940 | |
| 7941 | wdev = dev->ieee80211_ptr; |
| 7942 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7943 | if (!rdev->ops->set_power_mgmt) |
| 7944 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7945 | |
| 7946 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; |
| 7947 | |
| 7948 | if (state == wdev->ps) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7949 | return 0; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7950 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7951 | err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7952 | if (!err) |
| 7953 | wdev->ps = state; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7954 | return err; |
| 7955 | } |
| 7956 | |
| 7957 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) |
| 7958 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7959 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7960 | enum nl80211_ps_state ps_state; |
| 7961 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7962 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7963 | struct sk_buff *msg; |
| 7964 | void *hdr; |
| 7965 | int err; |
| 7966 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7967 | wdev = dev->ieee80211_ptr; |
| 7968 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7969 | if (!rdev->ops->set_power_mgmt) |
| 7970 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7971 | |
| 7972 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7973 | if (!msg) |
| 7974 | return -ENOMEM; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7975 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7976 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7977 | NL80211_CMD_GET_POWER_SAVE); |
| 7978 | if (!hdr) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7979 | err = -ENOBUFS; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7980 | goto free_msg; |
| 7981 | } |
| 7982 | |
| 7983 | if (wdev->ps) |
| 7984 | ps_state = NL80211_PS_ENABLED; |
| 7985 | else |
| 7986 | ps_state = NL80211_PS_DISABLED; |
| 7987 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7988 | if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) |
| 7989 | goto nla_put_failure; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7990 | |
| 7991 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7992 | return genlmsg_reply(msg, info); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7993 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7994 | nla_put_failure: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7995 | err = -ENOBUFS; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7996 | free_msg: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7997 | nlmsg_free(msg); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7998 | return err; |
| 7999 | } |
| 8000 | |
Johannes Berg | 94e860f | 2014-01-20 23:58:15 +0100 | [diff] [blame] | 8001 | static const struct nla_policy |
| 8002 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = { |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8003 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, |
| 8004 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, |
| 8005 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 8006 | [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 }, |
| 8007 | [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 }, |
| 8008 | [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8009 | }; |
| 8010 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 8011 | static int nl80211_set_cqm_txe(struct genl_info *info, |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 8012 | u32 rate, u32 pkts, u32 intvl) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 8013 | { |
| 8014 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 8015 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 8016 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 8017 | |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 8018 | if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 8019 | return -EINVAL; |
| 8020 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 8021 | if (!rdev->ops->set_cqm_txe_config) |
| 8022 | return -EOPNOTSUPP; |
| 8023 | |
| 8024 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
| 8025 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 8026 | return -EOPNOTSUPP; |
| 8027 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8028 | return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 8029 | } |
| 8030 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8031 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
| 8032 | s32 threshold, u32 hysteresis) |
| 8033 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8034 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8035 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 8036 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8037 | |
| 8038 | if (threshold > 0) |
| 8039 | return -EINVAL; |
| 8040 | |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 8041 | /* disabling - hysteresis should also be zero then */ |
| 8042 | if (threshold == 0) |
| 8043 | hysteresis = 0; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8044 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8045 | if (!rdev->ops->set_cqm_rssi_config) |
| 8046 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8047 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 8048 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8049 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 8050 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8051 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8052 | return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8053 | } |
| 8054 | |
| 8055 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) |
| 8056 | { |
| 8057 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; |
| 8058 | struct nlattr *cqm; |
| 8059 | int err; |
| 8060 | |
| 8061 | cqm = info->attrs[NL80211_ATTR_CQM]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 8062 | if (!cqm) |
| 8063 | return -EINVAL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8064 | |
| 8065 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, |
| 8066 | nl80211_attr_cqm_policy); |
| 8067 | if (err) |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 8068 | return err; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8069 | |
| 8070 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && |
| 8071 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 8072 | s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
| 8073 | u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8074 | |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 8075 | return nl80211_set_cqm_rssi(info, threshold, hysteresis); |
| 8076 | } |
| 8077 | |
| 8078 | if (attrs[NL80211_ATTR_CQM_TXE_RATE] && |
| 8079 | attrs[NL80211_ATTR_CQM_TXE_PKTS] && |
| 8080 | attrs[NL80211_ATTR_CQM_TXE_INTVL]) { |
| 8081 | u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]); |
| 8082 | u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]); |
| 8083 | u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]); |
| 8084 | |
| 8085 | return nl80211_set_cqm_txe(info, rate, pkts, intvl); |
| 8086 | } |
| 8087 | |
| 8088 | return -EINVAL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8089 | } |
| 8090 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8091 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
| 8092 | { |
| 8093 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8094 | struct net_device *dev = info->user_ptr[1]; |
| 8095 | struct mesh_config cfg; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 8096 | struct mesh_setup setup; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8097 | int err; |
| 8098 | |
| 8099 | /* start with default */ |
| 8100 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 8101 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8102 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 8103 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8104 | /* and parse parameters if given */ |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 8105 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8106 | if (err) |
| 8107 | return err; |
| 8108 | } |
| 8109 | |
| 8110 | if (!info->attrs[NL80211_ATTR_MESH_ID] || |
| 8111 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) |
| 8112 | return -EINVAL; |
| 8113 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 8114 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
| 8115 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 8116 | |
Chun-Yeow Yeoh | 4bb6234 | 2011-11-24 17:15:20 -0800 | [diff] [blame] | 8117 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 8118 | !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, |
| 8119 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 8120 | return -EINVAL; |
| 8121 | |
Marco Porsch | 9bdbf04 | 2013-01-07 16:04:51 +0100 | [diff] [blame] | 8122 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 8123 | setup.beacon_interval = |
| 8124 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 8125 | if (setup.beacon_interval < 10 || |
| 8126 | setup.beacon_interval > 10000) |
| 8127 | return -EINVAL; |
| 8128 | } |
| 8129 | |
| 8130 | if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) { |
| 8131 | setup.dtim_period = |
| 8132 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 8133 | if (setup.dtim_period < 1 || setup.dtim_period > 100) |
| 8134 | return -EINVAL; |
| 8135 | } |
| 8136 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 8137 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
| 8138 | /* parse additional setup parameters if given */ |
| 8139 | err = nl80211_parse_mesh_setup(info, &setup); |
| 8140 | if (err) |
| 8141 | return err; |
| 8142 | } |
| 8143 | |
Thomas Pedersen | d37bb18 | 2013-03-04 13:06:13 -0800 | [diff] [blame] | 8144 | if (setup.user_mpm) |
| 8145 | cfg.auto_open_plinks = false; |
| 8146 | |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 8147 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 8148 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
| 8149 | if (err) |
| 8150 | return err; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 8151 | } else { |
| 8152 | /* cfg80211_join_mesh() will sort it out */ |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 8153 | setup.chandef.chan = NULL; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 8154 | } |
| 8155 | |
Ashok Nagarajan | ffb3cf3 | 2013-06-03 10:33:36 -0700 | [diff] [blame] | 8156 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 8157 | u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 8158 | int n_rates = |
| 8159 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 8160 | struct ieee80211_supported_band *sband; |
| 8161 | |
| 8162 | if (!setup.chandef.chan) |
| 8163 | return -EINVAL; |
| 8164 | |
| 8165 | sband = rdev->wiphy.bands[setup.chandef.chan->band]; |
| 8166 | |
| 8167 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 8168 | &setup.basic_rates); |
| 8169 | if (err) |
| 8170 | return err; |
| 8171 | } |
| 8172 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 8173 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8174 | } |
| 8175 | |
| 8176 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) |
| 8177 | { |
| 8178 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8179 | struct net_device *dev = info->user_ptr[1]; |
| 8180 | |
| 8181 | return cfg80211_leave_mesh(rdev, dev); |
| 8182 | } |
| 8183 | |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 8184 | #ifdef CONFIG_PM |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8185 | static int nl80211_send_wowlan_patterns(struct sk_buff *msg, |
| 8186 | struct cfg80211_registered_device *rdev) |
| 8187 | { |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8188 | struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config; |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8189 | struct nlattr *nl_pats, *nl_pat; |
| 8190 | int i, pat_len; |
| 8191 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8192 | if (!wowlan->n_patterns) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8193 | return 0; |
| 8194 | |
| 8195 | nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN); |
| 8196 | if (!nl_pats) |
| 8197 | return -ENOBUFS; |
| 8198 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8199 | for (i = 0; i < wowlan->n_patterns; i++) { |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8200 | nl_pat = nla_nest_start(msg, i + 1); |
| 8201 | if (!nl_pat) |
| 8202 | return -ENOBUFS; |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8203 | pat_len = wowlan->patterns[i].pattern_len; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8204 | 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] | 8205 | wowlan->patterns[i].mask) || |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8206 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
| 8207 | wowlan->patterns[i].pattern) || |
| 8208 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8209 | wowlan->patterns[i].pkt_offset)) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8210 | return -ENOBUFS; |
| 8211 | nla_nest_end(msg, nl_pat); |
| 8212 | } |
| 8213 | nla_nest_end(msg, nl_pats); |
| 8214 | |
| 8215 | return 0; |
| 8216 | } |
| 8217 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8218 | static int nl80211_send_wowlan_tcp(struct sk_buff *msg, |
| 8219 | struct cfg80211_wowlan_tcp *tcp) |
| 8220 | { |
| 8221 | struct nlattr *nl_tcp; |
| 8222 | |
| 8223 | if (!tcp) |
| 8224 | return 0; |
| 8225 | |
| 8226 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); |
| 8227 | if (!nl_tcp) |
| 8228 | return -ENOBUFS; |
| 8229 | |
| 8230 | if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) || |
| 8231 | nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) || |
| 8232 | nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) || |
| 8233 | nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) || |
| 8234 | nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) || |
| 8235 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 8236 | tcp->payload_len, tcp->payload) || |
| 8237 | nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, |
| 8238 | tcp->data_interval) || |
| 8239 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, |
| 8240 | tcp->wake_len, tcp->wake_data) || |
| 8241 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK, |
| 8242 | DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask)) |
| 8243 | return -ENOBUFS; |
| 8244 | |
| 8245 | if (tcp->payload_seq.len && |
| 8246 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ, |
| 8247 | sizeof(tcp->payload_seq), &tcp->payload_seq)) |
| 8248 | return -ENOBUFS; |
| 8249 | |
| 8250 | if (tcp->payload_tok.len && |
| 8251 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, |
| 8252 | sizeof(tcp->payload_tok) + tcp->tokens_size, |
| 8253 | &tcp->payload_tok)) |
| 8254 | return -ENOBUFS; |
| 8255 | |
Johannes Berg | e248ad3 | 2013-05-16 10:24:28 +0200 | [diff] [blame] | 8256 | nla_nest_end(msg, nl_tcp); |
| 8257 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8258 | return 0; |
| 8259 | } |
| 8260 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8261 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 8262 | { |
| 8263 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8264 | struct sk_buff *msg; |
| 8265 | void *hdr; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8266 | u32 size = NLMSG_DEFAULT_SIZE; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8267 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8268 | if (!rdev->wiphy.wowlan) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8269 | return -EOPNOTSUPP; |
| 8270 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8271 | if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) { |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8272 | /* adjust size to have room for all the data */ |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8273 | size += rdev->wiphy.wowlan_config->tcp->tokens_size + |
| 8274 | rdev->wiphy.wowlan_config->tcp->payload_len + |
| 8275 | rdev->wiphy.wowlan_config->tcp->wake_len + |
| 8276 | rdev->wiphy.wowlan_config->tcp->wake_len / 8; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8277 | } |
| 8278 | |
| 8279 | msg = nlmsg_new(size, GFP_KERNEL); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8280 | if (!msg) |
| 8281 | return -ENOMEM; |
| 8282 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8283 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8284 | NL80211_CMD_GET_WOWLAN); |
| 8285 | if (!hdr) |
| 8286 | goto nla_put_failure; |
| 8287 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8288 | if (rdev->wiphy.wowlan_config) { |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8289 | struct nlattr *nl_wowlan; |
| 8290 | |
| 8291 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
| 8292 | if (!nl_wowlan) |
| 8293 | goto nla_put_failure; |
| 8294 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8295 | if ((rdev->wiphy.wowlan_config->any && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8296 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8297 | (rdev->wiphy.wowlan_config->disconnect && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8298 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8299 | (rdev->wiphy.wowlan_config->magic_pkt && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8300 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8301 | (rdev->wiphy.wowlan_config->gtk_rekey_failure && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8302 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8303 | (rdev->wiphy.wowlan_config->eap_identity_req && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8304 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8305 | (rdev->wiphy.wowlan_config->four_way_handshake && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8306 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8307 | (rdev->wiphy.wowlan_config->rfkill_release && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8308 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 8309 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8310 | |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8311 | if (nl80211_send_wowlan_patterns(msg, rdev)) |
| 8312 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8313 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8314 | if (nl80211_send_wowlan_tcp(msg, |
| 8315 | rdev->wiphy.wowlan_config->tcp)) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8316 | goto nla_put_failure; |
| 8317 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8318 | nla_nest_end(msg, nl_wowlan); |
| 8319 | } |
| 8320 | |
| 8321 | genlmsg_end(msg, hdr); |
| 8322 | return genlmsg_reply(msg, info); |
| 8323 | |
| 8324 | nla_put_failure: |
| 8325 | nlmsg_free(msg); |
| 8326 | return -ENOBUFS; |
| 8327 | } |
| 8328 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8329 | static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev, |
| 8330 | struct nlattr *attr, |
| 8331 | struct cfg80211_wowlan *trig) |
| 8332 | { |
| 8333 | struct nlattr *tb[NUM_NL80211_WOWLAN_TCP]; |
| 8334 | struct cfg80211_wowlan_tcp *cfg; |
| 8335 | struct nl80211_wowlan_tcp_data_token *tok = NULL; |
| 8336 | struct nl80211_wowlan_tcp_data_seq *seq = NULL; |
| 8337 | u32 size; |
| 8338 | u32 data_size, wake_size, tokens_size = 0, wake_mask_size; |
| 8339 | int err, port; |
| 8340 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8341 | if (!rdev->wiphy.wowlan->tcp) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8342 | return -EINVAL; |
| 8343 | |
| 8344 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP, |
| 8345 | nla_data(attr), nla_len(attr), |
| 8346 | nl80211_wowlan_tcp_policy); |
| 8347 | if (err) |
| 8348 | return err; |
| 8349 | |
| 8350 | if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] || |
| 8351 | !tb[NL80211_WOWLAN_TCP_DST_IPV4] || |
| 8352 | !tb[NL80211_WOWLAN_TCP_DST_MAC] || |
| 8353 | !tb[NL80211_WOWLAN_TCP_DST_PORT] || |
| 8354 | !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] || |
| 8355 | !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] || |
| 8356 | !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] || |
| 8357 | !tb[NL80211_WOWLAN_TCP_WAKE_MASK]) |
| 8358 | return -EINVAL; |
| 8359 | |
| 8360 | data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8361 | if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8362 | return -EINVAL; |
| 8363 | |
| 8364 | if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) > |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8365 | rdev->wiphy.wowlan->tcp->data_interval_max || |
Johannes Berg | 723d568 | 2013-02-26 13:56:40 +0100 | [diff] [blame] | 8366 | nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8367 | return -EINVAL; |
| 8368 | |
| 8369 | wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8370 | if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8371 | return -EINVAL; |
| 8372 | |
| 8373 | wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]); |
| 8374 | if (wake_mask_size != DIV_ROUND_UP(wake_size, 8)) |
| 8375 | return -EINVAL; |
| 8376 | |
| 8377 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) { |
| 8378 | u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 8379 | |
| 8380 | tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 8381 | tokens_size = tokln - sizeof(*tok); |
| 8382 | |
| 8383 | if (!tok->len || tokens_size % tok->len) |
| 8384 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8385 | if (!rdev->wiphy.wowlan->tcp->tok) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8386 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8387 | if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8388 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8389 | if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8390 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8391 | if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8392 | return -EINVAL; |
| 8393 | if (tok->offset + tok->len > data_size) |
| 8394 | return -EINVAL; |
| 8395 | } |
| 8396 | |
| 8397 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) { |
| 8398 | seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8399 | if (!rdev->wiphy.wowlan->tcp->seq) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8400 | return -EINVAL; |
| 8401 | if (seq->len == 0 || seq->len > 4) |
| 8402 | return -EINVAL; |
| 8403 | if (seq->len + seq->offset > data_size) |
| 8404 | return -EINVAL; |
| 8405 | } |
| 8406 | |
| 8407 | size = sizeof(*cfg); |
| 8408 | size += data_size; |
| 8409 | size += wake_size + wake_mask_size; |
| 8410 | size += tokens_size; |
| 8411 | |
| 8412 | cfg = kzalloc(size, GFP_KERNEL); |
| 8413 | if (!cfg) |
| 8414 | return -ENOMEM; |
| 8415 | cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]); |
| 8416 | cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]); |
| 8417 | memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]), |
| 8418 | ETH_ALEN); |
| 8419 | if (tb[NL80211_WOWLAN_TCP_SRC_PORT]) |
| 8420 | port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]); |
| 8421 | else |
| 8422 | port = 0; |
| 8423 | #ifdef CONFIG_INET |
| 8424 | /* allocate a socket and port for it and use it */ |
| 8425 | err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM, |
| 8426 | IPPROTO_TCP, &cfg->sock, 1); |
| 8427 | if (err) { |
| 8428 | kfree(cfg); |
| 8429 | return err; |
| 8430 | } |
| 8431 | if (inet_csk_get_port(cfg->sock->sk, port)) { |
| 8432 | sock_release(cfg->sock); |
| 8433 | kfree(cfg); |
| 8434 | return -EADDRINUSE; |
| 8435 | } |
| 8436 | cfg->src_port = inet_sk(cfg->sock->sk)->inet_num; |
| 8437 | #else |
| 8438 | if (!port) { |
| 8439 | kfree(cfg); |
| 8440 | return -EINVAL; |
| 8441 | } |
| 8442 | cfg->src_port = port; |
| 8443 | #endif |
| 8444 | |
| 8445 | cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]); |
| 8446 | cfg->payload_len = data_size; |
| 8447 | cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size; |
| 8448 | memcpy((void *)cfg->payload, |
| 8449 | nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]), |
| 8450 | data_size); |
| 8451 | if (seq) |
| 8452 | cfg->payload_seq = *seq; |
| 8453 | cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]); |
| 8454 | cfg->wake_len = wake_size; |
| 8455 | cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size; |
| 8456 | memcpy((void *)cfg->wake_data, |
| 8457 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]), |
| 8458 | wake_size); |
| 8459 | cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size + |
| 8460 | data_size + wake_size; |
| 8461 | memcpy((void *)cfg->wake_mask, |
| 8462 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]), |
| 8463 | wake_mask_size); |
| 8464 | if (tok) { |
| 8465 | cfg->tokens_size = tokens_size; |
| 8466 | memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size); |
| 8467 | } |
| 8468 | |
| 8469 | trig->tcp = cfg; |
| 8470 | |
| 8471 | return 0; |
| 8472 | } |
| 8473 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8474 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 8475 | { |
| 8476 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8477 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8478 | struct cfg80211_wowlan new_triggers = {}; |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8479 | struct cfg80211_wowlan *ntrig; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8480 | const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8481 | int err, i; |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8482 | bool prev_enabled = rdev->wiphy.wowlan_config; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8483 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8484 | if (!wowlan) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8485 | return -EOPNOTSUPP; |
| 8486 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8487 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) { |
| 8488 | cfg80211_rdev_free_wowlan(rdev); |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8489 | rdev->wiphy.wowlan_config = NULL; |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8490 | goto set_wakeup; |
| 8491 | } |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8492 | |
| 8493 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG, |
| 8494 | nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 8495 | nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 8496 | nl80211_wowlan_policy); |
| 8497 | if (err) |
| 8498 | return err; |
| 8499 | |
| 8500 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { |
| 8501 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) |
| 8502 | return -EINVAL; |
| 8503 | new_triggers.any = true; |
| 8504 | } |
| 8505 | |
| 8506 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { |
| 8507 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) |
| 8508 | return -EINVAL; |
| 8509 | new_triggers.disconnect = true; |
| 8510 | } |
| 8511 | |
| 8512 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { |
| 8513 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) |
| 8514 | return -EINVAL; |
| 8515 | new_triggers.magic_pkt = true; |
| 8516 | } |
| 8517 | |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 8518 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
| 8519 | return -EINVAL; |
| 8520 | |
| 8521 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { |
| 8522 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) |
| 8523 | return -EINVAL; |
| 8524 | new_triggers.gtk_rekey_failure = true; |
| 8525 | } |
| 8526 | |
| 8527 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { |
| 8528 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) |
| 8529 | return -EINVAL; |
| 8530 | new_triggers.eap_identity_req = true; |
| 8531 | } |
| 8532 | |
| 8533 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { |
| 8534 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) |
| 8535 | return -EINVAL; |
| 8536 | new_triggers.four_way_handshake = true; |
| 8537 | } |
| 8538 | |
| 8539 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { |
| 8540 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) |
| 8541 | return -EINVAL; |
| 8542 | new_triggers.rfkill_release = true; |
| 8543 | } |
| 8544 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8545 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
| 8546 | struct nlattr *pat; |
| 8547 | int n_patterns = 0; |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8548 | int rem, pat_len, mask_len, pkt_offset; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8549 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8550 | |
| 8551 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 8552 | rem) |
| 8553 | n_patterns++; |
| 8554 | if (n_patterns > wowlan->n_patterns) |
| 8555 | return -EINVAL; |
| 8556 | |
| 8557 | new_triggers.patterns = kcalloc(n_patterns, |
| 8558 | sizeof(new_triggers.patterns[0]), |
| 8559 | GFP_KERNEL); |
| 8560 | if (!new_triggers.patterns) |
| 8561 | return -ENOMEM; |
| 8562 | |
| 8563 | new_triggers.n_patterns = n_patterns; |
| 8564 | i = 0; |
| 8565 | |
| 8566 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 8567 | rem) { |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 8568 | u8 *mask_pat; |
| 8569 | |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8570 | nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat), |
| 8571 | nla_len(pat), NULL); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8572 | err = -EINVAL; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8573 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
| 8574 | !pat_tb[NL80211_PKTPAT_PATTERN]) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8575 | goto error; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8576 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8577 | mask_len = DIV_ROUND_UP(pat_len, 8); |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8578 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8579 | goto error; |
| 8580 | if (pat_len > wowlan->pattern_max_len || |
| 8581 | pat_len < wowlan->pattern_min_len) |
| 8582 | goto error; |
| 8583 | |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8584 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8585 | pkt_offset = 0; |
| 8586 | else |
| 8587 | pkt_offset = nla_get_u32( |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8588 | pat_tb[NL80211_PKTPAT_OFFSET]); |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8589 | if (pkt_offset > wowlan->max_pkt_offset) |
| 8590 | goto error; |
| 8591 | new_triggers.patterns[i].pkt_offset = pkt_offset; |
| 8592 | |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 8593 | mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 8594 | if (!mask_pat) { |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8595 | err = -ENOMEM; |
| 8596 | goto error; |
| 8597 | } |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 8598 | new_triggers.patterns[i].mask = mask_pat; |
| 8599 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]), |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8600 | mask_len); |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 8601 | mask_pat += mask_len; |
| 8602 | new_triggers.patterns[i].pattern = mask_pat; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8603 | new_triggers.patterns[i].pattern_len = pat_len; |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 8604 | memcpy(mask_pat, |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8605 | nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8606 | pat_len); |
| 8607 | i++; |
| 8608 | } |
| 8609 | } |
| 8610 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8611 | if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) { |
| 8612 | err = nl80211_parse_wowlan_tcp( |
| 8613 | rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION], |
| 8614 | &new_triggers); |
| 8615 | if (err) |
| 8616 | goto error; |
| 8617 | } |
| 8618 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8619 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL); |
| 8620 | if (!ntrig) { |
| 8621 | err = -ENOMEM; |
| 8622 | goto error; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8623 | } |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8624 | cfg80211_rdev_free_wowlan(rdev); |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8625 | rdev->wiphy.wowlan_config = ntrig; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8626 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8627 | set_wakeup: |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8628 | if (rdev->ops->set_wakeup && |
| 8629 | prev_enabled != !!rdev->wiphy.wowlan_config) |
| 8630 | rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config); |
Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame] | 8631 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8632 | return 0; |
| 8633 | error: |
| 8634 | for (i = 0; i < new_triggers.n_patterns; i++) |
| 8635 | kfree(new_triggers.patterns[i].mask); |
| 8636 | kfree(new_triggers.patterns); |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8637 | if (new_triggers.tcp && new_triggers.tcp->sock) |
| 8638 | sock_release(new_triggers.tcp->sock); |
| 8639 | kfree(new_triggers.tcp); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8640 | return err; |
| 8641 | } |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 8642 | #endif |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8643 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 8644 | static int nl80211_send_coalesce_rules(struct sk_buff *msg, |
| 8645 | struct cfg80211_registered_device *rdev) |
| 8646 | { |
| 8647 | struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules; |
| 8648 | int i, j, pat_len; |
| 8649 | struct cfg80211_coalesce_rules *rule; |
| 8650 | |
| 8651 | if (!rdev->coalesce->n_rules) |
| 8652 | return 0; |
| 8653 | |
| 8654 | nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE); |
| 8655 | if (!nl_rules) |
| 8656 | return -ENOBUFS; |
| 8657 | |
| 8658 | for (i = 0; i < rdev->coalesce->n_rules; i++) { |
| 8659 | nl_rule = nla_nest_start(msg, i + 1); |
| 8660 | if (!nl_rule) |
| 8661 | return -ENOBUFS; |
| 8662 | |
| 8663 | rule = &rdev->coalesce->rules[i]; |
| 8664 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY, |
| 8665 | rule->delay)) |
| 8666 | return -ENOBUFS; |
| 8667 | |
| 8668 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION, |
| 8669 | rule->condition)) |
| 8670 | return -ENOBUFS; |
| 8671 | |
| 8672 | nl_pats = nla_nest_start(msg, |
| 8673 | NL80211_ATTR_COALESCE_RULE_PKT_PATTERN); |
| 8674 | if (!nl_pats) |
| 8675 | return -ENOBUFS; |
| 8676 | |
| 8677 | for (j = 0; j < rule->n_patterns; j++) { |
| 8678 | nl_pat = nla_nest_start(msg, j + 1); |
| 8679 | if (!nl_pat) |
| 8680 | return -ENOBUFS; |
| 8681 | pat_len = rule->patterns[j].pattern_len; |
| 8682 | if (nla_put(msg, NL80211_PKTPAT_MASK, |
| 8683 | DIV_ROUND_UP(pat_len, 8), |
| 8684 | rule->patterns[j].mask) || |
| 8685 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
| 8686 | rule->patterns[j].pattern) || |
| 8687 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, |
| 8688 | rule->patterns[j].pkt_offset)) |
| 8689 | return -ENOBUFS; |
| 8690 | nla_nest_end(msg, nl_pat); |
| 8691 | } |
| 8692 | nla_nest_end(msg, nl_pats); |
| 8693 | nla_nest_end(msg, nl_rule); |
| 8694 | } |
| 8695 | nla_nest_end(msg, nl_rules); |
| 8696 | |
| 8697 | return 0; |
| 8698 | } |
| 8699 | |
| 8700 | static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info) |
| 8701 | { |
| 8702 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8703 | struct sk_buff *msg; |
| 8704 | void *hdr; |
| 8705 | |
| 8706 | if (!rdev->wiphy.coalesce) |
| 8707 | return -EOPNOTSUPP; |
| 8708 | |
| 8709 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 8710 | if (!msg) |
| 8711 | return -ENOMEM; |
| 8712 | |
| 8713 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 8714 | NL80211_CMD_GET_COALESCE); |
| 8715 | if (!hdr) |
| 8716 | goto nla_put_failure; |
| 8717 | |
| 8718 | if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev)) |
| 8719 | goto nla_put_failure; |
| 8720 | |
| 8721 | genlmsg_end(msg, hdr); |
| 8722 | return genlmsg_reply(msg, info); |
| 8723 | |
| 8724 | nla_put_failure: |
| 8725 | nlmsg_free(msg); |
| 8726 | return -ENOBUFS; |
| 8727 | } |
| 8728 | |
| 8729 | void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev) |
| 8730 | { |
| 8731 | struct cfg80211_coalesce *coalesce = rdev->coalesce; |
| 8732 | int i, j; |
| 8733 | struct cfg80211_coalesce_rules *rule; |
| 8734 | |
| 8735 | if (!coalesce) |
| 8736 | return; |
| 8737 | |
| 8738 | for (i = 0; i < coalesce->n_rules; i++) { |
| 8739 | rule = &coalesce->rules[i]; |
| 8740 | for (j = 0; j < rule->n_patterns; j++) |
| 8741 | kfree(rule->patterns[j].mask); |
| 8742 | kfree(rule->patterns); |
| 8743 | } |
| 8744 | kfree(coalesce->rules); |
| 8745 | kfree(coalesce); |
| 8746 | rdev->coalesce = NULL; |
| 8747 | } |
| 8748 | |
| 8749 | static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev, |
| 8750 | struct nlattr *rule, |
| 8751 | struct cfg80211_coalesce_rules *new_rule) |
| 8752 | { |
| 8753 | int err, i; |
| 8754 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; |
| 8755 | struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat; |
| 8756 | int rem, pat_len, mask_len, pkt_offset, n_patterns = 0; |
| 8757 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
| 8758 | |
| 8759 | err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule), |
| 8760 | nla_len(rule), nl80211_coalesce_policy); |
| 8761 | if (err) |
| 8762 | return err; |
| 8763 | |
| 8764 | if (tb[NL80211_ATTR_COALESCE_RULE_DELAY]) |
| 8765 | new_rule->delay = |
| 8766 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]); |
| 8767 | if (new_rule->delay > coalesce->max_delay) |
| 8768 | return -EINVAL; |
| 8769 | |
| 8770 | if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION]) |
| 8771 | new_rule->condition = |
| 8772 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]); |
| 8773 | if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH && |
| 8774 | new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH) |
| 8775 | return -EINVAL; |
| 8776 | |
| 8777 | if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN]) |
| 8778 | return -EINVAL; |
| 8779 | |
| 8780 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], |
| 8781 | rem) |
| 8782 | n_patterns++; |
| 8783 | if (n_patterns > coalesce->n_patterns) |
| 8784 | return -EINVAL; |
| 8785 | |
| 8786 | new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]), |
| 8787 | GFP_KERNEL); |
| 8788 | if (!new_rule->patterns) |
| 8789 | return -ENOMEM; |
| 8790 | |
| 8791 | new_rule->n_patterns = n_patterns; |
| 8792 | i = 0; |
| 8793 | |
| 8794 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], |
| 8795 | rem) { |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 8796 | u8 *mask_pat; |
| 8797 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 8798 | nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat), |
| 8799 | nla_len(pat), NULL); |
| 8800 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
| 8801 | !pat_tb[NL80211_PKTPAT_PATTERN]) |
| 8802 | return -EINVAL; |
| 8803 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
| 8804 | mask_len = DIV_ROUND_UP(pat_len, 8); |
| 8805 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
| 8806 | return -EINVAL; |
| 8807 | if (pat_len > coalesce->pattern_max_len || |
| 8808 | pat_len < coalesce->pattern_min_len) |
| 8809 | return -EINVAL; |
| 8810 | |
| 8811 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
| 8812 | pkt_offset = 0; |
| 8813 | else |
| 8814 | pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]); |
| 8815 | if (pkt_offset > coalesce->max_pkt_offset) |
| 8816 | return -EINVAL; |
| 8817 | new_rule->patterns[i].pkt_offset = pkt_offset; |
| 8818 | |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 8819 | mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 8820 | if (!mask_pat) |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 8821 | return -ENOMEM; |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 8822 | |
| 8823 | new_rule->patterns[i].mask = mask_pat; |
| 8824 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]), |
| 8825 | mask_len); |
| 8826 | |
| 8827 | mask_pat += mask_len; |
| 8828 | new_rule->patterns[i].pattern = mask_pat; |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 8829 | new_rule->patterns[i].pattern_len = pat_len; |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 8830 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
| 8831 | pat_len); |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 8832 | i++; |
| 8833 | } |
| 8834 | |
| 8835 | return 0; |
| 8836 | } |
| 8837 | |
| 8838 | static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info) |
| 8839 | { |
| 8840 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8841 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; |
| 8842 | struct cfg80211_coalesce new_coalesce = {}; |
| 8843 | struct cfg80211_coalesce *n_coalesce; |
| 8844 | int err, rem_rule, n_rules = 0, i, j; |
| 8845 | struct nlattr *rule; |
| 8846 | struct cfg80211_coalesce_rules *tmp_rule; |
| 8847 | |
| 8848 | if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce) |
| 8849 | return -EOPNOTSUPP; |
| 8850 | |
| 8851 | if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) { |
| 8852 | cfg80211_rdev_free_coalesce(rdev); |
| 8853 | rdev->ops->set_coalesce(&rdev->wiphy, NULL); |
| 8854 | return 0; |
| 8855 | } |
| 8856 | |
| 8857 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], |
| 8858 | rem_rule) |
| 8859 | n_rules++; |
| 8860 | if (n_rules > coalesce->n_rules) |
| 8861 | return -EINVAL; |
| 8862 | |
| 8863 | new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]), |
| 8864 | GFP_KERNEL); |
| 8865 | if (!new_coalesce.rules) |
| 8866 | return -ENOMEM; |
| 8867 | |
| 8868 | new_coalesce.n_rules = n_rules; |
| 8869 | i = 0; |
| 8870 | |
| 8871 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], |
| 8872 | rem_rule) { |
| 8873 | err = nl80211_parse_coalesce_rule(rdev, rule, |
| 8874 | &new_coalesce.rules[i]); |
| 8875 | if (err) |
| 8876 | goto error; |
| 8877 | |
| 8878 | i++; |
| 8879 | } |
| 8880 | |
| 8881 | err = rdev->ops->set_coalesce(&rdev->wiphy, &new_coalesce); |
| 8882 | if (err) |
| 8883 | goto error; |
| 8884 | |
| 8885 | n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL); |
| 8886 | if (!n_coalesce) { |
| 8887 | err = -ENOMEM; |
| 8888 | goto error; |
| 8889 | } |
| 8890 | cfg80211_rdev_free_coalesce(rdev); |
| 8891 | rdev->coalesce = n_coalesce; |
| 8892 | |
| 8893 | return 0; |
| 8894 | error: |
| 8895 | for (i = 0; i < new_coalesce.n_rules; i++) { |
| 8896 | tmp_rule = &new_coalesce.rules[i]; |
| 8897 | for (j = 0; j < tmp_rule->n_patterns; j++) |
| 8898 | kfree(tmp_rule->patterns[j].mask); |
| 8899 | kfree(tmp_rule->patterns); |
| 8900 | } |
| 8901 | kfree(new_coalesce.rules); |
| 8902 | |
| 8903 | return err; |
| 8904 | } |
| 8905 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 8906 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
| 8907 | { |
| 8908 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8909 | struct net_device *dev = info->user_ptr[1]; |
| 8910 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 8911 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; |
| 8912 | struct cfg80211_gtk_rekey_data rekey_data; |
| 8913 | int err; |
| 8914 | |
| 8915 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) |
| 8916 | return -EINVAL; |
| 8917 | |
| 8918 | err = nla_parse(tb, MAX_NL80211_REKEY_DATA, |
| 8919 | nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 8920 | nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 8921 | nl80211_rekey_policy); |
| 8922 | if (err) |
| 8923 | return err; |
| 8924 | |
| 8925 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) |
| 8926 | return -ERANGE; |
| 8927 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) |
| 8928 | return -ERANGE; |
| 8929 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) |
| 8930 | return -ERANGE; |
| 8931 | |
| 8932 | memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]), |
| 8933 | NL80211_KEK_LEN); |
| 8934 | memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]), |
| 8935 | NL80211_KCK_LEN); |
| 8936 | memcpy(rekey_data.replay_ctr, |
| 8937 | nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]), |
| 8938 | NL80211_REPLAY_CTR_LEN); |
| 8939 | |
| 8940 | wdev_lock(wdev); |
| 8941 | if (!wdev->current_bss) { |
| 8942 | err = -ENOTCONN; |
| 8943 | goto out; |
| 8944 | } |
| 8945 | |
| 8946 | if (!rdev->ops->set_rekey_data) { |
| 8947 | err = -EOPNOTSUPP; |
| 8948 | goto out; |
| 8949 | } |
| 8950 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8951 | err = rdev_set_rekey_data(rdev, dev, &rekey_data); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 8952 | out: |
| 8953 | wdev_unlock(wdev); |
| 8954 | return err; |
| 8955 | } |
| 8956 | |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8957 | static int nl80211_register_unexpected_frame(struct sk_buff *skb, |
| 8958 | struct genl_info *info) |
| 8959 | { |
| 8960 | struct net_device *dev = info->user_ptr[1]; |
| 8961 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 8962 | |
| 8963 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 8964 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 8965 | return -EINVAL; |
| 8966 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8967 | if (wdev->ap_unexpected_nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8968 | return -EBUSY; |
| 8969 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8970 | wdev->ap_unexpected_nlportid = info->snd_portid; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8971 | return 0; |
| 8972 | } |
| 8973 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8974 | static int nl80211_probe_client(struct sk_buff *skb, |
| 8975 | struct genl_info *info) |
| 8976 | { |
| 8977 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8978 | struct net_device *dev = info->user_ptr[1]; |
| 8979 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 8980 | struct sk_buff *msg; |
| 8981 | void *hdr; |
| 8982 | const u8 *addr; |
| 8983 | u64 cookie; |
| 8984 | int err; |
| 8985 | |
| 8986 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 8987 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 8988 | return -EOPNOTSUPP; |
| 8989 | |
| 8990 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 8991 | return -EINVAL; |
| 8992 | |
| 8993 | if (!rdev->ops->probe_client) |
| 8994 | return -EOPNOTSUPP; |
| 8995 | |
| 8996 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 8997 | if (!msg) |
| 8998 | return -ENOMEM; |
| 8999 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9000 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9001 | NL80211_CMD_PROBE_CLIENT); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 9002 | if (!hdr) { |
| 9003 | err = -ENOBUFS; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9004 | goto free_msg; |
| 9005 | } |
| 9006 | |
| 9007 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 9008 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 9009 | err = rdev_probe_client(rdev, dev, addr, &cookie); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9010 | if (err) |
| 9011 | goto free_msg; |
| 9012 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9013 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 9014 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9015 | |
| 9016 | genlmsg_end(msg, hdr); |
| 9017 | |
| 9018 | return genlmsg_reply(msg, info); |
| 9019 | |
| 9020 | nla_put_failure: |
| 9021 | err = -ENOBUFS; |
| 9022 | free_msg: |
| 9023 | nlmsg_free(msg); |
| 9024 | return err; |
| 9025 | } |
| 9026 | |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9027 | static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) |
| 9028 | { |
| 9029 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9030 | struct cfg80211_beacon_registration *reg, *nreg; |
| 9031 | int rv; |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9032 | |
| 9033 | if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) |
| 9034 | return -EOPNOTSUPP; |
| 9035 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9036 | nreg = kzalloc(sizeof(*nreg), GFP_KERNEL); |
| 9037 | if (!nreg) |
| 9038 | return -ENOMEM; |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9039 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9040 | /* First, check if already registered. */ |
| 9041 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 9042 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 9043 | if (reg->nlportid == info->snd_portid) { |
| 9044 | rv = -EALREADY; |
| 9045 | goto out_err; |
| 9046 | } |
| 9047 | } |
| 9048 | /* Add it to the list */ |
| 9049 | nreg->nlportid = info->snd_portid; |
| 9050 | list_add(&nreg->list, &rdev->beacon_registrations); |
| 9051 | |
| 9052 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9053 | |
| 9054 | return 0; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9055 | out_err: |
| 9056 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 9057 | kfree(nreg); |
| 9058 | return rv; |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9059 | } |
| 9060 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9061 | static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 9062 | { |
| 9063 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9064 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 9065 | int err; |
| 9066 | |
| 9067 | if (!rdev->ops->start_p2p_device) |
| 9068 | return -EOPNOTSUPP; |
| 9069 | |
| 9070 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 9071 | return -EOPNOTSUPP; |
| 9072 | |
| 9073 | if (wdev->p2p_started) |
| 9074 | return 0; |
| 9075 | |
Luciano Coelho | b6a5501 | 2014-02-27 11:07:21 +0200 | [diff] [blame] | 9076 | if (rfkill_blocked(rdev->rfkill)) |
| 9077 | return -ERFKILL; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9078 | |
Johannes Berg | eeb126e | 2012-10-23 15:16:50 +0200 | [diff] [blame] | 9079 | err = rdev_start_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9080 | if (err) |
| 9081 | return err; |
| 9082 | |
| 9083 | wdev->p2p_started = true; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9084 | rdev->opencount++; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9085 | |
| 9086 | return 0; |
| 9087 | } |
| 9088 | |
| 9089 | static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 9090 | { |
| 9091 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9092 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 9093 | |
| 9094 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 9095 | return -EOPNOTSUPP; |
| 9096 | |
| 9097 | if (!rdev->ops->stop_p2p_device) |
| 9098 | return -EOPNOTSUPP; |
| 9099 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 9100 | cfg80211_stop_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9101 | |
| 9102 | return 0; |
| 9103 | } |
| 9104 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 9105 | static int nl80211_get_protocol_features(struct sk_buff *skb, |
| 9106 | struct genl_info *info) |
| 9107 | { |
| 9108 | void *hdr; |
| 9109 | struct sk_buff *msg; |
| 9110 | |
| 9111 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 9112 | if (!msg) |
| 9113 | return -ENOMEM; |
| 9114 | |
| 9115 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 9116 | NL80211_CMD_GET_PROTOCOL_FEATURES); |
| 9117 | if (!hdr) |
| 9118 | goto nla_put_failure; |
| 9119 | |
| 9120 | if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES, |
| 9121 | NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)) |
| 9122 | goto nla_put_failure; |
| 9123 | |
| 9124 | genlmsg_end(msg, hdr); |
| 9125 | return genlmsg_reply(msg, info); |
| 9126 | |
| 9127 | nla_put_failure: |
| 9128 | kfree_skb(msg); |
| 9129 | return -ENOBUFS; |
| 9130 | } |
| 9131 | |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 9132 | static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info) |
| 9133 | { |
| 9134 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9135 | struct cfg80211_update_ft_ies_params ft_params; |
| 9136 | struct net_device *dev = info->user_ptr[1]; |
| 9137 | |
| 9138 | if (!rdev->ops->update_ft_ies) |
| 9139 | return -EOPNOTSUPP; |
| 9140 | |
| 9141 | if (!info->attrs[NL80211_ATTR_MDID] || |
| 9142 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 9143 | return -EINVAL; |
| 9144 | |
| 9145 | memset(&ft_params, 0, sizeof(ft_params)); |
| 9146 | ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]); |
| 9147 | ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 9148 | ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 9149 | |
| 9150 | return rdev_update_ft_ies(rdev, dev, &ft_params); |
| 9151 | } |
| 9152 | |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 9153 | static int nl80211_crit_protocol_start(struct sk_buff *skb, |
| 9154 | struct genl_info *info) |
| 9155 | { |
| 9156 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9157 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 9158 | enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC; |
| 9159 | u16 duration; |
| 9160 | int ret; |
| 9161 | |
| 9162 | if (!rdev->ops->crit_proto_start) |
| 9163 | return -EOPNOTSUPP; |
| 9164 | |
| 9165 | if (WARN_ON(!rdev->ops->crit_proto_stop)) |
| 9166 | return -EINVAL; |
| 9167 | |
| 9168 | if (rdev->crit_proto_nlportid) |
| 9169 | return -EBUSY; |
| 9170 | |
| 9171 | /* determine protocol if provided */ |
| 9172 | if (info->attrs[NL80211_ATTR_CRIT_PROT_ID]) |
| 9173 | proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]); |
| 9174 | |
| 9175 | if (proto >= NUM_NL80211_CRIT_PROTO) |
| 9176 | return -EINVAL; |
| 9177 | |
| 9178 | /* timeout must be provided */ |
| 9179 | if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]) |
| 9180 | return -EINVAL; |
| 9181 | |
| 9182 | duration = |
| 9183 | nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]); |
| 9184 | |
| 9185 | if (duration > NL80211_CRIT_PROTO_MAX_DURATION) |
| 9186 | return -ERANGE; |
| 9187 | |
| 9188 | ret = rdev_crit_proto_start(rdev, wdev, proto, duration); |
| 9189 | if (!ret) |
| 9190 | rdev->crit_proto_nlportid = info->snd_portid; |
| 9191 | |
| 9192 | return ret; |
| 9193 | } |
| 9194 | |
| 9195 | static int nl80211_crit_protocol_stop(struct sk_buff *skb, |
| 9196 | struct genl_info *info) |
| 9197 | { |
| 9198 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9199 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 9200 | |
| 9201 | if (!rdev->ops->crit_proto_stop) |
| 9202 | return -EOPNOTSUPP; |
| 9203 | |
| 9204 | if (rdev->crit_proto_nlportid) { |
| 9205 | rdev->crit_proto_nlportid = 0; |
| 9206 | rdev_crit_proto_stop(rdev, wdev); |
| 9207 | } |
| 9208 | return 0; |
| 9209 | } |
| 9210 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 9211 | static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info) |
| 9212 | { |
| 9213 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9214 | struct wireless_dev *wdev = |
| 9215 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); |
| 9216 | int i, err; |
| 9217 | u32 vid, subcmd; |
| 9218 | |
| 9219 | if (!rdev->wiphy.vendor_commands) |
| 9220 | return -EOPNOTSUPP; |
| 9221 | |
| 9222 | if (IS_ERR(wdev)) { |
| 9223 | err = PTR_ERR(wdev); |
| 9224 | if (err != -EINVAL) |
| 9225 | return err; |
| 9226 | wdev = NULL; |
| 9227 | } else if (wdev->wiphy != &rdev->wiphy) { |
| 9228 | return -EINVAL; |
| 9229 | } |
| 9230 | |
| 9231 | if (!info->attrs[NL80211_ATTR_VENDOR_ID] || |
| 9232 | !info->attrs[NL80211_ATTR_VENDOR_SUBCMD]) |
| 9233 | return -EINVAL; |
| 9234 | |
| 9235 | vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]); |
| 9236 | subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]); |
| 9237 | for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { |
| 9238 | const struct wiphy_vendor_command *vcmd; |
| 9239 | void *data = NULL; |
| 9240 | int len = 0; |
| 9241 | |
| 9242 | vcmd = &rdev->wiphy.vendor_commands[i]; |
| 9243 | |
| 9244 | if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd) |
| 9245 | continue; |
| 9246 | |
| 9247 | if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV | |
| 9248 | WIPHY_VENDOR_CMD_NEED_NETDEV)) { |
| 9249 | if (!wdev) |
| 9250 | return -EINVAL; |
| 9251 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV && |
| 9252 | !wdev->netdev) |
| 9253 | return -EINVAL; |
| 9254 | |
| 9255 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) { |
| 9256 | if (wdev->netdev && |
| 9257 | !netif_running(wdev->netdev)) |
| 9258 | return -ENETDOWN; |
| 9259 | if (!wdev->netdev && !wdev->p2p_started) |
| 9260 | return -ENETDOWN; |
| 9261 | } |
| 9262 | } else { |
| 9263 | wdev = NULL; |
| 9264 | } |
| 9265 | |
| 9266 | if (info->attrs[NL80211_ATTR_VENDOR_DATA]) { |
| 9267 | data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]); |
| 9268 | len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]); |
| 9269 | } |
| 9270 | |
| 9271 | rdev->cur_cmd_info = info; |
| 9272 | err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev, |
| 9273 | data, len); |
| 9274 | rdev->cur_cmd_info = NULL; |
| 9275 | return err; |
| 9276 | } |
| 9277 | |
| 9278 | return -EOPNOTSUPP; |
| 9279 | } |
| 9280 | |
| 9281 | struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy, |
| 9282 | enum nl80211_commands cmd, |
| 9283 | enum nl80211_attrs attr, |
| 9284 | int approxlen) |
| 9285 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 9286 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 9287 | |
| 9288 | if (WARN_ON(!rdev->cur_cmd_info)) |
| 9289 | return NULL; |
| 9290 | |
| 9291 | return __cfg80211_alloc_vendor_skb(rdev, approxlen, |
| 9292 | rdev->cur_cmd_info->snd_portid, |
| 9293 | rdev->cur_cmd_info->snd_seq, |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 9294 | cmd, attr, NULL, GFP_KERNEL); |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 9295 | } |
| 9296 | EXPORT_SYMBOL(__cfg80211_alloc_reply_skb); |
| 9297 | |
| 9298 | int cfg80211_vendor_cmd_reply(struct sk_buff *skb) |
| 9299 | { |
| 9300 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 9301 | void *hdr = ((void **)skb->cb)[1]; |
| 9302 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 9303 | |
| 9304 | if (WARN_ON(!rdev->cur_cmd_info)) { |
| 9305 | kfree_skb(skb); |
| 9306 | return -EINVAL; |
| 9307 | } |
| 9308 | |
| 9309 | nla_nest_end(skb, data); |
| 9310 | genlmsg_end(skb, hdr); |
| 9311 | return genlmsg_reply(skb, rdev->cur_cmd_info); |
| 9312 | } |
| 9313 | EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply); |
| 9314 | |
| 9315 | |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 9316 | static int nl80211_set_qos_map(struct sk_buff *skb, |
| 9317 | struct genl_info *info) |
| 9318 | { |
| 9319 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9320 | struct cfg80211_qos_map *qos_map = NULL; |
| 9321 | struct net_device *dev = info->user_ptr[1]; |
| 9322 | u8 *pos, len, num_des, des_len, des; |
| 9323 | int ret; |
| 9324 | |
| 9325 | if (!rdev->ops->set_qos_map) |
| 9326 | return -EOPNOTSUPP; |
| 9327 | |
| 9328 | if (info->attrs[NL80211_ATTR_QOS_MAP]) { |
| 9329 | pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]); |
| 9330 | len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]); |
| 9331 | |
| 9332 | if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN || |
| 9333 | len > IEEE80211_QOS_MAP_LEN_MAX) |
| 9334 | return -EINVAL; |
| 9335 | |
| 9336 | qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL); |
| 9337 | if (!qos_map) |
| 9338 | return -ENOMEM; |
| 9339 | |
| 9340 | num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1; |
| 9341 | if (num_des) { |
| 9342 | des_len = num_des * |
| 9343 | sizeof(struct cfg80211_dscp_exception); |
| 9344 | memcpy(qos_map->dscp_exception, pos, des_len); |
| 9345 | qos_map->num_des = num_des; |
| 9346 | for (des = 0; des < num_des; des++) { |
| 9347 | if (qos_map->dscp_exception[des].up > 7) { |
| 9348 | kfree(qos_map); |
| 9349 | return -EINVAL; |
| 9350 | } |
| 9351 | } |
| 9352 | pos += des_len; |
| 9353 | } |
| 9354 | memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN); |
| 9355 | } |
| 9356 | |
| 9357 | wdev_lock(dev->ieee80211_ptr); |
| 9358 | ret = nl80211_key_allowed(dev->ieee80211_ptr); |
| 9359 | if (!ret) |
| 9360 | ret = rdev_set_qos_map(rdev, dev, qos_map); |
| 9361 | wdev_unlock(dev->ieee80211_ptr); |
| 9362 | |
| 9363 | kfree(qos_map); |
| 9364 | return ret; |
| 9365 | } |
| 9366 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9367 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
| 9368 | #define NL80211_FLAG_NEED_NETDEV 0x02 |
| 9369 | #define NL80211_FLAG_NEED_RTNL 0x04 |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9370 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
| 9371 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ |
| 9372 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 9373 | #define NL80211_FLAG_NEED_WDEV 0x10 |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9374 | /* 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] | 9375 | #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\ |
| 9376 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9377 | |
Johannes Berg | f84f771 | 2013-11-14 17:14:45 +0100 | [diff] [blame] | 9378 | 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] | 9379 | struct genl_info *info) |
| 9380 | { |
| 9381 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 9382 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9383 | struct net_device *dev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9384 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
| 9385 | |
| 9386 | if (rtnl) |
| 9387 | rtnl_lock(); |
| 9388 | |
| 9389 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 9390 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9391 | if (IS_ERR(rdev)) { |
| 9392 | if (rtnl) |
| 9393 | rtnl_unlock(); |
| 9394 | return PTR_ERR(rdev); |
| 9395 | } |
| 9396 | info->user_ptr[0] = rdev; |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 9397 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV || |
| 9398 | ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 9399 | ASSERT_RTNL(); |
| 9400 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 9401 | wdev = __cfg80211_wdev_from_attrs(genl_info_net(info), |
| 9402 | info->attrs); |
| 9403 | if (IS_ERR(wdev)) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9404 | if (rtnl) |
| 9405 | rtnl_unlock(); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 9406 | return PTR_ERR(wdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9407 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 9408 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 9409 | dev = wdev->netdev; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 9410 | rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 9411 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 9412 | if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
| 9413 | if (!dev) { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 9414 | if (rtnl) |
| 9415 | rtnl_unlock(); |
| 9416 | return -EINVAL; |
| 9417 | } |
| 9418 | |
| 9419 | info->user_ptr[1] = dev; |
| 9420 | } else { |
| 9421 | info->user_ptr[1] = wdev; |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9422 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 9423 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 9424 | if (dev) { |
| 9425 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && |
| 9426 | !netif_running(dev)) { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 9427 | if (rtnl) |
| 9428 | rtnl_unlock(); |
| 9429 | return -ENETDOWN; |
| 9430 | } |
| 9431 | |
| 9432 | dev_hold(dev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9433 | } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) { |
| 9434 | if (!wdev->p2p_started) { |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9435 | if (rtnl) |
| 9436 | rtnl_unlock(); |
| 9437 | return -ENETDOWN; |
| 9438 | } |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 9439 | } |
| 9440 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9441 | info->user_ptr[0] = rdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9442 | } |
| 9443 | |
| 9444 | return 0; |
| 9445 | } |
| 9446 | |
Johannes Berg | f84f771 | 2013-11-14 17:14:45 +0100 | [diff] [blame] | 9447 | 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] | 9448 | struct genl_info *info) |
| 9449 | { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 9450 | if (info->user_ptr[1]) { |
| 9451 | if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
| 9452 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 9453 | |
| 9454 | if (wdev->netdev) |
| 9455 | dev_put(wdev->netdev); |
| 9456 | } else { |
| 9457 | dev_put(info->user_ptr[1]); |
| 9458 | } |
| 9459 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9460 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
| 9461 | rtnl_unlock(); |
| 9462 | } |
| 9463 | |
Johannes Berg | 4534de8 | 2013-11-14 17:14:46 +0100 | [diff] [blame] | 9464 | static const struct genl_ops nl80211_ops[] = { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9465 | { |
| 9466 | .cmd = NL80211_CMD_GET_WIPHY, |
| 9467 | .doit = nl80211_get_wiphy, |
| 9468 | .dumpit = nl80211_dump_wiphy, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 9469 | .done = nl80211_dump_wiphy_done, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9470 | .policy = nl80211_policy, |
| 9471 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 9472 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9473 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9474 | }, |
| 9475 | { |
| 9476 | .cmd = NL80211_CMD_SET_WIPHY, |
| 9477 | .doit = nl80211_set_wiphy, |
| 9478 | .policy = nl80211_policy, |
| 9479 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9480 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9481 | }, |
| 9482 | { |
| 9483 | .cmd = NL80211_CMD_GET_INTERFACE, |
| 9484 | .doit = nl80211_get_interface, |
| 9485 | .dumpit = nl80211_dump_interface, |
| 9486 | .policy = nl80211_policy, |
| 9487 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 9488 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 9489 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9490 | }, |
| 9491 | { |
| 9492 | .cmd = NL80211_CMD_SET_INTERFACE, |
| 9493 | .doit = nl80211_set_interface, |
| 9494 | .policy = nl80211_policy, |
| 9495 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9496 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9497 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9498 | }, |
| 9499 | { |
| 9500 | .cmd = NL80211_CMD_NEW_INTERFACE, |
| 9501 | .doit = nl80211_new_interface, |
| 9502 | .policy = nl80211_policy, |
| 9503 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9504 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9505 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9506 | }, |
| 9507 | { |
| 9508 | .cmd = NL80211_CMD_DEL_INTERFACE, |
| 9509 | .doit = nl80211_del_interface, |
| 9510 | .policy = nl80211_policy, |
| 9511 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 9512 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9513 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9514 | }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 9515 | { |
| 9516 | .cmd = NL80211_CMD_GET_KEY, |
| 9517 | .doit = nl80211_get_key, |
| 9518 | .policy = nl80211_policy, |
| 9519 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9520 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9521 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 9522 | }, |
| 9523 | { |
| 9524 | .cmd = NL80211_CMD_SET_KEY, |
| 9525 | .doit = nl80211_set_key, |
| 9526 | .policy = nl80211_policy, |
| 9527 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9528 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9529 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 9530 | }, |
| 9531 | { |
| 9532 | .cmd = NL80211_CMD_NEW_KEY, |
| 9533 | .doit = nl80211_new_key, |
| 9534 | .policy = nl80211_policy, |
| 9535 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9536 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9537 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 9538 | }, |
| 9539 | { |
| 9540 | .cmd = NL80211_CMD_DEL_KEY, |
| 9541 | .doit = nl80211_del_key, |
| 9542 | .policy = nl80211_policy, |
| 9543 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9544 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9545 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 9546 | }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 9547 | { |
| 9548 | .cmd = NL80211_CMD_SET_BEACON, |
| 9549 | .policy = nl80211_policy, |
| 9550 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 9551 | .doit = nl80211_set_beacon, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9552 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9553 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 9554 | }, |
| 9555 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 9556 | .cmd = NL80211_CMD_START_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 9557 | .policy = nl80211_policy, |
| 9558 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 9559 | .doit = nl80211_start_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9560 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9561 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 9562 | }, |
| 9563 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 9564 | .cmd = NL80211_CMD_STOP_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 9565 | .policy = nl80211_policy, |
| 9566 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 9567 | .doit = nl80211_stop_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9568 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9569 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 9570 | }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 9571 | { |
| 9572 | .cmd = NL80211_CMD_GET_STATION, |
| 9573 | .doit = nl80211_get_station, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9574 | .dumpit = nl80211_dump_station, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 9575 | .policy = nl80211_policy, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9576 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9577 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 9578 | }, |
| 9579 | { |
| 9580 | .cmd = NL80211_CMD_SET_STATION, |
| 9581 | .doit = nl80211_set_station, |
| 9582 | .policy = nl80211_policy, |
| 9583 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9584 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9585 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 9586 | }, |
| 9587 | { |
| 9588 | .cmd = NL80211_CMD_NEW_STATION, |
| 9589 | .doit = nl80211_new_station, |
| 9590 | .policy = nl80211_policy, |
| 9591 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9592 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9593 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 9594 | }, |
| 9595 | { |
| 9596 | .cmd = NL80211_CMD_DEL_STATION, |
| 9597 | .doit = nl80211_del_station, |
| 9598 | .policy = nl80211_policy, |
| 9599 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9600 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9601 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 9602 | }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9603 | { |
| 9604 | .cmd = NL80211_CMD_GET_MPATH, |
| 9605 | .doit = nl80211_get_mpath, |
| 9606 | .dumpit = nl80211_dump_mpath, |
| 9607 | .policy = nl80211_policy, |
| 9608 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9609 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9610 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9611 | }, |
| 9612 | { |
| 9613 | .cmd = NL80211_CMD_SET_MPATH, |
| 9614 | .doit = nl80211_set_mpath, |
| 9615 | .policy = nl80211_policy, |
| 9616 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9617 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9618 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9619 | }, |
| 9620 | { |
| 9621 | .cmd = NL80211_CMD_NEW_MPATH, |
| 9622 | .doit = nl80211_new_mpath, |
| 9623 | .policy = nl80211_policy, |
| 9624 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9625 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9626 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9627 | }, |
| 9628 | { |
| 9629 | .cmd = NL80211_CMD_DEL_MPATH, |
| 9630 | .doit = nl80211_del_mpath, |
| 9631 | .policy = nl80211_policy, |
| 9632 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9633 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9634 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9635 | }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 9636 | { |
| 9637 | .cmd = NL80211_CMD_SET_BSS, |
| 9638 | .doit = nl80211_set_bss, |
| 9639 | .policy = nl80211_policy, |
| 9640 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9641 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9642 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 9643 | }, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 9644 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 9645 | .cmd = NL80211_CMD_GET_REG, |
| 9646 | .doit = nl80211_get_reg, |
| 9647 | .policy = nl80211_policy, |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 9648 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 9649 | /* can be retrieved by unprivileged users */ |
| 9650 | }, |
| 9651 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 9652 | .cmd = NL80211_CMD_SET_REG, |
| 9653 | .doit = nl80211_set_reg, |
| 9654 | .policy = nl80211_policy, |
| 9655 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 9656 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 9657 | }, |
| 9658 | { |
| 9659 | .cmd = NL80211_CMD_REQ_SET_REG, |
| 9660 | .doit = nl80211_req_set_reg, |
| 9661 | .policy = nl80211_policy, |
| 9662 | .flags = GENL_ADMIN_PERM, |
| 9663 | }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 9664 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 9665 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
| 9666 | .doit = nl80211_get_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 9667 | .policy = nl80211_policy, |
| 9668 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9669 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9670 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 9671 | }, |
| 9672 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 9673 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
| 9674 | .doit = nl80211_update_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 9675 | .policy = nl80211_policy, |
| 9676 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 9677 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9678 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 9679 | }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 9680 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9681 | .cmd = NL80211_CMD_TRIGGER_SCAN, |
| 9682 | .doit = nl80211_trigger_scan, |
| 9683 | .policy = nl80211_policy, |
| 9684 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9685 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9686 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9687 | }, |
| 9688 | { |
| 9689 | .cmd = NL80211_CMD_GET_SCAN, |
| 9690 | .policy = nl80211_policy, |
| 9691 | .dumpit = nl80211_dump_scan, |
| 9692 | }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9693 | { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9694 | .cmd = NL80211_CMD_START_SCHED_SCAN, |
| 9695 | .doit = nl80211_start_sched_scan, |
| 9696 | .policy = nl80211_policy, |
| 9697 | .flags = GENL_ADMIN_PERM, |
| 9698 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9699 | NL80211_FLAG_NEED_RTNL, |
| 9700 | }, |
| 9701 | { |
| 9702 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, |
| 9703 | .doit = nl80211_stop_sched_scan, |
| 9704 | .policy = nl80211_policy, |
| 9705 | .flags = GENL_ADMIN_PERM, |
| 9706 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9707 | NL80211_FLAG_NEED_RTNL, |
| 9708 | }, |
| 9709 | { |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9710 | .cmd = NL80211_CMD_AUTHENTICATE, |
| 9711 | .doit = nl80211_authenticate, |
| 9712 | .policy = nl80211_policy, |
| 9713 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9714 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9715 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9716 | }, |
| 9717 | { |
| 9718 | .cmd = NL80211_CMD_ASSOCIATE, |
| 9719 | .doit = nl80211_associate, |
| 9720 | .policy = nl80211_policy, |
| 9721 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9722 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9723 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9724 | }, |
| 9725 | { |
| 9726 | .cmd = NL80211_CMD_DEAUTHENTICATE, |
| 9727 | .doit = nl80211_deauthenticate, |
| 9728 | .policy = nl80211_policy, |
| 9729 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9730 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9731 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9732 | }, |
| 9733 | { |
| 9734 | .cmd = NL80211_CMD_DISASSOCIATE, |
| 9735 | .doit = nl80211_disassociate, |
| 9736 | .policy = nl80211_policy, |
| 9737 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9738 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9739 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9740 | }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9741 | { |
| 9742 | .cmd = NL80211_CMD_JOIN_IBSS, |
| 9743 | .doit = nl80211_join_ibss, |
| 9744 | .policy = nl80211_policy, |
| 9745 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9746 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9747 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9748 | }, |
| 9749 | { |
| 9750 | .cmd = NL80211_CMD_LEAVE_IBSS, |
| 9751 | .doit = nl80211_leave_ibss, |
| 9752 | .policy = nl80211_policy, |
| 9753 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9754 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9755 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9756 | }, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 9757 | #ifdef CONFIG_NL80211_TESTMODE |
| 9758 | { |
| 9759 | .cmd = NL80211_CMD_TESTMODE, |
| 9760 | .doit = nl80211_testmode_do, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 9761 | .dumpit = nl80211_testmode_dump, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 9762 | .policy = nl80211_policy, |
| 9763 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9764 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9765 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 9766 | }, |
| 9767 | #endif |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9768 | { |
| 9769 | .cmd = NL80211_CMD_CONNECT, |
| 9770 | .doit = nl80211_connect, |
| 9771 | .policy = nl80211_policy, |
| 9772 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9773 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9774 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9775 | }, |
| 9776 | { |
| 9777 | .cmd = NL80211_CMD_DISCONNECT, |
| 9778 | .doit = nl80211_disconnect, |
| 9779 | .policy = nl80211_policy, |
| 9780 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9781 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9782 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9783 | }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9784 | { |
| 9785 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, |
| 9786 | .doit = nl80211_wiphy_netns, |
| 9787 | .policy = nl80211_policy, |
| 9788 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9789 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9790 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9791 | }, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 9792 | { |
| 9793 | .cmd = NL80211_CMD_GET_SURVEY, |
| 9794 | .policy = nl80211_policy, |
| 9795 | .dumpit = nl80211_dump_survey, |
| 9796 | }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9797 | { |
| 9798 | .cmd = NL80211_CMD_SET_PMKSA, |
| 9799 | .doit = nl80211_setdel_pmksa, |
| 9800 | .policy = nl80211_policy, |
| 9801 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9802 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9803 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9804 | }, |
| 9805 | { |
| 9806 | .cmd = NL80211_CMD_DEL_PMKSA, |
| 9807 | .doit = nl80211_setdel_pmksa, |
| 9808 | .policy = nl80211_policy, |
| 9809 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9810 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9811 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9812 | }, |
| 9813 | { |
| 9814 | .cmd = NL80211_CMD_FLUSH_PMKSA, |
| 9815 | .doit = nl80211_flush_pmksa, |
| 9816 | .policy = nl80211_policy, |
| 9817 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9818 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9819 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9820 | }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9821 | { |
| 9822 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, |
| 9823 | .doit = nl80211_remain_on_channel, |
| 9824 | .policy = nl80211_policy, |
| 9825 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9826 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9827 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9828 | }, |
| 9829 | { |
| 9830 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
| 9831 | .doit = nl80211_cancel_remain_on_channel, |
| 9832 | .policy = nl80211_policy, |
| 9833 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9834 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9835 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9836 | }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 9837 | { |
| 9838 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, |
| 9839 | .doit = nl80211_set_tx_bitrate_mask, |
| 9840 | .policy = nl80211_policy, |
| 9841 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9842 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9843 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 9844 | }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9845 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9846 | .cmd = NL80211_CMD_REGISTER_FRAME, |
| 9847 | .doit = nl80211_register_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9848 | .policy = nl80211_policy, |
| 9849 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9850 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9851 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9852 | }, |
| 9853 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9854 | .cmd = NL80211_CMD_FRAME, |
| 9855 | .doit = nl80211_tx_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9856 | .policy = nl80211_policy, |
| 9857 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9858 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9859 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9860 | }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9861 | { |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 9862 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, |
| 9863 | .doit = nl80211_tx_mgmt_cancel_wait, |
| 9864 | .policy = nl80211_policy, |
| 9865 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9866 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 9867 | NL80211_FLAG_NEED_RTNL, |
| 9868 | }, |
| 9869 | { |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9870 | .cmd = NL80211_CMD_SET_POWER_SAVE, |
| 9871 | .doit = nl80211_set_power_save, |
| 9872 | .policy = nl80211_policy, |
| 9873 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9874 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9875 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9876 | }, |
| 9877 | { |
| 9878 | .cmd = NL80211_CMD_GET_POWER_SAVE, |
| 9879 | .doit = nl80211_get_power_save, |
| 9880 | .policy = nl80211_policy, |
| 9881 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9882 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9883 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9884 | }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9885 | { |
| 9886 | .cmd = NL80211_CMD_SET_CQM, |
| 9887 | .doit = nl80211_set_cqm, |
| 9888 | .policy = nl80211_policy, |
| 9889 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9890 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9891 | NL80211_FLAG_NEED_RTNL, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9892 | }, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 9893 | { |
| 9894 | .cmd = NL80211_CMD_SET_CHANNEL, |
| 9895 | .doit = nl80211_set_channel, |
| 9896 | .policy = nl80211_policy, |
| 9897 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9898 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9899 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 9900 | }, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 9901 | { |
| 9902 | .cmd = NL80211_CMD_SET_WDS_PEER, |
| 9903 | .doit = nl80211_set_wds_peer, |
| 9904 | .policy = nl80211_policy, |
| 9905 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 9906 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9907 | NL80211_FLAG_NEED_RTNL, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 9908 | }, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 9909 | { |
| 9910 | .cmd = NL80211_CMD_JOIN_MESH, |
| 9911 | .doit = nl80211_join_mesh, |
| 9912 | .policy = nl80211_policy, |
| 9913 | .flags = GENL_ADMIN_PERM, |
| 9914 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9915 | NL80211_FLAG_NEED_RTNL, |
| 9916 | }, |
| 9917 | { |
| 9918 | .cmd = NL80211_CMD_LEAVE_MESH, |
| 9919 | .doit = nl80211_leave_mesh, |
| 9920 | .policy = nl80211_policy, |
| 9921 | .flags = GENL_ADMIN_PERM, |
| 9922 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9923 | NL80211_FLAG_NEED_RTNL, |
| 9924 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 9925 | #ifdef CONFIG_PM |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9926 | { |
| 9927 | .cmd = NL80211_CMD_GET_WOWLAN, |
| 9928 | .doit = nl80211_get_wowlan, |
| 9929 | .policy = nl80211_policy, |
| 9930 | /* can be retrieved by unprivileged users */ |
| 9931 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9932 | NL80211_FLAG_NEED_RTNL, |
| 9933 | }, |
| 9934 | { |
| 9935 | .cmd = NL80211_CMD_SET_WOWLAN, |
| 9936 | .doit = nl80211_set_wowlan, |
| 9937 | .policy = nl80211_policy, |
| 9938 | .flags = GENL_ADMIN_PERM, |
| 9939 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9940 | NL80211_FLAG_NEED_RTNL, |
| 9941 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 9942 | #endif |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 9943 | { |
| 9944 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, |
| 9945 | .doit = nl80211_set_rekey_data, |
| 9946 | .policy = nl80211_policy, |
| 9947 | .flags = GENL_ADMIN_PERM, |
| 9948 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9949 | NL80211_FLAG_NEED_RTNL, |
| 9950 | }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 9951 | { |
| 9952 | .cmd = NL80211_CMD_TDLS_MGMT, |
| 9953 | .doit = nl80211_tdls_mgmt, |
| 9954 | .policy = nl80211_policy, |
| 9955 | .flags = GENL_ADMIN_PERM, |
| 9956 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9957 | NL80211_FLAG_NEED_RTNL, |
| 9958 | }, |
| 9959 | { |
| 9960 | .cmd = NL80211_CMD_TDLS_OPER, |
| 9961 | .doit = nl80211_tdls_oper, |
| 9962 | .policy = nl80211_policy, |
| 9963 | .flags = GENL_ADMIN_PERM, |
| 9964 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9965 | NL80211_FLAG_NEED_RTNL, |
| 9966 | }, |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9967 | { |
| 9968 | .cmd = NL80211_CMD_UNEXPECTED_FRAME, |
| 9969 | .doit = nl80211_register_unexpected_frame, |
| 9970 | .policy = nl80211_policy, |
| 9971 | .flags = GENL_ADMIN_PERM, |
| 9972 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9973 | NL80211_FLAG_NEED_RTNL, |
| 9974 | }, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9975 | { |
| 9976 | .cmd = NL80211_CMD_PROBE_CLIENT, |
| 9977 | .doit = nl80211_probe_client, |
| 9978 | .policy = nl80211_policy, |
| 9979 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9980 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9981 | NL80211_FLAG_NEED_RTNL, |
| 9982 | }, |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9983 | { |
| 9984 | .cmd = NL80211_CMD_REGISTER_BEACONS, |
| 9985 | .doit = nl80211_register_beacons, |
| 9986 | .policy = nl80211_policy, |
| 9987 | .flags = GENL_ADMIN_PERM, |
| 9988 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9989 | NL80211_FLAG_NEED_RTNL, |
| 9990 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 9991 | { |
| 9992 | .cmd = NL80211_CMD_SET_NOACK_MAP, |
| 9993 | .doit = nl80211_set_noack_map, |
| 9994 | .policy = nl80211_policy, |
| 9995 | .flags = GENL_ADMIN_PERM, |
| 9996 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9997 | NL80211_FLAG_NEED_RTNL, |
| 9998 | }, |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9999 | { |
| 10000 | .cmd = NL80211_CMD_START_P2P_DEVICE, |
| 10001 | .doit = nl80211_start_p2p_device, |
| 10002 | .policy = nl80211_policy, |
| 10003 | .flags = GENL_ADMIN_PERM, |
| 10004 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 10005 | NL80211_FLAG_NEED_RTNL, |
| 10006 | }, |
| 10007 | { |
| 10008 | .cmd = NL80211_CMD_STOP_P2P_DEVICE, |
| 10009 | .doit = nl80211_stop_p2p_device, |
| 10010 | .policy = nl80211_policy, |
| 10011 | .flags = GENL_ADMIN_PERM, |
| 10012 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 10013 | NL80211_FLAG_NEED_RTNL, |
| 10014 | }, |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 10015 | { |
| 10016 | .cmd = NL80211_CMD_SET_MCAST_RATE, |
| 10017 | .doit = nl80211_set_mcast_rate, |
| 10018 | .policy = nl80211_policy, |
| 10019 | .flags = GENL_ADMIN_PERM, |
| 10020 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 10021 | NL80211_FLAG_NEED_RTNL, |
| 10022 | }, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 10023 | { |
| 10024 | .cmd = NL80211_CMD_SET_MAC_ACL, |
| 10025 | .doit = nl80211_set_mac_acl, |
| 10026 | .policy = nl80211_policy, |
| 10027 | .flags = GENL_ADMIN_PERM, |
| 10028 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 10029 | NL80211_FLAG_NEED_RTNL, |
| 10030 | }, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 10031 | { |
| 10032 | .cmd = NL80211_CMD_RADAR_DETECT, |
| 10033 | .doit = nl80211_start_radar_detection, |
| 10034 | .policy = nl80211_policy, |
| 10035 | .flags = GENL_ADMIN_PERM, |
| 10036 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10037 | NL80211_FLAG_NEED_RTNL, |
| 10038 | }, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 10039 | { |
| 10040 | .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES, |
| 10041 | .doit = nl80211_get_protocol_features, |
| 10042 | .policy = nl80211_policy, |
| 10043 | }, |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 10044 | { |
| 10045 | .cmd = NL80211_CMD_UPDATE_FT_IES, |
| 10046 | .doit = nl80211_update_ft_ies, |
| 10047 | .policy = nl80211_policy, |
| 10048 | .flags = GENL_ADMIN_PERM, |
| 10049 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10050 | NL80211_FLAG_NEED_RTNL, |
| 10051 | }, |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 10052 | { |
| 10053 | .cmd = NL80211_CMD_CRIT_PROTOCOL_START, |
| 10054 | .doit = nl80211_crit_protocol_start, |
| 10055 | .policy = nl80211_policy, |
| 10056 | .flags = GENL_ADMIN_PERM, |
| 10057 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 10058 | NL80211_FLAG_NEED_RTNL, |
| 10059 | }, |
| 10060 | { |
| 10061 | .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP, |
| 10062 | .doit = nl80211_crit_protocol_stop, |
| 10063 | .policy = nl80211_policy, |
| 10064 | .flags = GENL_ADMIN_PERM, |
| 10065 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 10066 | NL80211_FLAG_NEED_RTNL, |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 10067 | }, |
| 10068 | { |
| 10069 | .cmd = NL80211_CMD_GET_COALESCE, |
| 10070 | .doit = nl80211_get_coalesce, |
| 10071 | .policy = nl80211_policy, |
| 10072 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 10073 | NL80211_FLAG_NEED_RTNL, |
| 10074 | }, |
| 10075 | { |
| 10076 | .cmd = NL80211_CMD_SET_COALESCE, |
| 10077 | .doit = nl80211_set_coalesce, |
| 10078 | .policy = nl80211_policy, |
| 10079 | .flags = GENL_ADMIN_PERM, |
| 10080 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 10081 | NL80211_FLAG_NEED_RTNL, |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 10082 | }, |
| 10083 | { |
| 10084 | .cmd = NL80211_CMD_CHANNEL_SWITCH, |
| 10085 | .doit = nl80211_channel_switch, |
| 10086 | .policy = nl80211_policy, |
| 10087 | .flags = GENL_ADMIN_PERM, |
| 10088 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10089 | NL80211_FLAG_NEED_RTNL, |
| 10090 | }, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 10091 | { |
| 10092 | .cmd = NL80211_CMD_VENDOR, |
| 10093 | .doit = nl80211_vendor_cmd, |
| 10094 | .policy = nl80211_policy, |
| 10095 | .flags = GENL_ADMIN_PERM, |
| 10096 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 10097 | NL80211_FLAG_NEED_RTNL, |
| 10098 | }, |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 10099 | { |
| 10100 | .cmd = NL80211_CMD_SET_QOS_MAP, |
| 10101 | .doit = nl80211_set_qos_map, |
| 10102 | .policy = nl80211_policy, |
| 10103 | .flags = GENL_ADMIN_PERM, |
| 10104 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10105 | NL80211_FLAG_NEED_RTNL, |
| 10106 | }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10107 | }; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10108 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10109 | /* notification functions */ |
| 10110 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 10111 | void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev, |
| 10112 | enum nl80211_commands cmd) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10113 | { |
| 10114 | struct sk_buff *msg; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 10115 | struct nl80211_dump_wiphy_state state = {}; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10116 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 10117 | WARN_ON(cmd != NL80211_CMD_NEW_WIPHY && |
| 10118 | cmd != NL80211_CMD_DEL_WIPHY); |
| 10119 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 10120 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10121 | if (!msg) |
| 10122 | return; |
| 10123 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 10124 | if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10125 | nlmsg_free(msg); |
| 10126 | return; |
| 10127 | } |
| 10128 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10129 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10130 | NL80211_MCGRP_CONFIG, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10131 | } |
| 10132 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 10133 | static int nl80211_add_scan_req(struct sk_buff *msg, |
| 10134 | struct cfg80211_registered_device *rdev) |
| 10135 | { |
| 10136 | struct cfg80211_scan_request *req = rdev->scan_req; |
| 10137 | struct nlattr *nest; |
| 10138 | int i; |
| 10139 | |
| 10140 | if (WARN_ON(!req)) |
| 10141 | return 0; |
| 10142 | |
| 10143 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); |
| 10144 | if (!nest) |
| 10145 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10146 | for (i = 0; i < req->n_ssids; i++) { |
| 10147 | if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) |
| 10148 | goto nla_put_failure; |
| 10149 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 10150 | nla_nest_end(msg, nest); |
| 10151 | |
| 10152 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 10153 | if (!nest) |
| 10154 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10155 | for (i = 0; i < req->n_channels; i++) { |
| 10156 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) |
| 10157 | goto nla_put_failure; |
| 10158 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 10159 | nla_nest_end(msg, nest); |
| 10160 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10161 | if (req->ie && |
| 10162 | nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie)) |
| 10163 | goto nla_put_failure; |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 10164 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 10165 | if (req->flags && |
| 10166 | nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags)) |
| 10167 | goto nla_put_failure; |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 10168 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 10169 | return 0; |
| 10170 | nla_put_failure: |
| 10171 | return -ENOBUFS; |
| 10172 | } |
| 10173 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 10174 | static int nl80211_send_scan_msg(struct sk_buff *msg, |
| 10175 | struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 10176 | struct wireless_dev *wdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10177 | u32 portid, u32 seq, int flags, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 10178 | u32 cmd) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10179 | { |
| 10180 | void *hdr; |
| 10181 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10182 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10183 | if (!hdr) |
| 10184 | return -1; |
| 10185 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10186 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 10187 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 10188 | wdev->netdev->ifindex)) || |
| 10189 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10190 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10191 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 10192 | /* ignore errors and send incomplete event anyway */ |
| 10193 | nl80211_add_scan_req(msg, rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10194 | |
| 10195 | return genlmsg_end(msg, hdr); |
| 10196 | |
| 10197 | nla_put_failure: |
| 10198 | genlmsg_cancel(msg, hdr); |
| 10199 | return -EMSGSIZE; |
| 10200 | } |
| 10201 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 10202 | static int |
| 10203 | nl80211_send_sched_scan_msg(struct sk_buff *msg, |
| 10204 | struct cfg80211_registered_device *rdev, |
| 10205 | struct net_device *netdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10206 | u32 portid, u32 seq, int flags, u32 cmd) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 10207 | { |
| 10208 | void *hdr; |
| 10209 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10210 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 10211 | if (!hdr) |
| 10212 | return -1; |
| 10213 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10214 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10215 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 10216 | goto nla_put_failure; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 10217 | |
| 10218 | return genlmsg_end(msg, hdr); |
| 10219 | |
| 10220 | nla_put_failure: |
| 10221 | genlmsg_cancel(msg, hdr); |
| 10222 | return -EMSGSIZE; |
| 10223 | } |
| 10224 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 10225 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 10226 | struct wireless_dev *wdev) |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 10227 | { |
| 10228 | struct sk_buff *msg; |
| 10229 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10230 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 10231 | if (!msg) |
| 10232 | return; |
| 10233 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 10234 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 10235 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
| 10236 | nlmsg_free(msg); |
| 10237 | return; |
| 10238 | } |
| 10239 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10240 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10241 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 10242 | } |
| 10243 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 10244 | struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev, |
| 10245 | struct wireless_dev *wdev, bool aborted) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10246 | { |
| 10247 | struct sk_buff *msg; |
| 10248 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 10249 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10250 | if (!msg) |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 10251 | return NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10252 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 10253 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 10254 | aborted ? NL80211_CMD_SCAN_ABORTED : |
| 10255 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10256 | nlmsg_free(msg); |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 10257 | return NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10258 | } |
| 10259 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 10260 | return msg; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10261 | } |
| 10262 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 10263 | void nl80211_send_scan_result(struct cfg80211_registered_device *rdev, |
| 10264 | struct sk_buff *msg) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10265 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10266 | if (!msg) |
| 10267 | return; |
| 10268 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10269 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10270 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10271 | } |
| 10272 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 10273 | void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev, |
| 10274 | struct net_device *netdev) |
| 10275 | { |
| 10276 | struct sk_buff *msg; |
| 10277 | |
| 10278 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 10279 | if (!msg) |
| 10280 | return; |
| 10281 | |
| 10282 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 10283 | NL80211_CMD_SCHED_SCAN_RESULTS) < 0) { |
| 10284 | nlmsg_free(msg); |
| 10285 | return; |
| 10286 | } |
| 10287 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10288 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10289 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 10290 | } |
| 10291 | |
| 10292 | void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev, |
| 10293 | struct net_device *netdev, u32 cmd) |
| 10294 | { |
| 10295 | struct sk_buff *msg; |
| 10296 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10297 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 10298 | if (!msg) |
| 10299 | return; |
| 10300 | |
| 10301 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) { |
| 10302 | nlmsg_free(msg); |
| 10303 | return; |
| 10304 | } |
| 10305 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10306 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10307 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 10308 | } |
| 10309 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 10310 | /* |
| 10311 | * This can happen on global regulatory changes or device specific settings |
| 10312 | * based on custom world regulatory domains. |
| 10313 | */ |
| 10314 | void nl80211_send_reg_change_event(struct regulatory_request *request) |
| 10315 | { |
| 10316 | struct sk_buff *msg; |
| 10317 | void *hdr; |
| 10318 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 10319 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 10320 | if (!msg) |
| 10321 | return; |
| 10322 | |
| 10323 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE); |
| 10324 | if (!hdr) { |
| 10325 | nlmsg_free(msg); |
| 10326 | return; |
| 10327 | } |
| 10328 | |
| 10329 | /* Userspace can always count this one always being set */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10330 | if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator)) |
| 10331 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 10332 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10333 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') { |
| 10334 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 10335 | NL80211_REGDOM_TYPE_WORLD)) |
| 10336 | goto nla_put_failure; |
| 10337 | } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') { |
| 10338 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 10339 | NL80211_REGDOM_TYPE_CUSTOM_WORLD)) |
| 10340 | goto nla_put_failure; |
| 10341 | } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || |
| 10342 | request->intersect) { |
| 10343 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 10344 | NL80211_REGDOM_TYPE_INTERSECTION)) |
| 10345 | goto nla_put_failure; |
| 10346 | } else { |
| 10347 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 10348 | NL80211_REGDOM_TYPE_COUNTRY) || |
| 10349 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, |
| 10350 | request->alpha2)) |
| 10351 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 10352 | } |
| 10353 | |
Johannes Berg | f417376 | 2012-12-03 18:23:37 +0100 | [diff] [blame] | 10354 | if (request->wiphy_idx != WIPHY_IDX_INVALID && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10355 | nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) |
| 10356 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 10357 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10358 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 10359 | |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 10360 | rcu_read_lock(); |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10361 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10362 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 10363 | rcu_read_unlock(); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 10364 | |
| 10365 | return; |
| 10366 | |
| 10367 | nla_put_failure: |
| 10368 | genlmsg_cancel(msg, hdr); |
| 10369 | nlmsg_free(msg); |
| 10370 | } |
| 10371 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10372 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
| 10373 | struct net_device *netdev, |
| 10374 | const u8 *buf, size_t len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10375 | enum nl80211_commands cmd, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10376 | { |
| 10377 | struct sk_buff *msg; |
| 10378 | void *hdr; |
| 10379 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10380 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10381 | if (!msg) |
| 10382 | return; |
| 10383 | |
| 10384 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 10385 | if (!hdr) { |
| 10386 | nlmsg_free(msg); |
| 10387 | return; |
| 10388 | } |
| 10389 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10390 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10391 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10392 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) |
| 10393 | goto nla_put_failure; |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10394 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10395 | genlmsg_end(msg, hdr); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10396 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10397 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10398 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10399 | return; |
| 10400 | |
| 10401 | nla_put_failure: |
| 10402 | genlmsg_cancel(msg, hdr); |
| 10403 | nlmsg_free(msg); |
| 10404 | } |
| 10405 | |
| 10406 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10407 | struct net_device *netdev, const u8 *buf, |
| 10408 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10409 | { |
| 10410 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10411 | NL80211_CMD_AUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10412 | } |
| 10413 | |
| 10414 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, |
| 10415 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10416 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10417 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10418 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 10419 | NL80211_CMD_ASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10420 | } |
| 10421 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 10422 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10423 | struct net_device *netdev, const u8 *buf, |
| 10424 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10425 | { |
| 10426 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10427 | NL80211_CMD_DEAUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10428 | } |
| 10429 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 10430 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
| 10431 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10432 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10433 | { |
| 10434 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10435 | NL80211_CMD_DISASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10436 | } |
| 10437 | |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 10438 | void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf, |
| 10439 | size_t len) |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 10440 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10441 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10442 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 10443 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 10444 | const struct ieee80211_mgmt *mgmt = (void *)buf; |
| 10445 | u32 cmd; |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 10446 | |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 10447 | if (WARN_ON(len < 2)) |
| 10448 | return; |
| 10449 | |
| 10450 | if (ieee80211_is_deauth(mgmt->frame_control)) |
| 10451 | cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE; |
| 10452 | else |
| 10453 | cmd = NL80211_CMD_UNPROT_DISASSOCIATE; |
| 10454 | |
| 10455 | trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len); |
| 10456 | nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC); |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 10457 | } |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 10458 | EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt); |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 10459 | |
Luis R. Rodriguez | 1b06bb4 | 2009-05-02 00:34:48 -0400 | [diff] [blame] | 10460 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
| 10461 | struct net_device *netdev, int cmd, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10462 | const u8 *addr, gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10463 | { |
| 10464 | struct sk_buff *msg; |
| 10465 | void *hdr; |
| 10466 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10467 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10468 | if (!msg) |
| 10469 | return; |
| 10470 | |
| 10471 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 10472 | if (!hdr) { |
| 10473 | nlmsg_free(msg); |
| 10474 | return; |
| 10475 | } |
| 10476 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10477 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10478 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10479 | nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || |
| 10480 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 10481 | goto nla_put_failure; |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10482 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10483 | genlmsg_end(msg, hdr); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10484 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10485 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10486 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10487 | return; |
| 10488 | |
| 10489 | nla_put_failure: |
| 10490 | genlmsg_cancel(msg, hdr); |
| 10491 | nlmsg_free(msg); |
| 10492 | } |
| 10493 | |
| 10494 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10495 | struct net_device *netdev, const u8 *addr, |
| 10496 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10497 | { |
| 10498 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10499 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10500 | } |
| 10501 | |
| 10502 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10503 | struct net_device *netdev, const u8 *addr, |
| 10504 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10505 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10506 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
| 10507 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10508 | } |
| 10509 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10510 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
| 10511 | struct net_device *netdev, const u8 *bssid, |
| 10512 | const u8 *req_ie, size_t req_ie_len, |
| 10513 | const u8 *resp_ie, size_t resp_ie_len, |
| 10514 | u16 status, gfp_t gfp) |
| 10515 | { |
| 10516 | struct sk_buff *msg; |
| 10517 | void *hdr; |
| 10518 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10519 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10520 | if (!msg) |
| 10521 | return; |
| 10522 | |
| 10523 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); |
| 10524 | if (!hdr) { |
| 10525 | nlmsg_free(msg); |
| 10526 | return; |
| 10527 | } |
| 10528 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10529 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10530 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10531 | (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) || |
| 10532 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) || |
| 10533 | (req_ie && |
| 10534 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 10535 | (resp_ie && |
| 10536 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 10537 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10538 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10539 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10540 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10541 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10542 | NL80211_MCGRP_MLME, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10543 | return; |
| 10544 | |
| 10545 | nla_put_failure: |
| 10546 | genlmsg_cancel(msg, hdr); |
| 10547 | nlmsg_free(msg); |
| 10548 | |
| 10549 | } |
| 10550 | |
| 10551 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, |
| 10552 | struct net_device *netdev, const u8 *bssid, |
| 10553 | const u8 *req_ie, size_t req_ie_len, |
| 10554 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) |
| 10555 | { |
| 10556 | struct sk_buff *msg; |
| 10557 | void *hdr; |
| 10558 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10559 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10560 | if (!msg) |
| 10561 | return; |
| 10562 | |
| 10563 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); |
| 10564 | if (!hdr) { |
| 10565 | nlmsg_free(msg); |
| 10566 | return; |
| 10567 | } |
| 10568 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10569 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10570 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10571 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) || |
| 10572 | (req_ie && |
| 10573 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 10574 | (resp_ie && |
| 10575 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 10576 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10577 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10578 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10579 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10580 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10581 | NL80211_MCGRP_MLME, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10582 | return; |
| 10583 | |
| 10584 | nla_put_failure: |
| 10585 | genlmsg_cancel(msg, hdr); |
| 10586 | nlmsg_free(msg); |
| 10587 | |
| 10588 | } |
| 10589 | |
| 10590 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, |
| 10591 | struct net_device *netdev, u16 reason, |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 10592 | const u8 *ie, size_t ie_len, bool from_ap) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10593 | { |
| 10594 | struct sk_buff *msg; |
| 10595 | void *hdr; |
| 10596 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10597 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10598 | if (!msg) |
| 10599 | return; |
| 10600 | |
| 10601 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); |
| 10602 | if (!hdr) { |
| 10603 | nlmsg_free(msg); |
| 10604 | return; |
| 10605 | } |
| 10606 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10607 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10608 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10609 | (from_ap && reason && |
| 10610 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) || |
| 10611 | (from_ap && |
| 10612 | nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) || |
| 10613 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) |
| 10614 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10615 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10616 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10617 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10618 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10619 | NL80211_MCGRP_MLME, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10620 | return; |
| 10621 | |
| 10622 | nla_put_failure: |
| 10623 | genlmsg_cancel(msg, hdr); |
| 10624 | nlmsg_free(msg); |
| 10625 | |
| 10626 | } |
| 10627 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10628 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
| 10629 | struct net_device *netdev, const u8 *bssid, |
| 10630 | gfp_t gfp) |
| 10631 | { |
| 10632 | struct sk_buff *msg; |
| 10633 | void *hdr; |
| 10634 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 10635 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10636 | if (!msg) |
| 10637 | return; |
| 10638 | |
| 10639 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); |
| 10640 | if (!hdr) { |
| 10641 | nlmsg_free(msg); |
| 10642 | return; |
| 10643 | } |
| 10644 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10645 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10646 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10647 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 10648 | goto nla_put_failure; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10649 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10650 | genlmsg_end(msg, hdr); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10651 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10652 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10653 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10654 | return; |
| 10655 | |
| 10656 | nla_put_failure: |
| 10657 | genlmsg_cancel(msg, hdr); |
| 10658 | nlmsg_free(msg); |
| 10659 | } |
| 10660 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10661 | void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr, |
| 10662 | const u8* ie, u8 ie_len, gfp_t gfp) |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10663 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10664 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 10665 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10666 | struct sk_buff *msg; |
| 10667 | void *hdr; |
| 10668 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10669 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT)) |
| 10670 | return; |
| 10671 | |
| 10672 | trace_cfg80211_notify_new_peer_candidate(dev, addr); |
| 10673 | |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10674 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 10675 | if (!msg) |
| 10676 | return; |
| 10677 | |
| 10678 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); |
| 10679 | if (!hdr) { |
| 10680 | nlmsg_free(msg); |
| 10681 | return; |
| 10682 | } |
| 10683 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10684 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10685 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 10686 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10687 | (ie_len && ie && |
| 10688 | nla_put(msg, NL80211_ATTR_IE, ie_len , ie))) |
| 10689 | goto nla_put_failure; |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10690 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10691 | genlmsg_end(msg, hdr); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10692 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10693 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10694 | NL80211_MCGRP_MLME, gfp); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10695 | return; |
| 10696 | |
| 10697 | nla_put_failure: |
| 10698 | genlmsg_cancel(msg, hdr); |
| 10699 | nlmsg_free(msg); |
| 10700 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10701 | EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10702 | |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 10703 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
| 10704 | struct net_device *netdev, const u8 *addr, |
| 10705 | enum nl80211_key_type key_type, int key_id, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10706 | const u8 *tsc, gfp_t gfp) |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 10707 | { |
| 10708 | struct sk_buff *msg; |
| 10709 | void *hdr; |
| 10710 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10711 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 10712 | if (!msg) |
| 10713 | return; |
| 10714 | |
| 10715 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); |
| 10716 | if (!hdr) { |
| 10717 | nlmsg_free(msg); |
| 10718 | return; |
| 10719 | } |
| 10720 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10721 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10722 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10723 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
| 10724 | nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) || |
| 10725 | (key_id != -1 && |
| 10726 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) || |
| 10727 | (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc))) |
| 10728 | goto nla_put_failure; |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 10729 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10730 | genlmsg_end(msg, hdr); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 10731 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10732 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10733 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 10734 | return; |
| 10735 | |
| 10736 | nla_put_failure: |
| 10737 | genlmsg_cancel(msg, hdr); |
| 10738 | nlmsg_free(msg); |
| 10739 | } |
| 10740 | |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10741 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
| 10742 | struct ieee80211_channel *channel_before, |
| 10743 | struct ieee80211_channel *channel_after) |
| 10744 | { |
| 10745 | struct sk_buff *msg; |
| 10746 | void *hdr; |
| 10747 | struct nlattr *nl_freq; |
| 10748 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 10749 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10750 | if (!msg) |
| 10751 | return; |
| 10752 | |
| 10753 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); |
| 10754 | if (!hdr) { |
| 10755 | nlmsg_free(msg); |
| 10756 | return; |
| 10757 | } |
| 10758 | |
| 10759 | /* |
| 10760 | * Since we are applying the beacon hint to a wiphy we know its |
| 10761 | * wiphy_idx is valid |
| 10762 | */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10763 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 10764 | goto nla_put_failure; |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10765 | |
| 10766 | /* Before */ |
| 10767 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); |
| 10768 | if (!nl_freq) |
| 10769 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 10770 | if (nl80211_msg_put_channel(msg, channel_before, false)) |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10771 | goto nla_put_failure; |
| 10772 | nla_nest_end(msg, nl_freq); |
| 10773 | |
| 10774 | /* After */ |
| 10775 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); |
| 10776 | if (!nl_freq) |
| 10777 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 10778 | if (nl80211_msg_put_channel(msg, channel_after, false)) |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10779 | goto nla_put_failure; |
| 10780 | nla_nest_end(msg, nl_freq); |
| 10781 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10782 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10783 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 10784 | rcu_read_lock(); |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10785 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10786 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 10787 | rcu_read_unlock(); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10788 | |
| 10789 | return; |
| 10790 | |
| 10791 | nla_put_failure: |
| 10792 | genlmsg_cancel(msg, hdr); |
| 10793 | nlmsg_free(msg); |
| 10794 | } |
| 10795 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10796 | static void nl80211_send_remain_on_chan_event( |
| 10797 | int cmd, struct cfg80211_registered_device *rdev, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10798 | struct wireless_dev *wdev, u64 cookie, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10799 | struct ieee80211_channel *chan, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10800 | unsigned int duration, gfp_t gfp) |
| 10801 | { |
| 10802 | struct sk_buff *msg; |
| 10803 | void *hdr; |
| 10804 | |
| 10805 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 10806 | if (!msg) |
| 10807 | return; |
| 10808 | |
| 10809 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 10810 | if (!hdr) { |
| 10811 | nlmsg_free(msg); |
| 10812 | return; |
| 10813 | } |
| 10814 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10815 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10816 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 10817 | wdev->netdev->ifindex)) || |
Johannes Berg | 00f5335 | 2012-07-17 11:53:12 +0200 | [diff] [blame] | 10818 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10819 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) || |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 10820 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 10821 | NL80211_CHAN_NO_HT) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10822 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 10823 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10824 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10825 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL && |
| 10826 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) |
| 10827 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10828 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10829 | genlmsg_end(msg, hdr); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10830 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10831 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10832 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10833 | return; |
| 10834 | |
| 10835 | nla_put_failure: |
| 10836 | genlmsg_cancel(msg, hdr); |
| 10837 | nlmsg_free(msg); |
| 10838 | } |
| 10839 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10840 | void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie, |
| 10841 | struct ieee80211_channel *chan, |
| 10842 | unsigned int duration, gfp_t gfp) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10843 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10844 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 10845 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10846 | |
| 10847 | trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10848 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10849 | rdev, wdev, cookie, chan, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 10850 | duration, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10851 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10852 | EXPORT_SYMBOL(cfg80211_ready_on_channel); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10853 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10854 | void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie, |
| 10855 | struct ieee80211_channel *chan, |
| 10856 | gfp_t 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 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 10859 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10860 | |
| 10861 | trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10862 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 10863 | rdev, wdev, cookie, chan, 0, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10864 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10865 | EXPORT_SYMBOL(cfg80211_remain_on_channel_expired); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10866 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10867 | void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr, |
| 10868 | struct station_info *sinfo, gfp_t gfp) |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 10869 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10870 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 10871 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 10872 | struct sk_buff *msg; |
| 10873 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10874 | trace_cfg80211_new_sta(dev, mac_addr, sinfo); |
| 10875 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10876 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 10877 | if (!msg) |
| 10878 | return; |
| 10879 | |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 10880 | if (nl80211_send_station(msg, 0, 0, 0, |
| 10881 | rdev, dev, mac_addr, sinfo) < 0) { |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 10882 | nlmsg_free(msg); |
| 10883 | return; |
| 10884 | } |
| 10885 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10886 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10887 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 10888 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10889 | EXPORT_SYMBOL(cfg80211_new_sta); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 10890 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10891 | 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] | 10892 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10893 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 10894 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 10895 | struct sk_buff *msg; |
| 10896 | void *hdr; |
| 10897 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10898 | trace_cfg80211_del_sta(dev, mac_addr); |
| 10899 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10900 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 10901 | if (!msg) |
| 10902 | return; |
| 10903 | |
| 10904 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION); |
| 10905 | if (!hdr) { |
| 10906 | nlmsg_free(msg); |
| 10907 | return; |
| 10908 | } |
| 10909 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10910 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 10911 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 10912 | goto nla_put_failure; |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 10913 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10914 | genlmsg_end(msg, hdr); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 10915 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10916 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10917 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 10918 | return; |
| 10919 | |
| 10920 | nla_put_failure: |
| 10921 | genlmsg_cancel(msg, hdr); |
| 10922 | nlmsg_free(msg); |
| 10923 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10924 | EXPORT_SYMBOL(cfg80211_del_sta); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 10925 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10926 | void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr, |
| 10927 | enum nl80211_connect_failed_reason reason, |
| 10928 | gfp_t gfp) |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 10929 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10930 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 10931 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 10932 | struct sk_buff *msg; |
| 10933 | void *hdr; |
| 10934 | |
| 10935 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 10936 | if (!msg) |
| 10937 | return; |
| 10938 | |
| 10939 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED); |
| 10940 | if (!hdr) { |
| 10941 | nlmsg_free(msg); |
| 10942 | return; |
| 10943 | } |
| 10944 | |
| 10945 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 10946 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 10947 | nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason)) |
| 10948 | goto nla_put_failure; |
| 10949 | |
| 10950 | genlmsg_end(msg, hdr); |
| 10951 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10952 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10953 | NL80211_MCGRP_MLME, gfp); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 10954 | return; |
| 10955 | |
| 10956 | nla_put_failure: |
| 10957 | genlmsg_cancel(msg, hdr); |
| 10958 | nlmsg_free(msg); |
| 10959 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10960 | EXPORT_SYMBOL(cfg80211_conn_failed); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 10961 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 10962 | static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, |
| 10963 | const u8 *addr, gfp_t gfp) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10964 | { |
| 10965 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 10966 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10967 | struct sk_buff *msg; |
| 10968 | void *hdr; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10969 | u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10970 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10971 | if (!nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10972 | return false; |
| 10973 | |
| 10974 | msg = nlmsg_new(100, gfp); |
| 10975 | if (!msg) |
| 10976 | return true; |
| 10977 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 10978 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10979 | if (!hdr) { |
| 10980 | nlmsg_free(msg); |
| 10981 | return true; |
| 10982 | } |
| 10983 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10984 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10985 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 10986 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 10987 | goto nla_put_failure; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10988 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 10989 | genlmsg_end(msg, hdr); |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10990 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10991 | return true; |
| 10992 | |
| 10993 | nla_put_failure: |
| 10994 | genlmsg_cancel(msg, hdr); |
| 10995 | nlmsg_free(msg); |
| 10996 | return true; |
| 10997 | } |
| 10998 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10999 | bool cfg80211_rx_spurious_frame(struct net_device *dev, |
| 11000 | const u8 *addr, gfp_t gfp) |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 11001 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11002 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11003 | bool ret; |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 11004 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11005 | trace_cfg80211_rx_spurious_frame(dev, addr); |
| 11006 | |
| 11007 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 11008 | wdev->iftype != NL80211_IFTYPE_P2P_GO)) { |
| 11009 | trace_cfg80211_return_bool(false); |
| 11010 | return false; |
| 11011 | } |
| 11012 | ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, |
| 11013 | addr, gfp); |
| 11014 | trace_cfg80211_return_bool(ret); |
| 11015 | return ret; |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 11016 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11017 | EXPORT_SYMBOL(cfg80211_rx_spurious_frame); |
| 11018 | |
| 11019 | bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev, |
| 11020 | const u8 *addr, gfp_t gfp) |
| 11021 | { |
| 11022 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11023 | bool ret; |
| 11024 | |
| 11025 | trace_cfg80211_rx_unexpected_4addr_frame(dev, addr); |
| 11026 | |
| 11027 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 11028 | wdev->iftype != NL80211_IFTYPE_P2P_GO && |
| 11029 | wdev->iftype != NL80211_IFTYPE_AP_VLAN)) { |
| 11030 | trace_cfg80211_return_bool(false); |
| 11031 | return false; |
| 11032 | } |
| 11033 | ret = __nl80211_unexpected_frame(dev, |
| 11034 | NL80211_CMD_UNEXPECTED_4ADDR_FRAME, |
| 11035 | addr, gfp); |
| 11036 | trace_cfg80211_return_bool(ret); |
| 11037 | return ret; |
| 11038 | } |
| 11039 | EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame); |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 11040 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 11041 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11042 | struct wireless_dev *wdev, u32 nlportid, |
Johannes Berg | 804483e | 2012-03-05 22:18:41 +0100 | [diff] [blame] | 11043 | int freq, int sig_dbm, |
Vladimir Kondratiev | 19504cf | 2013-08-15 14:51:28 +0300 | [diff] [blame] | 11044 | const u8 *buf, size_t len, u32 flags, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11045 | { |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11046 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11047 | struct sk_buff *msg; |
| 11048 | void *hdr; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11049 | |
| 11050 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 11051 | if (!msg) |
| 11052 | return -ENOMEM; |
| 11053 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 11054 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11055 | if (!hdr) { |
| 11056 | nlmsg_free(msg); |
| 11057 | return -ENOMEM; |
| 11058 | } |
| 11059 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11060 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11061 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 11062 | netdev->ifindex)) || |
Ilan Peer | a838490 | 2013-05-08 16:35:55 +0300 | [diff] [blame] | 11063 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11064 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
| 11065 | (sig_dbm && |
| 11066 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
Vladimir Kondratiev | 19504cf | 2013-08-15 14:51:28 +0300 | [diff] [blame] | 11067 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
| 11068 | (flags && |
| 11069 | nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11070 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11071 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11072 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11073 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11074 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11075 | |
| 11076 | nla_put_failure: |
| 11077 | genlmsg_cancel(msg, hdr); |
| 11078 | nlmsg_free(msg); |
| 11079 | return -ENOBUFS; |
| 11080 | } |
| 11081 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11082 | void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie, |
| 11083 | const u8 *buf, size_t len, bool ack, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11084 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11085 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11086 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11087 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11088 | struct sk_buff *msg; |
| 11089 | void *hdr; |
| 11090 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11091 | trace_cfg80211_mgmt_tx_status(wdev, cookie, ack); |
| 11092 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11093 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 11094 | if (!msg) |
| 11095 | return; |
| 11096 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 11097 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11098 | if (!hdr) { |
| 11099 | nlmsg_free(msg); |
| 11100 | return; |
| 11101 | } |
| 11102 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11103 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11104 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 11105 | netdev->ifindex)) || |
Ilan Peer | a838490 | 2013-05-08 16:35:55 +0300 | [diff] [blame] | 11106 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11107 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
| 11108 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || |
| 11109 | (ack && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 11110 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11111 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11112 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11113 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11114 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11115 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11116 | return; |
| 11117 | |
| 11118 | nla_put_failure: |
| 11119 | genlmsg_cancel(msg, hdr); |
| 11120 | nlmsg_free(msg); |
| 11121 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11122 | EXPORT_SYMBOL(cfg80211_mgmt_tx_status); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11123 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11124 | void cfg80211_cqm_rssi_notify(struct net_device *dev, |
| 11125 | enum nl80211_cqm_rssi_threshold_event rssi_event, |
| 11126 | gfp_t gfp) |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11127 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11128 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11129 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11130 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11131 | struct sk_buff *msg; |
| 11132 | struct nlattr *pinfoattr; |
| 11133 | void *hdr; |
| 11134 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11135 | trace_cfg80211_cqm_rssi_notify(dev, rssi_event); |
| 11136 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11137 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11138 | if (!msg) |
| 11139 | return; |
| 11140 | |
| 11141 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 11142 | if (!hdr) { |
| 11143 | nlmsg_free(msg); |
| 11144 | return; |
| 11145 | } |
| 11146 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11147 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11148 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11149 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11150 | |
| 11151 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 11152 | if (!pinfoattr) |
| 11153 | goto nla_put_failure; |
| 11154 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11155 | if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, |
| 11156 | rssi_event)) |
| 11157 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11158 | |
| 11159 | nla_nest_end(msg, pinfoattr); |
| 11160 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11161 | genlmsg_end(msg, hdr); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11162 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11163 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11164 | NL80211_MCGRP_MLME, gfp); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11165 | return; |
| 11166 | |
| 11167 | nla_put_failure: |
| 11168 | genlmsg_cancel(msg, hdr); |
| 11169 | nlmsg_free(msg); |
| 11170 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11171 | EXPORT_SYMBOL(cfg80211_cqm_rssi_notify); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11172 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11173 | static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
| 11174 | struct net_device *netdev, const u8 *bssid, |
| 11175 | const u8 *replay_ctr, gfp_t gfp) |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 11176 | { |
| 11177 | struct sk_buff *msg; |
| 11178 | struct nlattr *rekey_attr; |
| 11179 | void *hdr; |
| 11180 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11181 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 11182 | if (!msg) |
| 11183 | return; |
| 11184 | |
| 11185 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); |
| 11186 | if (!hdr) { |
| 11187 | nlmsg_free(msg); |
| 11188 | return; |
| 11189 | } |
| 11190 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11191 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11192 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 11193 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 11194 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 11195 | |
| 11196 | rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); |
| 11197 | if (!rekey_attr) |
| 11198 | goto nla_put_failure; |
| 11199 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11200 | if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
| 11201 | NL80211_REPLAY_CTR_LEN, replay_ctr)) |
| 11202 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 11203 | |
| 11204 | nla_nest_end(msg, rekey_attr); |
| 11205 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11206 | genlmsg_end(msg, hdr); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 11207 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11208 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11209 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 11210 | return; |
| 11211 | |
| 11212 | nla_put_failure: |
| 11213 | genlmsg_cancel(msg, hdr); |
| 11214 | nlmsg_free(msg); |
| 11215 | } |
| 11216 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11217 | void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid, |
| 11218 | const u8 *replay_ctr, gfp_t gfp) |
| 11219 | { |
| 11220 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11221 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11222 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11223 | |
| 11224 | trace_cfg80211_gtk_rekey_notify(dev, bssid); |
| 11225 | nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp); |
| 11226 | } |
| 11227 | EXPORT_SYMBOL(cfg80211_gtk_rekey_notify); |
| 11228 | |
| 11229 | static void |
| 11230 | nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, |
| 11231 | struct net_device *netdev, int index, |
| 11232 | const u8 *bssid, bool preauth, gfp_t gfp) |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 11233 | { |
| 11234 | struct sk_buff *msg; |
| 11235 | struct nlattr *attr; |
| 11236 | void *hdr; |
| 11237 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11238 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 11239 | if (!msg) |
| 11240 | return; |
| 11241 | |
| 11242 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); |
| 11243 | if (!hdr) { |
| 11244 | nlmsg_free(msg); |
| 11245 | return; |
| 11246 | } |
| 11247 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11248 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11249 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 11250 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 11251 | |
| 11252 | attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE); |
| 11253 | if (!attr) |
| 11254 | goto nla_put_failure; |
| 11255 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11256 | if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) || |
| 11257 | nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) || |
| 11258 | (preauth && |
| 11259 | nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH))) |
| 11260 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 11261 | |
| 11262 | nla_nest_end(msg, attr); |
| 11263 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11264 | genlmsg_end(msg, hdr); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 11265 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11266 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11267 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 11268 | return; |
| 11269 | |
| 11270 | nla_put_failure: |
| 11271 | genlmsg_cancel(msg, hdr); |
| 11272 | nlmsg_free(msg); |
| 11273 | } |
| 11274 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11275 | void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index, |
| 11276 | const u8 *bssid, bool preauth, gfp_t gfp) |
| 11277 | { |
| 11278 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11279 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11280 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11281 | |
| 11282 | trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth); |
| 11283 | nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp); |
| 11284 | } |
| 11285 | EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify); |
| 11286 | |
| 11287 | static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev, |
| 11288 | struct net_device *netdev, |
| 11289 | struct cfg80211_chan_def *chandef, |
| 11290 | gfp_t gfp) |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 11291 | { |
| 11292 | struct sk_buff *msg; |
| 11293 | void *hdr; |
| 11294 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11295 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 11296 | if (!msg) |
| 11297 | return; |
| 11298 | |
| 11299 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY); |
| 11300 | if (!hdr) { |
| 11301 | nlmsg_free(msg); |
| 11302 | return; |
| 11303 | } |
| 11304 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 11305 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 11306 | goto nla_put_failure; |
| 11307 | |
| 11308 | if (nl80211_send_chandef(msg, chandef)) |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 11309 | goto nla_put_failure; |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 11310 | |
| 11311 | genlmsg_end(msg, hdr); |
| 11312 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11313 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11314 | NL80211_MCGRP_MLME, gfp); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 11315 | return; |
| 11316 | |
| 11317 | nla_put_failure: |
| 11318 | genlmsg_cancel(msg, hdr); |
| 11319 | nlmsg_free(msg); |
| 11320 | } |
| 11321 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11322 | void cfg80211_ch_switch_notify(struct net_device *dev, |
| 11323 | struct cfg80211_chan_def *chandef) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 11324 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11325 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11326 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11327 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11328 | |
Simon Wunderlich | e487eae | 2013-11-21 18:19:51 +0100 | [diff] [blame] | 11329 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11330 | |
Simon Wunderlich | e487eae | 2013-11-21 18:19:51 +0100 | [diff] [blame] | 11331 | trace_cfg80211_ch_switch_notify(dev, chandef); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11332 | |
| 11333 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 11334 | wdev->iftype != NL80211_IFTYPE_P2P_GO && |
Chun-Yeow Yeoh | b8456a1 | 2013-10-17 15:55:02 -0700 | [diff] [blame] | 11335 | wdev->iftype != NL80211_IFTYPE_ADHOC && |
| 11336 | wdev->iftype != NL80211_IFTYPE_MESH_POINT)) |
Simon Wunderlich | e487eae | 2013-11-21 18:19:51 +0100 | [diff] [blame] | 11337 | return; |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11338 | |
Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 11339 | wdev->chandef = *chandef; |
Janusz Dziedzic | 96f55f1 | 2014-01-24 14:29:21 +0100 | [diff] [blame] | 11340 | wdev->preset_chandef = *chandef; |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11341 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11342 | } |
| 11343 | EXPORT_SYMBOL(cfg80211_ch_switch_notify); |
| 11344 | |
| 11345 | void cfg80211_cqm_txe_notify(struct net_device *dev, |
| 11346 | const u8 *peer, u32 num_packets, |
| 11347 | u32 rate, u32 intvl, gfp_t gfp) |
| 11348 | { |
| 11349 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11350 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11351 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 11352 | struct sk_buff *msg; |
| 11353 | struct nlattr *pinfoattr; |
| 11354 | void *hdr; |
| 11355 | |
| 11356 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 11357 | if (!msg) |
| 11358 | return; |
| 11359 | |
| 11360 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 11361 | if (!hdr) { |
| 11362 | nlmsg_free(msg); |
| 11363 | return; |
| 11364 | } |
| 11365 | |
| 11366 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11367 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 11368 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
| 11369 | goto nla_put_failure; |
| 11370 | |
| 11371 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 11372 | if (!pinfoattr) |
| 11373 | goto nla_put_failure; |
| 11374 | |
| 11375 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets)) |
| 11376 | goto nla_put_failure; |
| 11377 | |
| 11378 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate)) |
| 11379 | goto nla_put_failure; |
| 11380 | |
| 11381 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl)) |
| 11382 | goto nla_put_failure; |
| 11383 | |
| 11384 | nla_nest_end(msg, pinfoattr); |
| 11385 | |
| 11386 | genlmsg_end(msg, hdr); |
| 11387 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11388 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11389 | NL80211_MCGRP_MLME, gfp); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 11390 | return; |
| 11391 | |
| 11392 | nla_put_failure: |
| 11393 | genlmsg_cancel(msg, hdr); |
| 11394 | nlmsg_free(msg); |
| 11395 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11396 | EXPORT_SYMBOL(cfg80211_cqm_txe_notify); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 11397 | |
| 11398 | void |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 11399 | nl80211_radar_notify(struct cfg80211_registered_device *rdev, |
Janusz Dziedzic | d2859df | 2013-11-06 13:55:51 +0100 | [diff] [blame] | 11400 | const struct cfg80211_chan_def *chandef, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 11401 | enum nl80211_radar_event event, |
| 11402 | struct net_device *netdev, gfp_t gfp) |
| 11403 | { |
| 11404 | struct sk_buff *msg; |
| 11405 | void *hdr; |
| 11406 | |
| 11407 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 11408 | if (!msg) |
| 11409 | return; |
| 11410 | |
| 11411 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT); |
| 11412 | if (!hdr) { |
| 11413 | nlmsg_free(msg); |
| 11414 | return; |
| 11415 | } |
| 11416 | |
| 11417 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 11418 | goto nla_put_failure; |
| 11419 | |
| 11420 | /* NOP and radar events don't need a netdev parameter */ |
| 11421 | if (netdev) { |
| 11422 | struct wireless_dev *wdev = netdev->ieee80211_ptr; |
| 11423 | |
| 11424 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 11425 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 11426 | goto nla_put_failure; |
| 11427 | } |
| 11428 | |
| 11429 | if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event)) |
| 11430 | goto nla_put_failure; |
| 11431 | |
| 11432 | if (nl80211_send_chandef(msg, chandef)) |
| 11433 | goto nla_put_failure; |
| 11434 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 11435 | genlmsg_end(msg, hdr); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 11436 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11437 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11438 | NL80211_MCGRP_MLME, gfp); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 11439 | return; |
| 11440 | |
| 11441 | nla_put_failure: |
| 11442 | genlmsg_cancel(msg, hdr); |
| 11443 | nlmsg_free(msg); |
| 11444 | } |
| 11445 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11446 | void cfg80211_cqm_pktloss_notify(struct net_device *dev, |
| 11447 | const u8 *peer, u32 num_packets, gfp_t gfp) |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 11448 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11449 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11450 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11451 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 11452 | struct sk_buff *msg; |
| 11453 | struct nlattr *pinfoattr; |
| 11454 | void *hdr; |
| 11455 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11456 | trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets); |
| 11457 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11458 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 11459 | if (!msg) |
| 11460 | return; |
| 11461 | |
| 11462 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 11463 | if (!hdr) { |
| 11464 | nlmsg_free(msg); |
| 11465 | return; |
| 11466 | } |
| 11467 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11468 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11469 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11470 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
| 11471 | goto nla_put_failure; |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 11472 | |
| 11473 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 11474 | if (!pinfoattr) |
| 11475 | goto nla_put_failure; |
| 11476 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11477 | if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets)) |
| 11478 | goto nla_put_failure; |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 11479 | |
| 11480 | nla_nest_end(msg, pinfoattr); |
| 11481 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11482 | genlmsg_end(msg, hdr); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 11483 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11484 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11485 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 11486 | return; |
| 11487 | |
| 11488 | nla_put_failure: |
| 11489 | genlmsg_cancel(msg, hdr); |
| 11490 | nlmsg_free(msg); |
| 11491 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11492 | EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 11493 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11494 | void cfg80211_probe_status(struct net_device *dev, const u8 *addr, |
| 11495 | u64 cookie, bool acked, gfp_t gfp) |
| 11496 | { |
| 11497 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11498 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11499 | struct sk_buff *msg; |
| 11500 | void *hdr; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11501 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 11502 | trace_cfg80211_probe_status(dev, addr, cookie, acked); |
| 11503 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11504 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 11505 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11506 | if (!msg) |
| 11507 | return; |
| 11508 | |
| 11509 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); |
| 11510 | if (!hdr) { |
| 11511 | nlmsg_free(msg); |
| 11512 | return; |
| 11513 | } |
| 11514 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11515 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11516 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 11517 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 11518 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || |
| 11519 | (acked && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 11520 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11521 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 11522 | genlmsg_end(msg, hdr); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11523 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11524 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11525 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11526 | return; |
| 11527 | |
| 11528 | nla_put_failure: |
| 11529 | genlmsg_cancel(msg, hdr); |
| 11530 | nlmsg_free(msg); |
| 11531 | } |
| 11532 | EXPORT_SYMBOL(cfg80211_probe_status); |
| 11533 | |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11534 | void cfg80211_report_obss_beacon(struct wiphy *wiphy, |
| 11535 | const u8 *frame, size_t len, |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11536 | int freq, int sig_dbm) |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11537 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11538 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11539 | struct sk_buff *msg; |
| 11540 | void *hdr; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11541 | struct cfg80211_beacon_registration *reg; |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11542 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 11543 | trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm); |
| 11544 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11545 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 11546 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 11547 | msg = nlmsg_new(len + 100, GFP_ATOMIC); |
| 11548 | if (!msg) { |
| 11549 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 11550 | return; |
| 11551 | } |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11552 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11553 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
| 11554 | if (!hdr) |
| 11555 | goto nla_put_failure; |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11556 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11557 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11558 | (freq && |
| 11559 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || |
| 11560 | (sig_dbm && |
| 11561 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
| 11562 | nla_put(msg, NL80211_ATTR_FRAME, len, frame)) |
| 11563 | goto nla_put_failure; |
| 11564 | |
| 11565 | genlmsg_end(msg, hdr); |
| 11566 | |
| 11567 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid); |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11568 | } |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11569 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11570 | return; |
| 11571 | |
| 11572 | nla_put_failure: |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11573 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 11574 | if (hdr) |
| 11575 | genlmsg_cancel(msg, hdr); |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11576 | nlmsg_free(msg); |
| 11577 | } |
| 11578 | EXPORT_SYMBOL(cfg80211_report_obss_beacon); |
| 11579 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 11580 | #ifdef CONFIG_PM |
| 11581 | void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev, |
| 11582 | struct cfg80211_wowlan_wakeup *wakeup, |
| 11583 | gfp_t gfp) |
| 11584 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11585 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 11586 | struct sk_buff *msg; |
| 11587 | void *hdr; |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 11588 | int size = 200; |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 11589 | |
| 11590 | trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup); |
| 11591 | |
| 11592 | if (wakeup) |
| 11593 | size += wakeup->packet_present_len; |
| 11594 | |
| 11595 | msg = nlmsg_new(size, gfp); |
| 11596 | if (!msg) |
| 11597 | return; |
| 11598 | |
| 11599 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN); |
| 11600 | if (!hdr) |
| 11601 | goto free_msg; |
| 11602 | |
| 11603 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11604 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 11605 | goto free_msg; |
| 11606 | |
| 11607 | if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 11608 | wdev->netdev->ifindex)) |
| 11609 | goto free_msg; |
| 11610 | |
| 11611 | if (wakeup) { |
| 11612 | struct nlattr *reasons; |
| 11613 | |
| 11614 | reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
Johannes Berg | 7fa322c | 2013-10-25 11:16:58 +0200 | [diff] [blame] | 11615 | if (!reasons) |
| 11616 | goto free_msg; |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 11617 | |
| 11618 | if (wakeup->disconnect && |
| 11619 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) |
| 11620 | goto free_msg; |
| 11621 | if (wakeup->magic_pkt && |
| 11622 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) |
| 11623 | goto free_msg; |
| 11624 | if (wakeup->gtk_rekey_failure && |
| 11625 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) |
| 11626 | goto free_msg; |
| 11627 | if (wakeup->eap_identity_req && |
| 11628 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) |
| 11629 | goto free_msg; |
| 11630 | if (wakeup->four_way_handshake && |
| 11631 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) |
| 11632 | goto free_msg; |
| 11633 | if (wakeup->rfkill_release && |
| 11634 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)) |
| 11635 | goto free_msg; |
| 11636 | |
| 11637 | if (wakeup->pattern_idx >= 0 && |
| 11638 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 11639 | wakeup->pattern_idx)) |
| 11640 | goto free_msg; |
| 11641 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 11642 | if (wakeup->tcp_match && |
| 11643 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH)) |
| 11644 | goto free_msg; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11645 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 11646 | if (wakeup->tcp_connlost && |
| 11647 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST)) |
| 11648 | goto free_msg; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11649 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 11650 | if (wakeup->tcp_nomoretokens && |
| 11651 | nla_put_flag(msg, |
| 11652 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS)) |
| 11653 | goto free_msg; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11654 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 11655 | if (wakeup->packet) { |
| 11656 | u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211; |
| 11657 | u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN; |
| 11658 | |
| 11659 | if (!wakeup->packet_80211) { |
| 11660 | pkt_attr = |
| 11661 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023; |
| 11662 | len_attr = |
| 11663 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN; |
| 11664 | } |
| 11665 | |
| 11666 | if (wakeup->packet_len && |
| 11667 | nla_put_u32(msg, len_attr, wakeup->packet_len)) |
| 11668 | goto free_msg; |
| 11669 | |
| 11670 | if (nla_put(msg, pkt_attr, wakeup->packet_present_len, |
| 11671 | wakeup->packet)) |
| 11672 | goto free_msg; |
| 11673 | } |
| 11674 | |
| 11675 | nla_nest_end(msg, reasons); |
| 11676 | } |
| 11677 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 11678 | genlmsg_end(msg, hdr); |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 11679 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11680 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11681 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 11682 | return; |
| 11683 | |
| 11684 | free_msg: |
| 11685 | nlmsg_free(msg); |
| 11686 | } |
| 11687 | EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup); |
| 11688 | #endif |
| 11689 | |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 11690 | void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer, |
| 11691 | enum nl80211_tdls_operation oper, |
| 11692 | u16 reason_code, gfp_t gfp) |
| 11693 | { |
| 11694 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11695 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 11696 | struct sk_buff *msg; |
| 11697 | void *hdr; |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 11698 | |
| 11699 | trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper, |
| 11700 | reason_code); |
| 11701 | |
| 11702 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 11703 | if (!msg) |
| 11704 | return; |
| 11705 | |
| 11706 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER); |
| 11707 | if (!hdr) { |
| 11708 | nlmsg_free(msg); |
| 11709 | return; |
| 11710 | } |
| 11711 | |
| 11712 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11713 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 11714 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) || |
| 11715 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) || |
| 11716 | (reason_code > 0 && |
| 11717 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) |
| 11718 | goto nla_put_failure; |
| 11719 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 11720 | genlmsg_end(msg, hdr); |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 11721 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11722 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11723 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 11724 | return; |
| 11725 | |
| 11726 | nla_put_failure: |
| 11727 | genlmsg_cancel(msg, hdr); |
| 11728 | nlmsg_free(msg); |
| 11729 | } |
| 11730 | EXPORT_SYMBOL(cfg80211_tdls_oper_request); |
| 11731 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11732 | static int nl80211_netlink_notify(struct notifier_block * nb, |
| 11733 | unsigned long state, |
| 11734 | void *_notify) |
| 11735 | { |
| 11736 | struct netlink_notify *notify = _notify; |
| 11737 | struct cfg80211_registered_device *rdev; |
| 11738 | struct wireless_dev *wdev; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11739 | struct cfg80211_beacon_registration *reg, *tmp; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11740 | |
| 11741 | if (state != NETLINK_URELEASE) |
| 11742 | return NOTIFY_DONE; |
| 11743 | |
| 11744 | rcu_read_lock(); |
| 11745 | |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11746 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 11747 | bool schedule_destroy_work = false; |
| 11748 | |
| 11749 | list_for_each_entry_rcu(wdev, &rdev->wdev_list, list) { |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11750 | cfg80211_mlme_unregister_socket(wdev, notify->portid); |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11751 | |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 11752 | if (wdev->owner_nlportid == notify->portid) |
| 11753 | schedule_destroy_work = true; |
| 11754 | } |
| 11755 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11756 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 11757 | list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations, |
| 11758 | list) { |
| 11759 | if (reg->nlportid == notify->portid) { |
| 11760 | list_del(®->list); |
| 11761 | kfree(reg); |
| 11762 | break; |
| 11763 | } |
| 11764 | } |
| 11765 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 11766 | |
| 11767 | if (schedule_destroy_work) { |
| 11768 | struct cfg80211_iface_destroy *destroy; |
| 11769 | |
| 11770 | destroy = kzalloc(sizeof(*destroy), GFP_ATOMIC); |
| 11771 | if (destroy) { |
| 11772 | destroy->nlportid = notify->portid; |
| 11773 | spin_lock(&rdev->destroy_list_lock); |
| 11774 | list_add(&destroy->list, &rdev->destroy_list); |
| 11775 | spin_unlock(&rdev->destroy_list_lock); |
| 11776 | schedule_work(&rdev->destroy_work); |
| 11777 | } |
| 11778 | } |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11779 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11780 | |
| 11781 | rcu_read_unlock(); |
| 11782 | |
Zhao, Gang | 6784c7d | 2014-04-21 12:53:04 +0800 | [diff] [blame] | 11783 | return NOTIFY_OK; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11784 | } |
| 11785 | |
| 11786 | static struct notifier_block nl80211_netlink_notifier = { |
| 11787 | .notifier_call = nl80211_netlink_notify, |
| 11788 | }; |
| 11789 | |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 11790 | void cfg80211_ft_event(struct net_device *netdev, |
| 11791 | struct cfg80211_ft_event_params *ft_event) |
| 11792 | { |
| 11793 | struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11794 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 11795 | struct sk_buff *msg; |
| 11796 | void *hdr; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 11797 | |
| 11798 | trace_cfg80211_ft_event(wiphy, netdev, ft_event); |
| 11799 | |
| 11800 | if (!ft_event->target_ap) |
| 11801 | return; |
| 11802 | |
| 11803 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 11804 | if (!msg) |
| 11805 | return; |
| 11806 | |
| 11807 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT); |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 11808 | if (!hdr) |
| 11809 | goto out; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 11810 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 11811 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11812 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 11813 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap)) |
| 11814 | goto out; |
| 11815 | |
| 11816 | if (ft_event->ies && |
| 11817 | nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies)) |
| 11818 | goto out; |
| 11819 | if (ft_event->ric_ies && |
| 11820 | nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len, |
| 11821 | ft_event->ric_ies)) |
| 11822 | goto out; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 11823 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 11824 | genlmsg_end(msg, hdr); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 11825 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11826 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11827 | NL80211_MCGRP_MLME, GFP_KERNEL); |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 11828 | return; |
| 11829 | out: |
| 11830 | nlmsg_free(msg); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 11831 | } |
| 11832 | EXPORT_SYMBOL(cfg80211_ft_event); |
| 11833 | |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 11834 | void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp) |
| 11835 | { |
| 11836 | struct cfg80211_registered_device *rdev; |
| 11837 | struct sk_buff *msg; |
| 11838 | void *hdr; |
| 11839 | u32 nlportid; |
| 11840 | |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11841 | rdev = wiphy_to_rdev(wdev->wiphy); |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 11842 | if (!rdev->crit_proto_nlportid) |
| 11843 | return; |
| 11844 | |
| 11845 | nlportid = rdev->crit_proto_nlportid; |
| 11846 | rdev->crit_proto_nlportid = 0; |
| 11847 | |
| 11848 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 11849 | if (!msg) |
| 11850 | return; |
| 11851 | |
| 11852 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP); |
| 11853 | if (!hdr) |
| 11854 | goto nla_put_failure; |
| 11855 | |
| 11856 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11857 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 11858 | goto nla_put_failure; |
| 11859 | |
| 11860 | genlmsg_end(msg, hdr); |
| 11861 | |
| 11862 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
| 11863 | return; |
| 11864 | |
| 11865 | nla_put_failure: |
| 11866 | if (hdr) |
| 11867 | genlmsg_cancel(msg, hdr); |
| 11868 | nlmsg_free(msg); |
| 11869 | |
| 11870 | } |
| 11871 | EXPORT_SYMBOL(cfg80211_crit_proto_stopped); |
| 11872 | |
Johannes Berg | 348baf0 | 2014-01-24 14:06:29 +0100 | [diff] [blame] | 11873 | void nl80211_send_ap_stopped(struct wireless_dev *wdev) |
| 11874 | { |
| 11875 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11876 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 348baf0 | 2014-01-24 14:06:29 +0100 | [diff] [blame] | 11877 | struct sk_buff *msg; |
| 11878 | void *hdr; |
| 11879 | |
| 11880 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 11881 | if (!msg) |
| 11882 | return; |
| 11883 | |
| 11884 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP); |
| 11885 | if (!hdr) |
| 11886 | goto out; |
| 11887 | |
| 11888 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11889 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) || |
| 11890 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 11891 | goto out; |
| 11892 | |
| 11893 | genlmsg_end(msg, hdr); |
| 11894 | |
| 11895 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0, |
| 11896 | NL80211_MCGRP_MLME, GFP_KERNEL); |
| 11897 | return; |
| 11898 | out: |
| 11899 | nlmsg_free(msg); |
| 11900 | } |
| 11901 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11902 | /* initialisation/exit functions */ |
| 11903 | |
| 11904 | int nl80211_init(void) |
| 11905 | { |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 11906 | int err; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11907 | |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11908 | err = genl_register_family_with_ops_groups(&nl80211_fam, nl80211_ops, |
| 11909 | nl80211_mcgrps); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11910 | if (err) |
| 11911 | return err; |
| 11912 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11913 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
| 11914 | if (err) |
| 11915 | goto err_out; |
| 11916 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11917 | return 0; |
| 11918 | err_out: |
| 11919 | genl_unregister_family(&nl80211_fam); |
| 11920 | return err; |
| 11921 | } |
| 11922 | |
| 11923 | void nl80211_exit(void) |
| 11924 | { |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11925 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11926 | genl_unregister_family(&nl80211_fam); |
| 11927 | } |