Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1 | /* |
| 2 | * This is the new netlink-based wireless configuration interface. |
| 3 | * |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4 | * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net> |
Johannes Berg | 2740f0c | 2014-09-03 15:24:58 +0300 | [diff] [blame] | 5 | * Copyright 2013-2014 Intel Mobile Communications GmbH |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <linux/if.h> |
| 9 | #include <linux/module.h> |
| 10 | #include <linux/err.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 11 | #include <linux/slab.h> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 12 | #include <linux/list.h> |
| 13 | #include <linux/if_ether.h> |
| 14 | #include <linux/ieee80211.h> |
| 15 | #include <linux/nl80211.h> |
| 16 | #include <linux/rtnetlink.h> |
| 17 | #include <linux/netlink.h> |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 18 | #include <linux/etherdevice.h> |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 19 | #include <net/net_namespace.h> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 20 | #include <net/genetlink.h> |
| 21 | #include <net/cfg80211.h> |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 22 | #include <net/sock.h> |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 23 | #include <net/inet_connection_sock.h> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 24 | #include "core.h" |
| 25 | #include "nl80211.h" |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 26 | #include "reg.h" |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 27 | #include "rdev-ops.h" |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 28 | |
Jouni Malinen | 5fb628e | 2011-08-10 23:54:35 +0300 | [diff] [blame] | 29 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 30 | struct genl_info *info, |
| 31 | struct cfg80211_crypto_settings *settings, |
| 32 | int cipher_limit); |
| 33 | |
Johannes Berg | f84f771 | 2013-11-14 17:14:45 +0100 | [diff] [blame] | 34 | static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 35 | struct genl_info *info); |
Johannes Berg | f84f771 | 2013-11-14 17:14:45 +0100 | [diff] [blame] | 36 | static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 37 | struct genl_info *info); |
| 38 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 39 | /* the netlink family */ |
| 40 | static struct genl_family nl80211_fam = { |
Marcel Holtmann | fb4e156 | 2013-04-28 16:22:06 -0700 | [diff] [blame] | 41 | .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */ |
| 42 | .name = NL80211_GENL_NAME, /* have users key off the name instead */ |
| 43 | .hdrsize = 0, /* no private header */ |
| 44 | .version = 1, /* no particular meaning now */ |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 45 | .maxattr = NL80211_ATTR_MAX, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 46 | .netnsok = true, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 47 | .pre_doit = nl80211_pre_doit, |
| 48 | .post_doit = nl80211_post_doit, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 49 | }; |
| 50 | |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 51 | /* multicast groups */ |
| 52 | enum nl80211_multicast_groups { |
| 53 | NL80211_MCGRP_CONFIG, |
| 54 | NL80211_MCGRP_SCAN, |
| 55 | NL80211_MCGRP_REGULATORY, |
| 56 | NL80211_MCGRP_MLME, |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 57 | NL80211_MCGRP_VENDOR, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 58 | NL80211_MCGRP_TESTMODE /* keep last - ifdef! */ |
| 59 | }; |
| 60 | |
| 61 | static const struct genl_multicast_group nl80211_mcgrps[] = { |
| 62 | [NL80211_MCGRP_CONFIG] = { .name = "config", }, |
| 63 | [NL80211_MCGRP_SCAN] = { .name = "scan", }, |
| 64 | [NL80211_MCGRP_REGULATORY] = { .name = "regulatory", }, |
| 65 | [NL80211_MCGRP_MLME] = { .name = "mlme", }, |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 66 | [NL80211_MCGRP_VENDOR] = { .name = "vendor", }, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 67 | #ifdef CONFIG_NL80211_TESTMODE |
| 68 | [NL80211_MCGRP_TESTMODE] = { .name = "testmode", } |
| 69 | #endif |
| 70 | }; |
| 71 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 72 | /* returns ERR_PTR values */ |
| 73 | static struct wireless_dev * |
| 74 | __cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 75 | { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 76 | struct cfg80211_registered_device *rdev; |
| 77 | struct wireless_dev *result = NULL; |
| 78 | bool have_ifidx = attrs[NL80211_ATTR_IFINDEX]; |
| 79 | bool have_wdev_id = attrs[NL80211_ATTR_WDEV]; |
| 80 | u64 wdev_id; |
| 81 | int wiphy_idx = -1; |
| 82 | int ifidx = -1; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 83 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 84 | ASSERT_RTNL(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 85 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 86 | if (!have_ifidx && !have_wdev_id) |
| 87 | return ERR_PTR(-EINVAL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 88 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 89 | if (have_ifidx) |
| 90 | ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); |
| 91 | if (have_wdev_id) { |
| 92 | wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); |
| 93 | wiphy_idx = wdev_id >> 32; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 94 | } |
| 95 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 96 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 97 | struct wireless_dev *wdev; |
| 98 | |
| 99 | if (wiphy_net(&rdev->wiphy) != netns) |
| 100 | continue; |
| 101 | |
| 102 | if (have_wdev_id && rdev->wiphy_idx != wiphy_idx) |
| 103 | continue; |
| 104 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 105 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
| 106 | if (have_ifidx && wdev->netdev && |
| 107 | wdev->netdev->ifindex == ifidx) { |
| 108 | result = wdev; |
| 109 | break; |
| 110 | } |
| 111 | if (have_wdev_id && wdev->identifier == (u32)wdev_id) { |
| 112 | result = wdev; |
| 113 | break; |
| 114 | } |
| 115 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 116 | |
| 117 | if (result) |
| 118 | break; |
| 119 | } |
| 120 | |
| 121 | if (result) |
| 122 | return result; |
| 123 | return ERR_PTR(-ENODEV); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 124 | } |
| 125 | |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 126 | static struct cfg80211_registered_device * |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 127 | __cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs) |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 128 | { |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 129 | struct cfg80211_registered_device *rdev = NULL, *tmp; |
| 130 | struct net_device *netdev; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 131 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 132 | ASSERT_RTNL(); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 133 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 134 | if (!attrs[NL80211_ATTR_WIPHY] && |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 135 | !attrs[NL80211_ATTR_IFINDEX] && |
| 136 | !attrs[NL80211_ATTR_WDEV]) |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 137 | return ERR_PTR(-EINVAL); |
| 138 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 139 | if (attrs[NL80211_ATTR_WIPHY]) |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 140 | rdev = cfg80211_rdev_by_wiphy_idx( |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 141 | nla_get_u32(attrs[NL80211_ATTR_WIPHY])); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 142 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 143 | if (attrs[NL80211_ATTR_WDEV]) { |
| 144 | u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); |
| 145 | struct wireless_dev *wdev; |
| 146 | bool found = false; |
| 147 | |
| 148 | tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32); |
| 149 | if (tmp) { |
| 150 | /* make sure wdev exists */ |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 151 | list_for_each_entry(wdev, &tmp->wdev_list, list) { |
| 152 | if (wdev->identifier != (u32)wdev_id) |
| 153 | continue; |
| 154 | found = true; |
| 155 | break; |
| 156 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 157 | |
| 158 | if (!found) |
| 159 | tmp = NULL; |
| 160 | |
| 161 | if (rdev && tmp != rdev) |
| 162 | return ERR_PTR(-EINVAL); |
| 163 | rdev = tmp; |
| 164 | } |
| 165 | } |
| 166 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 167 | if (attrs[NL80211_ATTR_IFINDEX]) { |
| 168 | int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 169 | netdev = __dev_get_by_index(netns, ifindex); |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 170 | if (netdev) { |
| 171 | if (netdev->ieee80211_ptr) |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 172 | tmp = wiphy_to_rdev( |
| 173 | netdev->ieee80211_ptr->wiphy); |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 174 | else |
| 175 | tmp = NULL; |
| 176 | |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 177 | /* not wireless device -- return error */ |
| 178 | if (!tmp) |
| 179 | return ERR_PTR(-EINVAL); |
| 180 | |
| 181 | /* mismatch -- return error */ |
| 182 | if (rdev && tmp != rdev) |
| 183 | return ERR_PTR(-EINVAL); |
| 184 | |
| 185 | rdev = tmp; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 186 | } |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 187 | } |
| 188 | |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 189 | if (!rdev) |
| 190 | return ERR_PTR(-ENODEV); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 191 | |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 192 | if (netns != wiphy_net(&rdev->wiphy)) |
| 193 | return ERR_PTR(-ENODEV); |
| 194 | |
| 195 | return rdev; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 196 | } |
| 197 | |
| 198 | /* |
| 199 | * This function returns a pointer to the driver |
| 200 | * that the genl_info item that is passed refers to. |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 201 | * |
| 202 | * The result of this can be a PTR_ERR and hence must |
| 203 | * be checked with IS_ERR() for errors. |
| 204 | */ |
| 205 | static struct cfg80211_registered_device * |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 206 | cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info) |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 207 | { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 208 | return __cfg80211_rdev_from_attrs(netns, info->attrs); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 209 | } |
| 210 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 211 | /* policy for the attributes */ |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame^] | 212 | static const struct nla_policy nl80211_policy[NUM_NL80211_ATTR] = { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 213 | [NL80211_ATTR_WIPHY] = { .type = NLA_U32 }, |
| 214 | [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING, |
David S. Miller | 079e24e | 2009-05-26 21:15:00 -0700 | [diff] [blame] | 215 | .len = 20-1 }, |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 216 | [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED }, |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 217 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 218 | [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 }, |
Sujith | 094d05d | 2008-12-12 11:57:43 +0530 | [diff] [blame] | 219 | [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 220 | [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 }, |
| 221 | [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 }, |
| 222 | [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 }, |
| 223 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 224 | [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 }, |
| 225 | [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 }, |
| 226 | [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 }, |
| 227 | [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 }, |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 228 | [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 }, |
Lorenzo Bianconi | 3057dbf | 2014-09-04 23:57:40 +0200 | [diff] [blame] | 229 | [NL80211_ATTR_WIPHY_DYN_ACK] = { .type = NLA_FLAG }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 230 | |
| 231 | [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 }, |
| 232 | [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 }, |
| 233 | [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 234 | |
Eliad Peller | e007b85 | 2011-11-24 18:13:56 +0200 | [diff] [blame] | 235 | [NL80211_ATTR_MAC] = { .len = ETH_ALEN }, |
| 236 | [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 237 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 238 | [NL80211_ATTR_KEY] = { .type = NLA_NESTED, }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 239 | [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY, |
| 240 | .len = WLAN_MAX_KEY_LEN }, |
| 241 | [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 }, |
| 242 | [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 }, |
| 243 | [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG }, |
Jouni Malinen | 8196226 | 2011-11-02 23:36:31 +0200 | [diff] [blame] | 244 | [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 245 | [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 246 | |
| 247 | [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 }, |
| 248 | [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 }, |
| 249 | [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY, |
| 250 | .len = IEEE80211_MAX_DATA_LEN }, |
| 251 | [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY, |
| 252 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 253 | [NL80211_ATTR_STA_AID] = { .type = NLA_U16 }, |
| 254 | [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED }, |
| 255 | [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 }, |
| 256 | [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY, |
| 257 | .len = NL80211_MAX_SUPP_RATES }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 258 | [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 259 | [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 }, |
Johannes Berg | 0a9542e | 2008-10-15 11:54:04 +0200 | [diff] [blame] | 260 | [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 261 | [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 262 | .len = IEEE80211_MAX_MESH_ID_LEN }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 263 | [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 264 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 265 | [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 }, |
| 266 | [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED }, |
| 267 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 268 | [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 }, |
| 269 | [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 }, |
| 270 | [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 }, |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 271 | [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY, |
| 272 | .len = NL80211_MAX_SUPP_RATES }, |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 273 | [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 }, |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 274 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 275 | [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 276 | [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 277 | |
Johannes Berg | 6c73941 | 2011-11-03 09:27:01 +0100 | [diff] [blame] | 278 | [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 279 | |
| 280 | [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 }, |
| 281 | [NL80211_ATTR_IE] = { .type = NLA_BINARY, |
| 282 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 283 | [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED }, |
| 284 | [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 285 | |
| 286 | [NL80211_ATTR_SSID] = { .type = NLA_BINARY, |
| 287 | .len = IEEE80211_MAX_SSID_LEN }, |
| 288 | [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 }, |
| 289 | [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 290 | [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG }, |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 291 | [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG }, |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 292 | [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 }, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 293 | [NL80211_ATTR_STA_FLAGS2] = { |
| 294 | .len = sizeof(struct nl80211_sta_flag_update), |
| 295 | }, |
Jouni Malinen | 3f77316c | 2009-05-11 21:57:57 +0300 | [diff] [blame] | 296 | [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG }, |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 297 | [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 }, |
| 298 | [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG }, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 299 | [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG }, |
| 300 | [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 }, |
| 301 | [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 302 | [NL80211_ATTR_PID] = { .type = NLA_U32 }, |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 303 | [NL80211_ATTR_4ADDR] = { .type = NLA_U8 }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 304 | [NL80211_ATTR_PMKID] = { .type = NLA_BINARY, |
| 305 | .len = WLAN_PMKID_LEN }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 306 | [NL80211_ATTR_DURATION] = { .type = NLA_U32 }, |
| 307 | [NL80211_ATTR_COOKIE] = { .type = NLA_U64 }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 308 | [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 309 | [NL80211_ATTR_FRAME] = { .type = NLA_BINARY, |
| 310 | .len = IEEE80211_MAX_DATA_LEN }, |
| 311 | [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 312 | [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 313 | [NL80211_ATTR_CQM] = { .type = NLA_NESTED, }, |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 314 | [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG }, |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 315 | [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 }, |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 316 | [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 }, |
| 317 | [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 }, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 318 | [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 }, |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 319 | [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 }, |
| 320 | [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 }, |
Felix Fietkau | 885a46d | 2010-11-11 15:07:22 +0100 | [diff] [blame] | 321 | [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 }, |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 322 | [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 323 | [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 324 | [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED }, |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 325 | [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 }, |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 326 | [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 }, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 327 | [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED }, |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 328 | [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED }, |
Jouni Malinen | 32e9de8 | 2011-08-10 23:53:31 +0300 | [diff] [blame] | 329 | [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 }, |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 330 | [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY, |
| 331 | .len = IEEE80211_MAX_DATA_LEN }, |
| 332 | [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY, |
| 333 | .len = IEEE80211_MAX_DATA_LEN }, |
Vivek Natarajan | f4b34b5 | 2011-08-29 14:23:03 +0530 | [diff] [blame] | 334 | [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG }, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 335 | [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED }, |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 336 | [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 337 | [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 }, |
| 338 | [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 }, |
| 339 | [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 }, |
| 340 | [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG }, |
| 341 | [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG }, |
Arik Nemtsov | 31fa97c | 2014-06-11 17:18:21 +0300 | [diff] [blame] | 342 | [NL80211_ATTR_TDLS_INITIATOR] = { .type = NLA_FLAG }, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 343 | [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG }, |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 344 | [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY, |
| 345 | .len = IEEE80211_MAX_DATA_LEN }, |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 346 | [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 }, |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 347 | [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG }, |
| 348 | [NL80211_ATTR_HT_CAPABILITY_MASK] = { |
| 349 | .len = NL80211_HT_CAPABILITY_LEN |
| 350 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 351 | [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 }, |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 352 | [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 }, |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 353 | [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 }, |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 354 | [NL80211_ATTR_WDEV] = { .type = NLA_U64 }, |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 355 | [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 }, |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 356 | [NL80211_ATTR_SAE_DATA] = { .type = NLA_BINARY, }, |
Mahesh Palivela | f461be3e | 2012-10-11 08:04:52 +0000 | [diff] [blame] | 357 | [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN }, |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 358 | [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 }, |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 359 | [NL80211_ATTR_P2P_CTWINDOW] = { .type = NLA_U8 }, |
| 360 | [NL80211_ATTR_P2P_OPPPS] = { .type = NLA_U8 }, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 361 | [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 }, |
| 362 | [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED }, |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 363 | [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 }, |
| 364 | [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, }, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 365 | [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, }, |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 366 | [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG }, |
| 367 | [NL80211_ATTR_VHT_CAPABILITY_MASK] = { |
| 368 | .len = NL80211_VHT_CAPABILITY_LEN, |
| 369 | }, |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 370 | [NL80211_ATTR_MDID] = { .type = NLA_U16 }, |
| 371 | [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY, |
| 372 | .len = IEEE80211_MAX_DATA_LEN }, |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 373 | [NL80211_ATTR_PEER_AID] = { .type = NLA_U16 }, |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 374 | [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 }, |
| 375 | [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG }, |
| 376 | [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED }, |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 377 | [NL80211_ATTR_CSA_C_OFF_BEACON] = { .type = NLA_BINARY }, |
| 378 | [NL80211_ATTR_CSA_C_OFF_PRESP] = { .type = NLA_BINARY }, |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 379 | [NL80211_ATTR_STA_SUPPORTED_CHANNELS] = { .type = NLA_BINARY }, |
| 380 | [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES] = { .type = NLA_BINARY }, |
Simon Wunderlich | 5336fa8 | 2013-10-07 18:41:05 +0200 | [diff] [blame] | 381 | [NL80211_ATTR_HANDLE_DFS] = { .type = NLA_FLAG }, |
Marek Kwaczynski | 60f4a7b | 2013-12-03 10:04:59 +0100 | [diff] [blame] | 382 | [NL80211_ATTR_OPMODE_NOTIF] = { .type = NLA_U8 }, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 383 | [NL80211_ATTR_VENDOR_ID] = { .type = NLA_U32 }, |
| 384 | [NL80211_ATTR_VENDOR_SUBCMD] = { .type = NLA_U32 }, |
| 385 | [NL80211_ATTR_VENDOR_DATA] = { .type = NLA_BINARY }, |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 386 | [NL80211_ATTR_QOS_MAP] = { .type = NLA_BINARY, |
| 387 | .len = IEEE80211_QOS_MAP_LEN_MAX }, |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 388 | [NL80211_ATTR_MAC_HINT] = { .len = ETH_ALEN }, |
| 389 | [NL80211_ATTR_WIPHY_FREQ_HINT] = { .type = NLA_U32 }, |
Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 390 | [NL80211_ATTR_TDLS_PEER_CAPABILITY] = { .type = NLA_U32 }, |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 391 | [NL80211_ATTR_IFACE_SOCKET_OWNER] = { .type = NLA_FLAG }, |
Andrei Otcheretianski | 34d22ce | 2014-05-09 14:11:44 +0300 | [diff] [blame] | 392 | [NL80211_ATTR_CSA_C_OFFSETS_TX] = { .type = NLA_BINARY }, |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 393 | [NL80211_ATTR_USE_RRM] = { .type = NLA_FLAG }, |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 394 | [NL80211_ATTR_TSID] = { .type = NLA_U8 }, |
| 395 | [NL80211_ATTR_USER_PRIO] = { .type = NLA_U8 }, |
| 396 | [NL80211_ATTR_ADMITTED_TIME] = { .type = NLA_U16 }, |
Eliad Peller | 18998c3 | 2014-09-10 14:07:34 +0300 | [diff] [blame] | 397 | [NL80211_ATTR_SMPS_MODE] = { .type = NLA_U8 }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 398 | }; |
| 399 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 400 | /* policy for the key attributes */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 401 | static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 402 | [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 403 | [NL80211_KEY_IDX] = { .type = NLA_U8 }, |
| 404 | [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, |
Jouni Malinen | 8196226 | 2011-11-02 23:36:31 +0200 | [diff] [blame] | 405 | [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 406 | [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, |
| 407 | [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 408 | [NL80211_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 409 | [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
| 410 | }; |
| 411 | |
| 412 | /* policy for the key default flags */ |
| 413 | static const struct nla_policy |
| 414 | nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = { |
| 415 | [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG }, |
| 416 | [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 417 | }; |
| 418 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 419 | /* policy for WoWLAN attributes */ |
| 420 | static const struct nla_policy |
| 421 | nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = { |
| 422 | [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG }, |
| 423 | [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG }, |
| 424 | [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG }, |
| 425 | [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED }, |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 426 | [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG }, |
| 427 | [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG }, |
| 428 | [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG }, |
| 429 | [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG }, |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 430 | [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED }, |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame^] | 431 | [NL80211_WOWLAN_TRIG_NET_DETECT] = { .type = NLA_NESTED }, |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 432 | }; |
| 433 | |
| 434 | static const struct nla_policy |
| 435 | nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = { |
| 436 | [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 }, |
| 437 | [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 }, |
| 438 | [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN }, |
| 439 | [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 }, |
| 440 | [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 }, |
| 441 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 }, |
| 442 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = { |
| 443 | .len = sizeof(struct nl80211_wowlan_tcp_data_seq) |
| 444 | }, |
| 445 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = { |
| 446 | .len = sizeof(struct nl80211_wowlan_tcp_data_token) |
| 447 | }, |
| 448 | [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 }, |
| 449 | [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 }, |
| 450 | [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 451 | }; |
| 452 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 453 | /* policy for coalesce rule attributes */ |
| 454 | static const struct nla_policy |
| 455 | nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = { |
| 456 | [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 }, |
| 457 | [NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 }, |
| 458 | [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED }, |
| 459 | }; |
| 460 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 461 | /* policy for GTK rekey offload attributes */ |
| 462 | static const struct nla_policy |
| 463 | nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = { |
| 464 | [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN }, |
| 465 | [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN }, |
| 466 | [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN }, |
| 467 | }; |
| 468 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 469 | static const struct nla_policy |
| 470 | nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = { |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 471 | [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 472 | .len = IEEE80211_MAX_SSID_LEN }, |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 473 | [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 }, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 474 | }; |
| 475 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 476 | static int nl80211_prepare_wdev_dump(struct sk_buff *skb, |
| 477 | struct netlink_callback *cb, |
| 478 | struct cfg80211_registered_device **rdev, |
| 479 | struct wireless_dev **wdev) |
Holger Schurig | a043897 | 2009-11-11 11:30:02 +0100 | [diff] [blame] | 480 | { |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 481 | int err; |
| 482 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 483 | rtnl_lock(); |
| 484 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 485 | if (!cb->args[0]) { |
| 486 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 487 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 488 | nl80211_policy); |
| 489 | if (err) |
| 490 | goto out_unlock; |
| 491 | |
| 492 | *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk), |
| 493 | nl80211_fam.attrbuf); |
| 494 | if (IS_ERR(*wdev)) { |
| 495 | err = PTR_ERR(*wdev); |
| 496 | goto out_unlock; |
| 497 | } |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 498 | *rdev = wiphy_to_rdev((*wdev)->wiphy); |
Johannes Berg | c319d50 | 2013-07-30 22:34:28 +0200 | [diff] [blame] | 499 | /* 0 is the first index - add 1 to parse only once */ |
| 500 | cb->args[0] = (*rdev)->wiphy_idx + 1; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 501 | cb->args[1] = (*wdev)->identifier; |
| 502 | } else { |
Johannes Berg | c319d50 | 2013-07-30 22:34:28 +0200 | [diff] [blame] | 503 | /* subtract the 1 again here */ |
| 504 | struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1); |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 505 | struct wireless_dev *tmp; |
| 506 | |
| 507 | if (!wiphy) { |
| 508 | err = -ENODEV; |
| 509 | goto out_unlock; |
| 510 | } |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 511 | *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 512 | *wdev = NULL; |
| 513 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 514 | list_for_each_entry(tmp, &(*rdev)->wdev_list, list) { |
| 515 | if (tmp->identifier == cb->args[1]) { |
| 516 | *wdev = tmp; |
| 517 | break; |
| 518 | } |
| 519 | } |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 520 | |
| 521 | if (!*wdev) { |
| 522 | err = -ENODEV; |
| 523 | goto out_unlock; |
| 524 | } |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 525 | } |
| 526 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 527 | return 0; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 528 | out_unlock: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 529 | rtnl_unlock(); |
| 530 | return err; |
| 531 | } |
| 532 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 533 | static void nl80211_finish_wdev_dump(struct cfg80211_registered_device *rdev) |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 534 | { |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 535 | rtnl_unlock(); |
| 536 | } |
| 537 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 538 | /* IE validation */ |
| 539 | static bool is_valid_ie_attr(const struct nlattr *attr) |
| 540 | { |
| 541 | const u8 *pos; |
| 542 | int len; |
| 543 | |
| 544 | if (!attr) |
| 545 | return true; |
| 546 | |
| 547 | pos = nla_data(attr); |
| 548 | len = nla_len(attr); |
| 549 | |
| 550 | while (len) { |
| 551 | u8 elemlen; |
| 552 | |
| 553 | if (len < 2) |
| 554 | return false; |
| 555 | len -= 2; |
| 556 | |
| 557 | elemlen = pos[1]; |
| 558 | if (elemlen > len) |
| 559 | return false; |
| 560 | |
| 561 | len -= elemlen; |
| 562 | pos += 2 + elemlen; |
| 563 | } |
| 564 | |
| 565 | return true; |
| 566 | } |
| 567 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 568 | /* message building helper */ |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 569 | 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] | 570 | int flags, u8 cmd) |
| 571 | { |
| 572 | /* since there is no private header just add the generic one */ |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 573 | return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 574 | } |
| 575 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 576 | static int nl80211_msg_put_channel(struct sk_buff *msg, |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 577 | struct ieee80211_channel *chan, |
| 578 | bool large) |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 579 | { |
Rostislav Lisovy | ea077c1 | 2014-04-15 14:37:55 +0200 | [diff] [blame] | 580 | /* Some channels must be completely excluded from the |
| 581 | * list to protect old user-space tools from breaking |
| 582 | */ |
| 583 | if (!large && chan->flags & |
| 584 | (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ)) |
| 585 | return 0; |
| 586 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 587 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
| 588 | chan->center_freq)) |
| 589 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 590 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 591 | if ((chan->flags & IEEE80211_CHAN_DISABLED) && |
| 592 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED)) |
| 593 | goto nla_put_failure; |
Luis R. Rodriguez | 8fe02e1 | 2013-10-21 19:22:25 +0200 | [diff] [blame] | 594 | if (chan->flags & IEEE80211_CHAN_NO_IR) { |
| 595 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR)) |
| 596 | goto nla_put_failure; |
| 597 | if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS)) |
| 598 | goto nla_put_failure; |
| 599 | } |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 600 | if (chan->flags & IEEE80211_CHAN_RADAR) { |
| 601 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR)) |
| 602 | goto nla_put_failure; |
| 603 | if (large) { |
| 604 | u32 time; |
| 605 | |
| 606 | time = elapsed_jiffies_msecs(chan->dfs_state_entered); |
| 607 | |
| 608 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE, |
| 609 | chan->dfs_state)) |
| 610 | goto nla_put_failure; |
| 611 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME, |
| 612 | time)) |
| 613 | goto nla_put_failure; |
Janusz Dziedzic | 089027e | 2014-02-21 19:46:12 +0100 | [diff] [blame] | 614 | if (nla_put_u32(msg, |
| 615 | NL80211_FREQUENCY_ATTR_DFS_CAC_TIME, |
| 616 | chan->dfs_cac_ms)) |
| 617 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 618 | } |
| 619 | } |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 620 | |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 621 | if (large) { |
| 622 | if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) && |
| 623 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS)) |
| 624 | goto nla_put_failure; |
| 625 | if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) && |
| 626 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS)) |
| 627 | goto nla_put_failure; |
| 628 | if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) && |
| 629 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ)) |
| 630 | goto nla_put_failure; |
| 631 | if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) && |
| 632 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ)) |
| 633 | goto nla_put_failure; |
David Spinadel | 570dbde | 2014-02-23 09:12:59 +0200 | [diff] [blame] | 634 | if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) && |
| 635 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY)) |
| 636 | goto nla_put_failure; |
| 637 | if ((chan->flags & IEEE80211_CHAN_GO_CONCURRENT) && |
| 638 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_GO_CONCURRENT)) |
| 639 | goto nla_put_failure; |
Rostislav Lisovy | ea077c1 | 2014-04-15 14:37:55 +0200 | [diff] [blame] | 640 | if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) && |
| 641 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ)) |
| 642 | goto nla_put_failure; |
| 643 | if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) && |
| 644 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ)) |
| 645 | goto nla_put_failure; |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 646 | } |
| 647 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 648 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
| 649 | DBM_TO_MBM(chan->max_power))) |
| 650 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 651 | |
| 652 | return 0; |
| 653 | |
| 654 | nla_put_failure: |
| 655 | return -ENOBUFS; |
| 656 | } |
| 657 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 658 | /* netlink command implementations */ |
| 659 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 660 | struct key_parse { |
| 661 | struct key_params p; |
| 662 | int idx; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 663 | int type; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 664 | bool def, defmgmt; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 665 | bool def_uni, def_multi; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 666 | }; |
| 667 | |
| 668 | static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k) |
| 669 | { |
| 670 | struct nlattr *tb[NL80211_KEY_MAX + 1]; |
| 671 | int err = nla_parse_nested(tb, NL80211_KEY_MAX, key, |
| 672 | nl80211_key_policy); |
| 673 | if (err) |
| 674 | return err; |
| 675 | |
| 676 | k->def = !!tb[NL80211_KEY_DEFAULT]; |
| 677 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; |
| 678 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 679 | if (k->def) { |
| 680 | k->def_uni = true; |
| 681 | k->def_multi = true; |
| 682 | } |
| 683 | if (k->defmgmt) |
| 684 | k->def_multi = true; |
| 685 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 686 | if (tb[NL80211_KEY_IDX]) |
| 687 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); |
| 688 | |
| 689 | if (tb[NL80211_KEY_DATA]) { |
| 690 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); |
| 691 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); |
| 692 | } |
| 693 | |
| 694 | if (tb[NL80211_KEY_SEQ]) { |
| 695 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); |
| 696 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); |
| 697 | } |
| 698 | |
| 699 | if (tb[NL80211_KEY_CIPHER]) |
| 700 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); |
| 701 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 702 | if (tb[NL80211_KEY_TYPE]) { |
| 703 | k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); |
| 704 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 705 | return -EINVAL; |
| 706 | } |
| 707 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 708 | if (tb[NL80211_KEY_DEFAULT_TYPES]) { |
| 709 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
Johannes Berg | 2da8f41 | 2012-01-20 13:52:37 +0100 | [diff] [blame] | 710 | err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 711 | tb[NL80211_KEY_DEFAULT_TYPES], |
| 712 | nl80211_key_default_policy); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 713 | if (err) |
| 714 | return err; |
| 715 | |
| 716 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 717 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 718 | } |
| 719 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 720 | return 0; |
| 721 | } |
| 722 | |
| 723 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) |
| 724 | { |
| 725 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { |
| 726 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 727 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 728 | } |
| 729 | |
| 730 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { |
| 731 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 732 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 733 | } |
| 734 | |
| 735 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 736 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 737 | |
| 738 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) |
| 739 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); |
| 740 | |
| 741 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; |
| 742 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; |
| 743 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 744 | if (k->def) { |
| 745 | k->def_uni = true; |
| 746 | k->def_multi = true; |
| 747 | } |
| 748 | if (k->defmgmt) |
| 749 | k->def_multi = true; |
| 750 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 751 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 752 | k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 753 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 754 | return -EINVAL; |
| 755 | } |
| 756 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 757 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { |
| 758 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
| 759 | int err = nla_parse_nested( |
| 760 | kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 761 | info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], |
| 762 | nl80211_key_default_policy); |
| 763 | if (err) |
| 764 | return err; |
| 765 | |
| 766 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 767 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 768 | } |
| 769 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 770 | return 0; |
| 771 | } |
| 772 | |
| 773 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) |
| 774 | { |
| 775 | int err; |
| 776 | |
| 777 | memset(k, 0, sizeof(*k)); |
| 778 | k->idx = -1; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 779 | k->type = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 780 | |
| 781 | if (info->attrs[NL80211_ATTR_KEY]) |
| 782 | err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k); |
| 783 | else |
| 784 | err = nl80211_parse_key_old(info, k); |
| 785 | |
| 786 | if (err) |
| 787 | return err; |
| 788 | |
| 789 | if (k->def && k->defmgmt) |
| 790 | return -EINVAL; |
| 791 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 792 | if (k->defmgmt) { |
| 793 | if (k->def_uni || !k->def_multi) |
| 794 | return -EINVAL; |
| 795 | } |
| 796 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 797 | if (k->idx != -1) { |
| 798 | if (k->defmgmt) { |
| 799 | if (k->idx < 4 || k->idx > 5) |
| 800 | return -EINVAL; |
| 801 | } else if (k->def) { |
| 802 | if (k->idx < 0 || k->idx > 3) |
| 803 | return -EINVAL; |
| 804 | } else { |
| 805 | if (k->idx < 0 || k->idx > 5) |
| 806 | return -EINVAL; |
| 807 | } |
| 808 | } |
| 809 | |
| 810 | return 0; |
| 811 | } |
| 812 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 813 | static struct cfg80211_cached_keys * |
| 814 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 815 | struct nlattr *keys, bool *no_ht) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 816 | { |
| 817 | struct key_parse parse; |
| 818 | struct nlattr *key; |
| 819 | struct cfg80211_cached_keys *result; |
| 820 | int rem, err, def = 0; |
| 821 | |
| 822 | result = kzalloc(sizeof(*result), GFP_KERNEL); |
| 823 | if (!result) |
| 824 | return ERR_PTR(-ENOMEM); |
| 825 | |
| 826 | result->def = -1; |
| 827 | result->defmgmt = -1; |
| 828 | |
| 829 | nla_for_each_nested(key, keys, rem) { |
| 830 | memset(&parse, 0, sizeof(parse)); |
| 831 | parse.idx = -1; |
| 832 | |
| 833 | err = nl80211_parse_key_new(key, &parse); |
| 834 | if (err) |
| 835 | goto error; |
| 836 | err = -EINVAL; |
| 837 | if (!parse.p.key) |
| 838 | goto error; |
| 839 | if (parse.idx < 0 || parse.idx > 4) |
| 840 | goto error; |
| 841 | if (parse.def) { |
| 842 | if (def) |
| 843 | goto error; |
| 844 | def = 1; |
| 845 | result->def = parse.idx; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 846 | if (!parse.def_uni || !parse.def_multi) |
| 847 | goto error; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 848 | } else if (parse.defmgmt) |
| 849 | goto error; |
| 850 | err = cfg80211_validate_key_settings(rdev, &parse.p, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 851 | parse.idx, false, NULL); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 852 | if (err) |
| 853 | goto error; |
| 854 | result->params[parse.idx].cipher = parse.p.cipher; |
| 855 | result->params[parse.idx].key_len = parse.p.key_len; |
| 856 | result->params[parse.idx].key = result->data[parse.idx]; |
| 857 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 858 | |
| 859 | if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 || |
| 860 | parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) { |
| 861 | if (no_ht) |
| 862 | *no_ht = true; |
| 863 | } |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 864 | } |
| 865 | |
| 866 | return result; |
| 867 | error: |
| 868 | kfree(result); |
| 869 | return ERR_PTR(err); |
| 870 | } |
| 871 | |
| 872 | static int nl80211_key_allowed(struct wireless_dev *wdev) |
| 873 | { |
| 874 | ASSERT_WDEV_LOCK(wdev); |
| 875 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 876 | switch (wdev->iftype) { |
| 877 | case NL80211_IFTYPE_AP: |
| 878 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 879 | case NL80211_IFTYPE_P2P_GO: |
Thomas Pedersen | ff973af | 2011-05-03 16:57:12 -0700 | [diff] [blame] | 880 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 881 | break; |
| 882 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 883 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 884 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 885 | if (!wdev->current_bss) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 886 | return -ENOLINK; |
| 887 | break; |
Johannes Berg | de4fcba | 2014-10-31 14:16:12 +0100 | [diff] [blame] | 888 | case NL80211_IFTYPE_UNSPECIFIED: |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 889 | case NL80211_IFTYPE_OCB: |
Johannes Berg | de4fcba | 2014-10-31 14:16:12 +0100 | [diff] [blame] | 890 | case NL80211_IFTYPE_MONITOR: |
| 891 | case NL80211_IFTYPE_P2P_DEVICE: |
| 892 | case NL80211_IFTYPE_WDS: |
| 893 | case NUM_NL80211_IFTYPES: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 894 | return -EINVAL; |
| 895 | } |
| 896 | |
| 897 | return 0; |
| 898 | } |
| 899 | |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 900 | static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy, |
| 901 | struct nlattr *tb) |
| 902 | { |
| 903 | struct ieee80211_channel *chan; |
| 904 | |
| 905 | if (tb == NULL) |
| 906 | return NULL; |
| 907 | chan = ieee80211_get_channel(wiphy, nla_get_u32(tb)); |
| 908 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) |
| 909 | return NULL; |
| 910 | return chan; |
| 911 | } |
| 912 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 913 | static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) |
| 914 | { |
| 915 | struct nlattr *nl_modes = nla_nest_start(msg, attr); |
| 916 | int i; |
| 917 | |
| 918 | if (!nl_modes) |
| 919 | goto nla_put_failure; |
| 920 | |
| 921 | i = 0; |
| 922 | while (ifmodes) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 923 | if ((ifmodes & 1) && nla_put_flag(msg, i)) |
| 924 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 925 | ifmodes >>= 1; |
| 926 | i++; |
| 927 | } |
| 928 | |
| 929 | nla_nest_end(msg, nl_modes); |
| 930 | return 0; |
| 931 | |
| 932 | nla_put_failure: |
| 933 | return -ENOBUFS; |
| 934 | } |
| 935 | |
| 936 | static int nl80211_put_iface_combinations(struct wiphy *wiphy, |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 937 | struct sk_buff *msg, |
| 938 | bool large) |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 939 | { |
| 940 | struct nlattr *nl_combis; |
| 941 | int i, j; |
| 942 | |
| 943 | nl_combis = nla_nest_start(msg, |
| 944 | NL80211_ATTR_INTERFACE_COMBINATIONS); |
| 945 | if (!nl_combis) |
| 946 | goto nla_put_failure; |
| 947 | |
| 948 | for (i = 0; i < wiphy->n_iface_combinations; i++) { |
| 949 | const struct ieee80211_iface_combination *c; |
| 950 | struct nlattr *nl_combi, *nl_limits; |
| 951 | |
| 952 | c = &wiphy->iface_combinations[i]; |
| 953 | |
| 954 | nl_combi = nla_nest_start(msg, i + 1); |
| 955 | if (!nl_combi) |
| 956 | goto nla_put_failure; |
| 957 | |
| 958 | nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS); |
| 959 | if (!nl_limits) |
| 960 | goto nla_put_failure; |
| 961 | |
| 962 | for (j = 0; j < c->n_limits; j++) { |
| 963 | struct nlattr *nl_limit; |
| 964 | |
| 965 | nl_limit = nla_nest_start(msg, j + 1); |
| 966 | if (!nl_limit) |
| 967 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 968 | if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX, |
| 969 | c->limits[j].max)) |
| 970 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 971 | if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, |
| 972 | c->limits[j].types)) |
| 973 | goto nla_put_failure; |
| 974 | nla_nest_end(msg, nl_limit); |
| 975 | } |
| 976 | |
| 977 | nla_nest_end(msg, nl_limits); |
| 978 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 979 | if (c->beacon_int_infra_match && |
| 980 | nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH)) |
| 981 | goto nla_put_failure; |
| 982 | if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, |
| 983 | c->num_different_channels) || |
| 984 | nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM, |
| 985 | c->max_interfaces)) |
| 986 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 987 | if (large && |
Felix Fietkau | 8c48b50 | 2014-05-05 11:48:40 +0200 | [diff] [blame] | 988 | (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS, |
| 989 | c->radar_detect_widths) || |
| 990 | nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS, |
| 991 | c->radar_detect_regions))) |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 992 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 993 | |
| 994 | nla_nest_end(msg, nl_combi); |
| 995 | } |
| 996 | |
| 997 | nla_nest_end(msg, nl_combis); |
| 998 | |
| 999 | return 0; |
| 1000 | nla_put_failure: |
| 1001 | return -ENOBUFS; |
| 1002 | } |
| 1003 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1004 | #ifdef CONFIG_PM |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1005 | static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev, |
| 1006 | struct sk_buff *msg) |
| 1007 | { |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 1008 | const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp; |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1009 | struct nlattr *nl_tcp; |
| 1010 | |
| 1011 | if (!tcp) |
| 1012 | return 0; |
| 1013 | |
| 1014 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); |
| 1015 | if (!nl_tcp) |
| 1016 | return -ENOBUFS; |
| 1017 | |
| 1018 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 1019 | tcp->data_payload_max)) |
| 1020 | return -ENOBUFS; |
| 1021 | |
| 1022 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 1023 | tcp->data_payload_max)) |
| 1024 | return -ENOBUFS; |
| 1025 | |
| 1026 | if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ)) |
| 1027 | return -ENOBUFS; |
| 1028 | |
| 1029 | if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, |
| 1030 | sizeof(*tcp->tok), tcp->tok)) |
| 1031 | return -ENOBUFS; |
| 1032 | |
| 1033 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, |
| 1034 | tcp->data_interval_max)) |
| 1035 | return -ENOBUFS; |
| 1036 | |
| 1037 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, |
| 1038 | tcp->wake_payload_max)) |
| 1039 | return -ENOBUFS; |
| 1040 | |
| 1041 | nla_nest_end(msg, nl_tcp); |
| 1042 | return 0; |
| 1043 | } |
| 1044 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1045 | static int nl80211_send_wowlan(struct sk_buff *msg, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1046 | struct cfg80211_registered_device *rdev, |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1047 | bool large) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1048 | { |
| 1049 | struct nlattr *nl_wowlan; |
| 1050 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1051 | if (!rdev->wiphy.wowlan) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1052 | return 0; |
| 1053 | |
| 1054 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); |
| 1055 | if (!nl_wowlan) |
| 1056 | return -ENOBUFS; |
| 1057 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1058 | if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1059 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1060 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1061 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1062 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1063 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1064 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1065 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1066 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1067 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1068 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1069 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1070 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1071 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1072 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1073 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 1074 | return -ENOBUFS; |
| 1075 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1076 | if (rdev->wiphy.wowlan->n_patterns) { |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 1077 | struct nl80211_pattern_support pat = { |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1078 | .max_patterns = rdev->wiphy.wowlan->n_patterns, |
| 1079 | .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len, |
| 1080 | .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len, |
| 1081 | .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1082 | }; |
| 1083 | |
| 1084 | if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 1085 | sizeof(pat), &pat)) |
| 1086 | return -ENOBUFS; |
| 1087 | } |
| 1088 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1089 | if (large && nl80211_send_wowlan_tcp_caps(rdev, msg)) |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1090 | return -ENOBUFS; |
| 1091 | |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame^] | 1092 | /* TODO: send wowlan net detect */ |
| 1093 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1094 | nla_nest_end(msg, nl_wowlan); |
| 1095 | |
| 1096 | return 0; |
| 1097 | } |
| 1098 | #endif |
| 1099 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1100 | static int nl80211_send_coalesce(struct sk_buff *msg, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1101 | struct cfg80211_registered_device *rdev) |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1102 | { |
| 1103 | struct nl80211_coalesce_rule_support rule; |
| 1104 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1105 | if (!rdev->wiphy.coalesce) |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1106 | return 0; |
| 1107 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1108 | rule.max_rules = rdev->wiphy.coalesce->n_rules; |
| 1109 | rule.max_delay = rdev->wiphy.coalesce->max_delay; |
| 1110 | rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns; |
| 1111 | rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len; |
| 1112 | rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len; |
| 1113 | rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset; |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1114 | |
| 1115 | if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule)) |
| 1116 | return -ENOBUFS; |
| 1117 | |
| 1118 | return 0; |
| 1119 | } |
| 1120 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1121 | static int nl80211_send_band_rateinfo(struct sk_buff *msg, |
| 1122 | struct ieee80211_supported_band *sband) |
| 1123 | { |
| 1124 | struct nlattr *nl_rates, *nl_rate; |
| 1125 | struct ieee80211_rate *rate; |
| 1126 | int i; |
| 1127 | |
| 1128 | /* add HT info */ |
| 1129 | if (sband->ht_cap.ht_supported && |
| 1130 | (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET, |
| 1131 | sizeof(sband->ht_cap.mcs), |
| 1132 | &sband->ht_cap.mcs) || |
| 1133 | nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA, |
| 1134 | sband->ht_cap.cap) || |
| 1135 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, |
| 1136 | sband->ht_cap.ampdu_factor) || |
| 1137 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, |
| 1138 | sband->ht_cap.ampdu_density))) |
| 1139 | return -ENOBUFS; |
| 1140 | |
| 1141 | /* add VHT info */ |
| 1142 | if (sband->vht_cap.vht_supported && |
| 1143 | (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET, |
| 1144 | sizeof(sband->vht_cap.vht_mcs), |
| 1145 | &sband->vht_cap.vht_mcs) || |
| 1146 | nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA, |
| 1147 | sband->vht_cap.cap))) |
| 1148 | return -ENOBUFS; |
| 1149 | |
| 1150 | /* add bitrates */ |
| 1151 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); |
| 1152 | if (!nl_rates) |
| 1153 | return -ENOBUFS; |
| 1154 | |
| 1155 | for (i = 0; i < sband->n_bitrates; i++) { |
| 1156 | nl_rate = nla_nest_start(msg, i); |
| 1157 | if (!nl_rate) |
| 1158 | return -ENOBUFS; |
| 1159 | |
| 1160 | rate = &sband->bitrates[i]; |
| 1161 | if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE, |
| 1162 | rate->bitrate)) |
| 1163 | return -ENOBUFS; |
| 1164 | if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) && |
| 1165 | nla_put_flag(msg, |
| 1166 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE)) |
| 1167 | return -ENOBUFS; |
| 1168 | |
| 1169 | nla_nest_end(msg, nl_rate); |
| 1170 | } |
| 1171 | |
| 1172 | nla_nest_end(msg, nl_rates); |
| 1173 | |
| 1174 | return 0; |
| 1175 | } |
| 1176 | |
| 1177 | static int |
| 1178 | nl80211_send_mgmt_stypes(struct sk_buff *msg, |
| 1179 | const struct ieee80211_txrx_stypes *mgmt_stypes) |
| 1180 | { |
| 1181 | u16 stypes; |
| 1182 | struct nlattr *nl_ftypes, *nl_ifs; |
| 1183 | enum nl80211_iftype ift; |
| 1184 | int i; |
| 1185 | |
| 1186 | if (!mgmt_stypes) |
| 1187 | return 0; |
| 1188 | |
| 1189 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES); |
| 1190 | if (!nl_ifs) |
| 1191 | return -ENOBUFS; |
| 1192 | |
| 1193 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 1194 | nl_ftypes = nla_nest_start(msg, ift); |
| 1195 | if (!nl_ftypes) |
| 1196 | return -ENOBUFS; |
| 1197 | i = 0; |
| 1198 | stypes = mgmt_stypes[ift].tx; |
| 1199 | while (stypes) { |
| 1200 | if ((stypes & 1) && |
| 1201 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1202 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1203 | return -ENOBUFS; |
| 1204 | stypes >>= 1; |
| 1205 | i++; |
| 1206 | } |
| 1207 | nla_nest_end(msg, nl_ftypes); |
| 1208 | } |
| 1209 | |
| 1210 | nla_nest_end(msg, nl_ifs); |
| 1211 | |
| 1212 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES); |
| 1213 | if (!nl_ifs) |
| 1214 | return -ENOBUFS; |
| 1215 | |
| 1216 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 1217 | nl_ftypes = nla_nest_start(msg, ift); |
| 1218 | if (!nl_ftypes) |
| 1219 | return -ENOBUFS; |
| 1220 | i = 0; |
| 1221 | stypes = mgmt_stypes[ift].rx; |
| 1222 | while (stypes) { |
| 1223 | if ((stypes & 1) && |
| 1224 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1225 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1226 | return -ENOBUFS; |
| 1227 | stypes >>= 1; |
| 1228 | i++; |
| 1229 | } |
| 1230 | nla_nest_end(msg, nl_ftypes); |
| 1231 | } |
| 1232 | nla_nest_end(msg, nl_ifs); |
| 1233 | |
| 1234 | return 0; |
| 1235 | } |
| 1236 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1237 | struct nl80211_dump_wiphy_state { |
| 1238 | s64 filter_wiphy; |
| 1239 | long start; |
| 1240 | long split_start, band_start, chan_start; |
| 1241 | bool split; |
| 1242 | }; |
| 1243 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1244 | static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev, |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1245 | enum nl80211_commands cmd, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1246 | struct sk_buff *msg, u32 portid, u32 seq, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1247 | int flags, struct nl80211_dump_wiphy_state *state) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1248 | { |
| 1249 | void *hdr; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1250 | struct nlattr *nl_bands, *nl_band; |
| 1251 | struct nlattr *nl_freqs, *nl_freq; |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1252 | struct nlattr *nl_cmds; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1253 | enum ieee80211_band band; |
| 1254 | struct ieee80211_channel *chan; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1255 | int i; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1256 | const struct ieee80211_txrx_stypes *mgmt_stypes = |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1257 | rdev->wiphy.mgmt_stypes; |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1258 | u32 features; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1259 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1260 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1261 | if (!hdr) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1262 | return -ENOBUFS; |
| 1263 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1264 | if (WARN_ON(!state)) |
| 1265 | return -EINVAL; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1266 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1267 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1268 | nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1269 | wiphy_name(&rdev->wiphy)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1270 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1271 | cfg80211_rdev_list_generation)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1272 | goto nla_put_failure; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1273 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1274 | if (cmd != NL80211_CMD_NEW_WIPHY) |
| 1275 | goto finish; |
| 1276 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1277 | switch (state->split_start) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1278 | case 0: |
| 1279 | if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1280 | rdev->wiphy.retry_short) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1281 | nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1282 | rdev->wiphy.retry_long) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1283 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1284 | rdev->wiphy.frag_threshold) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1285 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1286 | rdev->wiphy.rts_threshold) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1287 | nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1288 | rdev->wiphy.coverage_class) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1289 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1290 | rdev->wiphy.max_scan_ssids) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1291 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1292 | rdev->wiphy.max_sched_scan_ssids) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1293 | nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1294 | rdev->wiphy.max_scan_ie_len) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1295 | nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1296 | rdev->wiphy.max_sched_scan_ie_len) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1297 | nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1298 | rdev->wiphy.max_match_sets)) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1299 | goto nla_put_failure; |
| 1300 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1301 | if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1302 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN)) |
| 1303 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1304 | if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1305 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH)) |
| 1306 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1307 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1308 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD)) |
| 1309 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1310 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1311 | nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT)) |
| 1312 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1313 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1314 | nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT)) |
| 1315 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1316 | if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1317 | nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1318 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1319 | state->split_start++; |
| 1320 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1321 | break; |
| 1322 | case 1: |
| 1323 | if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1324 | sizeof(u32) * rdev->wiphy.n_cipher_suites, |
| 1325 | rdev->wiphy.cipher_suites)) |
Mahesh Palivela | bf0c111e | 2012-06-22 07:27:46 +0000 | [diff] [blame] | 1326 | goto nla_put_failure; |
| 1327 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1328 | if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1329 | rdev->wiphy.max_num_pmkids)) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1330 | goto nla_put_failure; |
| 1331 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1332 | if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1333 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE)) |
| 1334 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1335 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1336 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1337 | rdev->wiphy.available_antennas_tx) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1338 | nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1339 | rdev->wiphy.available_antennas_rx)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1340 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1341 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1342 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1343 | nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1344 | rdev->wiphy.probe_resp_offload)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1345 | goto nla_put_failure; |
Jouni Malinen | e2f367f26 | 2008-11-21 19:01:30 +0200 | [diff] [blame] | 1346 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1347 | if ((rdev->wiphy.available_antennas_tx || |
| 1348 | rdev->wiphy.available_antennas_rx) && |
| 1349 | rdev->ops->get_antenna) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1350 | u32 tx_ant = 0, rx_ant = 0; |
| 1351 | int res; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1352 | res = rdev_get_antenna(rdev, &tx_ant, &rx_ant); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1353 | if (!res) { |
| 1354 | if (nla_put_u32(msg, |
| 1355 | NL80211_ATTR_WIPHY_ANTENNA_TX, |
| 1356 | tx_ant) || |
| 1357 | nla_put_u32(msg, |
| 1358 | NL80211_ATTR_WIPHY_ANTENNA_RX, |
| 1359 | rx_ant)) |
| 1360 | goto nla_put_failure; |
| 1361 | } |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1362 | } |
| 1363 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1364 | state->split_start++; |
| 1365 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1366 | break; |
| 1367 | case 2: |
| 1368 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1369 | rdev->wiphy.interface_modes)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1370 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1371 | state->split_start++; |
| 1372 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1373 | break; |
| 1374 | case 3: |
| 1375 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); |
| 1376 | if (!nl_bands) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1377 | goto nla_put_failure; |
| 1378 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1379 | for (band = state->band_start; |
| 1380 | band < IEEE80211_NUM_BANDS; band++) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1381 | struct ieee80211_supported_band *sband; |
| 1382 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1383 | sband = rdev->wiphy.bands[band]; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1384 | |
| 1385 | if (!sband) |
| 1386 | continue; |
| 1387 | |
| 1388 | nl_band = nla_nest_start(msg, band); |
| 1389 | if (!nl_band) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1390 | goto nla_put_failure; |
| 1391 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1392 | switch (state->chan_start) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1393 | case 0: |
| 1394 | if (nl80211_send_band_rateinfo(msg, sband)) |
| 1395 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1396 | state->chan_start++; |
| 1397 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1398 | break; |
| 1399 | default: |
| 1400 | /* add frequencies */ |
| 1401 | nl_freqs = nla_nest_start( |
| 1402 | msg, NL80211_BAND_ATTR_FREQS); |
| 1403 | if (!nl_freqs) |
| 1404 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1405 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1406 | for (i = state->chan_start - 1; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1407 | i < sband->n_channels; |
| 1408 | i++) { |
| 1409 | nl_freq = nla_nest_start(msg, i); |
| 1410 | if (!nl_freq) |
| 1411 | goto nla_put_failure; |
| 1412 | |
| 1413 | chan = &sband->channels[i]; |
| 1414 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1415 | if (nl80211_msg_put_channel( |
| 1416 | msg, chan, |
| 1417 | state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1418 | goto nla_put_failure; |
| 1419 | |
| 1420 | nla_nest_end(msg, nl_freq); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1421 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1422 | break; |
| 1423 | } |
| 1424 | if (i < sband->n_channels) |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1425 | state->chan_start = i + 2; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1426 | else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1427 | state->chan_start = 0; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1428 | nla_nest_end(msg, nl_freqs); |
| 1429 | } |
| 1430 | |
| 1431 | nla_nest_end(msg, nl_band); |
| 1432 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1433 | if (state->split) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1434 | /* start again here */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1435 | if (state->chan_start) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1436 | band--; |
| 1437 | break; |
| 1438 | } |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1439 | } |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1440 | nla_nest_end(msg, nl_bands); |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1441 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1442 | if (band < IEEE80211_NUM_BANDS) |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1443 | state->band_start = band + 1; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1444 | else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1445 | state->band_start = 0; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1446 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1447 | /* if bands & channels are done, continue outside */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1448 | if (state->band_start == 0 && state->chan_start == 0) |
| 1449 | state->split_start++; |
| 1450 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1451 | break; |
| 1452 | case 4: |
| 1453 | nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); |
| 1454 | if (!nl_cmds) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1455 | goto nla_put_failure; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1456 | |
| 1457 | i = 0; |
| 1458 | #define CMD(op, n) \ |
| 1459 | do { \ |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1460 | if (rdev->ops->op) { \ |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1461 | i++; \ |
| 1462 | if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \ |
| 1463 | goto nla_put_failure; \ |
| 1464 | } \ |
| 1465 | } while (0) |
| 1466 | |
| 1467 | CMD(add_virtual_intf, NEW_INTERFACE); |
| 1468 | CMD(change_virtual_intf, SET_INTERFACE); |
| 1469 | CMD(add_key, NEW_KEY); |
| 1470 | CMD(start_ap, START_AP); |
| 1471 | CMD(add_station, NEW_STATION); |
| 1472 | CMD(add_mpath, NEW_MPATH); |
| 1473 | CMD(update_mesh_config, SET_MESH_CONFIG); |
| 1474 | CMD(change_bss, SET_BSS); |
| 1475 | CMD(auth, AUTHENTICATE); |
| 1476 | CMD(assoc, ASSOCIATE); |
| 1477 | CMD(deauth, DEAUTHENTICATE); |
| 1478 | CMD(disassoc, DISASSOCIATE); |
| 1479 | CMD(join_ibss, JOIN_IBSS); |
| 1480 | CMD(join_mesh, JOIN_MESH); |
| 1481 | CMD(set_pmksa, SET_PMKSA); |
| 1482 | CMD(del_pmksa, DEL_PMKSA); |
| 1483 | CMD(flush_pmksa, FLUSH_PMKSA); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1484 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1485 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); |
| 1486 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); |
| 1487 | CMD(mgmt_tx, FRAME); |
| 1488 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1489 | if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1490 | i++; |
| 1491 | if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS)) |
| 1492 | goto nla_put_failure; |
| 1493 | } |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1494 | if (rdev->ops->set_monitor_channel || rdev->ops->start_ap || |
| 1495 | rdev->ops->join_mesh) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1496 | i++; |
| 1497 | if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL)) |
| 1498 | goto nla_put_failure; |
| 1499 | } |
| 1500 | CMD(set_wds_peer, SET_WDS_PEER); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1501 | if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1502 | CMD(tdls_mgmt, TDLS_MGMT); |
| 1503 | CMD(tdls_oper, TDLS_OPER); |
| 1504 | } |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1505 | if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1506 | CMD(sched_scan_start, START_SCHED_SCAN); |
| 1507 | CMD(probe_client, PROBE_CLIENT); |
| 1508 | CMD(set_noack_map, SET_NOACK_MAP); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1509 | if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1510 | i++; |
| 1511 | if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS)) |
| 1512 | goto nla_put_failure; |
| 1513 | } |
| 1514 | CMD(start_p2p_device, START_P2P_DEVICE); |
| 1515 | CMD(set_mcast_rate, SET_MCAST_RATE); |
Johannes Berg | 02df00e | 2014-06-10 14:06:25 +0200 | [diff] [blame] | 1516 | #ifdef CONFIG_NL80211_TESTMODE |
| 1517 | CMD(testmode_cmd, TESTMODE); |
| 1518 | #endif |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1519 | if (state->split) { |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 1520 | CMD(crit_proto_start, CRIT_PROTOCOL_START); |
| 1521 | CMD(crit_proto_stop, CRIT_PROTOCOL_STOP); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1522 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 1523 | CMD(channel_switch, CHANNEL_SWITCH); |
Johannes Berg | 02df00e | 2014-06-10 14:06:25 +0200 | [diff] [blame] | 1524 | CMD(set_qos_map, SET_QOS_MAP); |
Johannes Berg | 723e73a | 2014-10-22 09:25:06 +0200 | [diff] [blame] | 1525 | if (rdev->wiphy.features & |
| 1526 | NL80211_FEATURE_SUPPORTS_WMM_ADMISSION) |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 1527 | CMD(add_tx_ts, ADD_TX_TS); |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 1528 | } |
Johannes Berg | 02df00e | 2014-06-10 14:06:25 +0200 | [diff] [blame] | 1529 | /* add into the if now */ |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1530 | #undef CMD |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1531 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1532 | if (rdev->ops->connect || rdev->ops->auth) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1533 | i++; |
| 1534 | if (nla_put_u32(msg, i, NL80211_CMD_CONNECT)) |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1535 | goto nla_put_failure; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1536 | } |
| 1537 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1538 | if (rdev->ops->disconnect || rdev->ops->deauth) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1539 | i++; |
| 1540 | if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT)) |
| 1541 | goto nla_put_failure; |
| 1542 | } |
Johannes Berg | 74b70a4 | 2010-08-24 12:15:53 +0200 | [diff] [blame] | 1543 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1544 | nla_nest_end(msg, nl_cmds); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1545 | state->split_start++; |
| 1546 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1547 | break; |
| 1548 | case 5: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1549 | if (rdev->ops->remain_on_channel && |
| 1550 | (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1551 | nla_put_u32(msg, |
| 1552 | NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1553 | rdev->wiphy.max_remain_on_channel_duration)) |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1554 | goto nla_put_failure; |
| 1555 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1556 | if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1557 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) |
| 1558 | goto nla_put_failure; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1559 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1560 | if (nl80211_send_mgmt_stypes(msg, mgmt_stypes)) |
| 1561 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1562 | state->split_start++; |
| 1563 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1564 | break; |
| 1565 | case 6: |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 1566 | #ifdef CONFIG_PM |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1567 | if (nl80211_send_wowlan(msg, rdev, state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1568 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1569 | state->split_start++; |
| 1570 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1571 | break; |
| 1572 | #else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1573 | state->split_start++; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1574 | #endif |
| 1575 | case 7: |
| 1576 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1577 | rdev->wiphy.software_iftypes)) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1578 | goto nla_put_failure; |
| 1579 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1580 | if (nl80211_put_iface_combinations(&rdev->wiphy, msg, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1581 | state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1582 | goto nla_put_failure; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1583 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1584 | state->split_start++; |
| 1585 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1586 | break; |
| 1587 | case 8: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1588 | if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1589 | nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1590 | rdev->wiphy.ap_sme_capa)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1591 | goto nla_put_failure; |
| 1592 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1593 | features = rdev->wiphy.features; |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1594 | /* |
| 1595 | * We can only add the per-channel limit information if the |
| 1596 | * dump is split, otherwise it makes it too big. Therefore |
| 1597 | * only advertise it in that case. |
| 1598 | */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1599 | if (state->split) |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1600 | features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS; |
| 1601 | if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1602 | goto nla_put_failure; |
| 1603 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1604 | if (rdev->wiphy.ht_capa_mod_mask && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1605 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1606 | sizeof(*rdev->wiphy.ht_capa_mod_mask), |
| 1607 | rdev->wiphy.ht_capa_mod_mask)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1608 | goto nla_put_failure; |
| 1609 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1610 | if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME && |
| 1611 | rdev->wiphy.max_acl_mac_addrs && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1612 | nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1613 | rdev->wiphy.max_acl_mac_addrs)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1614 | goto nla_put_failure; |
| 1615 | |
| 1616 | /* |
| 1617 | * Any information below this point is only available to |
| 1618 | * applications that can deal with it being split. This |
| 1619 | * helps ensure that newly added capabilities don't break |
| 1620 | * older tools by overrunning their buffers. |
| 1621 | * |
| 1622 | * We still increment split_start so that in the split |
| 1623 | * case we'll continue with more data in the next round, |
| 1624 | * but break unconditionally so unsplit data stops here. |
| 1625 | */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1626 | state->split_start++; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1627 | break; |
| 1628 | case 9: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1629 | if (rdev->wiphy.extended_capabilities && |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1630 | (nla_put(msg, NL80211_ATTR_EXT_CAPA, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1631 | rdev->wiphy.extended_capabilities_len, |
| 1632 | rdev->wiphy.extended_capabilities) || |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1633 | nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1634 | rdev->wiphy.extended_capabilities_len, |
| 1635 | rdev->wiphy.extended_capabilities_mask))) |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1636 | goto nla_put_failure; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1637 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1638 | if (rdev->wiphy.vht_capa_mod_mask && |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 1639 | nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1640 | sizeof(*rdev->wiphy.vht_capa_mod_mask), |
| 1641 | rdev->wiphy.vht_capa_mod_mask)) |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 1642 | goto nla_put_failure; |
| 1643 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1644 | state->split_start++; |
| 1645 | break; |
| 1646 | case 10: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1647 | if (nl80211_send_coalesce(msg, rdev)) |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1648 | goto nla_put_failure; |
| 1649 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1650 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) && |
Felix Fietkau | 01e0daa | 2013-11-09 14:57:54 +0100 | [diff] [blame] | 1651 | (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) || |
| 1652 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ))) |
| 1653 | goto nla_put_failure; |
Jouni Malinen | b43504c | 2014-01-15 00:01:08 +0200 | [diff] [blame] | 1654 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1655 | if (rdev->wiphy.max_ap_assoc_sta && |
Jouni Malinen | b43504c | 2014-01-15 00:01:08 +0200 | [diff] [blame] | 1656 | nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1657 | rdev->wiphy.max_ap_assoc_sta)) |
Jouni Malinen | b43504c | 2014-01-15 00:01:08 +0200 | [diff] [blame] | 1658 | goto nla_put_failure; |
| 1659 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 1660 | state->split_start++; |
| 1661 | break; |
| 1662 | case 11: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1663 | if (rdev->wiphy.n_vendor_commands) { |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1664 | const struct nl80211_vendor_cmd_info *info; |
| 1665 | struct nlattr *nested; |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 1666 | |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1667 | nested = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); |
| 1668 | if (!nested) |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 1669 | goto nla_put_failure; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1670 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1671 | for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { |
| 1672 | info = &rdev->wiphy.vendor_commands[i].info; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1673 | if (nla_put(msg, i + 1, sizeof(*info), info)) |
| 1674 | goto nla_put_failure; |
| 1675 | } |
| 1676 | nla_nest_end(msg, nested); |
| 1677 | } |
| 1678 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1679 | if (rdev->wiphy.n_vendor_events) { |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1680 | const struct nl80211_vendor_cmd_info *info; |
| 1681 | struct nlattr *nested; |
| 1682 | |
| 1683 | nested = nla_nest_start(msg, |
| 1684 | NL80211_ATTR_VENDOR_EVENTS); |
| 1685 | if (!nested) |
| 1686 | goto nla_put_failure; |
| 1687 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1688 | for (i = 0; i < rdev->wiphy.n_vendor_events; i++) { |
| 1689 | info = &rdev->wiphy.vendor_events[i]; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1690 | if (nla_put(msg, i + 1, sizeof(*info), info)) |
| 1691 | goto nla_put_failure; |
| 1692 | } |
| 1693 | nla_nest_end(msg, nested); |
| 1694 | } |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 1695 | state->split_start++; |
| 1696 | break; |
| 1697 | case 12: |
| 1698 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH && |
| 1699 | nla_put_u8(msg, NL80211_ATTR_MAX_CSA_COUNTERS, |
| 1700 | rdev->wiphy.max_num_csa_counters)) |
| 1701 | goto nla_put_failure; |
Felix Fietkau | 01e0daa | 2013-11-09 14:57:54 +0100 | [diff] [blame] | 1702 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1703 | /* done */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1704 | state->split_start = 0; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1705 | break; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1706 | } |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1707 | finish: |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1708 | return genlmsg_end(msg, hdr); |
| 1709 | |
| 1710 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 1711 | genlmsg_cancel(msg, hdr); |
| 1712 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1713 | } |
| 1714 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1715 | static int nl80211_dump_wiphy_parse(struct sk_buff *skb, |
| 1716 | struct netlink_callback *cb, |
| 1717 | struct nl80211_dump_wiphy_state *state) |
| 1718 | { |
| 1719 | struct nlattr **tb = nl80211_fam.attrbuf; |
| 1720 | int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 1721 | tb, nl80211_fam.maxattr, nl80211_policy); |
| 1722 | /* ignore parse errors for backward compatibility */ |
| 1723 | if (ret) |
| 1724 | return 0; |
| 1725 | |
| 1726 | state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP]; |
| 1727 | if (tb[NL80211_ATTR_WIPHY]) |
| 1728 | state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]); |
| 1729 | if (tb[NL80211_ATTR_WDEV]) |
| 1730 | state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32; |
| 1731 | if (tb[NL80211_ATTR_IFINDEX]) { |
| 1732 | struct net_device *netdev; |
| 1733 | struct cfg80211_registered_device *rdev; |
| 1734 | int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); |
| 1735 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 1736 | netdev = __dev_get_by_index(sock_net(skb->sk), ifidx); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1737 | if (!netdev) |
| 1738 | return -ENODEV; |
| 1739 | if (netdev->ieee80211_ptr) { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 1740 | rdev = wiphy_to_rdev( |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1741 | netdev->ieee80211_ptr->wiphy); |
| 1742 | state->filter_wiphy = rdev->wiphy_idx; |
| 1743 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1744 | } |
| 1745 | |
| 1746 | return 0; |
| 1747 | } |
| 1748 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1749 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) |
| 1750 | { |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1751 | int idx = 0, ret; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1752 | struct nl80211_dump_wiphy_state *state = (void *)cb->args[0]; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1753 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 3a5a423 | 2013-06-19 10:09:57 +0200 | [diff] [blame] | 1754 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1755 | rtnl_lock(); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1756 | if (!state) { |
| 1757 | state = kzalloc(sizeof(*state), GFP_KERNEL); |
John W. Linville | 57ed5cd | 2013-06-28 13:18:21 -0400 | [diff] [blame] | 1758 | if (!state) { |
| 1759 | rtnl_unlock(); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1760 | return -ENOMEM; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1761 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1762 | state->filter_wiphy = -1; |
| 1763 | ret = nl80211_dump_wiphy_parse(skb, cb, state); |
| 1764 | if (ret) { |
| 1765 | kfree(state); |
| 1766 | rtnl_unlock(); |
| 1767 | return ret; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1768 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1769 | cb->args[0] = (long)state; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1770 | } |
| 1771 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1772 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 1773 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1774 | continue; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1775 | if (++idx <= state->start) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1776 | continue; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1777 | if (state->filter_wiphy != -1 && |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1778 | state->filter_wiphy != rdev->wiphy_idx) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1779 | continue; |
| 1780 | /* attempt to fit multiple wiphy data chunks into the skb */ |
| 1781 | do { |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1782 | ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, |
| 1783 | skb, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1784 | NETLINK_CB(cb->skb).portid, |
| 1785 | cb->nlh->nlmsg_seq, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1786 | NLM_F_MULTI, state); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1787 | if (ret < 0) { |
| 1788 | /* |
| 1789 | * If sending the wiphy data didn't fit (ENOBUFS |
| 1790 | * or EMSGSIZE returned), this SKB is still |
| 1791 | * empty (so it's not too big because another |
| 1792 | * wiphy dataset is already in the skb) and |
| 1793 | * we've not tried to adjust the dump allocation |
| 1794 | * yet ... then adjust the alloc size to be |
| 1795 | * bigger, and return 1 but with the empty skb. |
| 1796 | * This results in an empty message being RX'ed |
| 1797 | * in userspace, but that is ignored. |
| 1798 | * |
| 1799 | * We can then retry with the larger buffer. |
| 1800 | */ |
| 1801 | if ((ret == -ENOBUFS || ret == -EMSGSIZE) && |
Pontus Fuchs | f12cb28 | 2014-01-16 15:00:40 +0100 | [diff] [blame] | 1802 | !skb->len && !state->split && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1803 | cb->min_dump_alloc < 4096) { |
| 1804 | cb->min_dump_alloc = 4096; |
Pontus Fuchs | f12cb28 | 2014-01-16 15:00:40 +0100 | [diff] [blame] | 1805 | state->split_start = 0; |
David S. Miller | d98cae64e | 2013-06-19 16:49:39 -0700 | [diff] [blame] | 1806 | rtnl_unlock(); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1807 | return 1; |
| 1808 | } |
| 1809 | idx--; |
| 1810 | break; |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1811 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1812 | } while (state->split_start > 0); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1813 | break; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1814 | } |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1815 | rtnl_unlock(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1816 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1817 | state->start = idx; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1818 | |
| 1819 | return skb->len; |
| 1820 | } |
| 1821 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1822 | static int nl80211_dump_wiphy_done(struct netlink_callback *cb) |
| 1823 | { |
| 1824 | kfree((void *)cb->args[0]); |
| 1825 | return 0; |
| 1826 | } |
| 1827 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1828 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1829 | { |
| 1830 | struct sk_buff *msg; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1831 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1832 | struct nl80211_dump_wiphy_state state = {}; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1833 | |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1834 | msg = nlmsg_new(4096, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1835 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1836 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1837 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1838 | if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg, |
| 1839 | info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1840 | &state) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1841 | nlmsg_free(msg); |
| 1842 | return -ENOBUFS; |
| 1843 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1844 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 1845 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1846 | } |
| 1847 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1848 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
| 1849 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, |
| 1850 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, |
| 1851 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, |
| 1852 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, |
| 1853 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, |
| 1854 | }; |
| 1855 | |
| 1856 | static int parse_txq_params(struct nlattr *tb[], |
| 1857 | struct ieee80211_txq_params *txq_params) |
| 1858 | { |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1859 | if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] || |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1860 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
| 1861 | !tb[NL80211_TXQ_ATTR_AIFS]) |
| 1862 | return -EINVAL; |
| 1863 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1864 | txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1865 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
| 1866 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); |
| 1867 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); |
| 1868 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); |
| 1869 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1870 | if (txq_params->ac >= NL80211_NUM_ACS) |
| 1871 | return -EINVAL; |
| 1872 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1873 | return 0; |
| 1874 | } |
| 1875 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1876 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
| 1877 | { |
| 1878 | /* |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1879 | * You can only set the channel explicitly for WDS interfaces, |
| 1880 | * all others have their channel managed via their respective |
| 1881 | * "establish a connection" command (connect, join, ...) |
| 1882 | * |
| 1883 | * For AP/GO and mesh mode, the channel can be set with the |
| 1884 | * channel userspace API, but is only stored and passed to the |
| 1885 | * low-level driver when the AP starts or the mesh is joined. |
| 1886 | * This is for backward compatibility, userspace can also give |
| 1887 | * the channel in the start-ap or join-mesh commands instead. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1888 | * |
| 1889 | * Monitors are special as they are normally slaved to |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1890 | * whatever else is going on, so they have their own special |
| 1891 | * operation to set the monitor channel if possible. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1892 | */ |
| 1893 | return !wdev || |
| 1894 | wdev->iftype == NL80211_IFTYPE_AP || |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1895 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 1896 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
| 1897 | wdev->iftype == NL80211_IFTYPE_P2P_GO; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1898 | } |
| 1899 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1900 | static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev, |
| 1901 | struct genl_info *info, |
| 1902 | struct cfg80211_chan_def *chandef) |
| 1903 | { |
Mahesh Palivela | dbeca2e | 2012-11-29 14:11:07 +0530 | [diff] [blame] | 1904 | u32 control_freq; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1905 | |
| 1906 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 1907 | return -EINVAL; |
| 1908 | |
| 1909 | control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 1910 | |
| 1911 | chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1912 | chandef->width = NL80211_CHAN_WIDTH_20_NOHT; |
| 1913 | chandef->center_freq1 = control_freq; |
| 1914 | chandef->center_freq2 = 0; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1915 | |
| 1916 | /* Primary channel not allowed */ |
| 1917 | if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) |
| 1918 | return -EINVAL; |
| 1919 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1920 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 1921 | enum nl80211_channel_type chantype; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1922 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1923 | chantype = nla_get_u32( |
| 1924 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 1925 | |
| 1926 | switch (chantype) { |
| 1927 | case NL80211_CHAN_NO_HT: |
| 1928 | case NL80211_CHAN_HT20: |
| 1929 | case NL80211_CHAN_HT40PLUS: |
| 1930 | case NL80211_CHAN_HT40MINUS: |
| 1931 | cfg80211_chandef_create(chandef, chandef->chan, |
| 1932 | chantype); |
| 1933 | break; |
| 1934 | default: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1935 | return -EINVAL; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1936 | } |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1937 | } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) { |
| 1938 | chandef->width = |
| 1939 | nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]); |
| 1940 | if (info->attrs[NL80211_ATTR_CENTER_FREQ1]) |
| 1941 | chandef->center_freq1 = |
| 1942 | nla_get_u32( |
| 1943 | info->attrs[NL80211_ATTR_CENTER_FREQ1]); |
| 1944 | if (info->attrs[NL80211_ATTR_CENTER_FREQ2]) |
| 1945 | chandef->center_freq2 = |
| 1946 | nla_get_u32( |
| 1947 | info->attrs[NL80211_ATTR_CENTER_FREQ2]); |
| 1948 | } |
| 1949 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 1950 | if (!cfg80211_chandef_valid(chandef)) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1951 | return -EINVAL; |
| 1952 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 1953 | if (!cfg80211_chandef_usable(&rdev->wiphy, chandef, |
| 1954 | IEEE80211_CHAN_DISABLED)) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1955 | return -EINVAL; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1956 | |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 1957 | if ((chandef->width == NL80211_CHAN_WIDTH_5 || |
| 1958 | chandef->width == NL80211_CHAN_WIDTH_10) && |
| 1959 | !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ)) |
| 1960 | return -EINVAL; |
| 1961 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1962 | return 0; |
| 1963 | } |
| 1964 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1965 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 1966 | struct net_device *dev, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1967 | struct genl_info *info) |
| 1968 | { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1969 | struct cfg80211_chan_def chandef; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1970 | int result; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1971 | enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR; |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 1972 | struct wireless_dev *wdev = NULL; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1973 | |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 1974 | if (dev) |
| 1975 | wdev = dev->ieee80211_ptr; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1976 | if (!nl80211_can_set_dev_channel(wdev)) |
| 1977 | return -EOPNOTSUPP; |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 1978 | if (wdev) |
| 1979 | iftype = wdev->iftype; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1980 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1981 | result = nl80211_parse_chandef(rdev, info, &chandef); |
| 1982 | if (result) |
| 1983 | return result; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1984 | |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1985 | switch (iftype) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1986 | case NL80211_IFTYPE_AP: |
| 1987 | case NL80211_IFTYPE_P2P_GO: |
Ilan Peer | 174e0cd | 2014-02-23 09:13:01 +0200 | [diff] [blame] | 1988 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef, iftype)) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1989 | result = -EINVAL; |
| 1990 | break; |
| 1991 | } |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 1992 | if (wdev->beacon_interval) { |
| 1993 | if (!dev || !rdev->ops->set_ap_chanwidth || |
| 1994 | !(rdev->wiphy.features & |
| 1995 | NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) { |
| 1996 | result = -EBUSY; |
| 1997 | break; |
| 1998 | } |
| 1999 | |
| 2000 | /* Only allow dynamic channel width changes */ |
| 2001 | if (chandef.chan != wdev->preset_chandef.chan) { |
| 2002 | result = -EBUSY; |
| 2003 | break; |
| 2004 | } |
| 2005 | result = rdev_set_ap_chanwidth(rdev, dev, &chandef); |
| 2006 | if (result) |
| 2007 | break; |
| 2008 | } |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2009 | wdev->preset_chandef = chandef; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2010 | result = 0; |
| 2011 | break; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 2012 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2013 | result = cfg80211_set_mesh_channel(rdev, wdev, &chandef); |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 2014 | break; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2015 | case NL80211_IFTYPE_MONITOR: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2016 | result = cfg80211_set_monitor_channel(rdev, &chandef); |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2017 | break; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2018 | default: |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2019 | result = -EINVAL; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2020 | } |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2021 | |
| 2022 | return result; |
| 2023 | } |
| 2024 | |
| 2025 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) |
| 2026 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2027 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2028 | struct net_device *netdev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2029 | |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2030 | return __nl80211_set_channel(rdev, netdev, info); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2031 | } |
| 2032 | |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2033 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
| 2034 | { |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 2035 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2036 | struct net_device *dev = info->user_ptr[1]; |
| 2037 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 388ac77 | 2010-10-07 13:11:09 +0200 | [diff] [blame] | 2038 | const u8 *bssid; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2039 | |
| 2040 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2041 | return -EINVAL; |
| 2042 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 2043 | if (netif_running(dev)) |
| 2044 | return -EBUSY; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2045 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 2046 | if (!rdev->ops->set_wds_peer) |
| 2047 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2048 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 2049 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
| 2050 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2051 | |
| 2052 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2053 | return rdev_set_wds_peer(rdev, dev, bssid); |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2054 | } |
| 2055 | |
| 2056 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2057 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 2058 | { |
| 2059 | struct cfg80211_registered_device *rdev; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2060 | struct net_device *netdev = NULL; |
| 2061 | struct wireless_dev *wdev; |
Bill Jordan | a1e567c | 2010-09-10 11:22:32 -0400 | [diff] [blame] | 2062 | int result = 0, rem_txq_params = 0; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2063 | struct nlattr *nl_txq_params; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2064 | u32 changed; |
| 2065 | u8 retry_short = 0, retry_long = 0; |
| 2066 | u32 frag_threshold = 0, rts_threshold = 0; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2067 | u8 coverage_class = 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2068 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2069 | ASSERT_RTNL(); |
| 2070 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2071 | /* |
| 2072 | * Try to find the wiphy and netdev. Normally this |
| 2073 | * function shouldn't need the netdev, but this is |
| 2074 | * done for backward compatibility -- previously |
| 2075 | * setting the channel was done per wiphy, but now |
| 2076 | * it is per netdev. Previous userland like hostapd |
| 2077 | * also passed a netdev to set_wiphy, so that it is |
| 2078 | * possible to let that go to the right netdev! |
| 2079 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2080 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2081 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
| 2082 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); |
| 2083 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2084 | netdev = __dev_get_by_index(genl_info_net(info), ifindex); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2085 | if (netdev && netdev->ieee80211_ptr) |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 2086 | rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2087 | else |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2088 | netdev = NULL; |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2089 | } |
| 2090 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2091 | if (!netdev) { |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 2092 | rdev = __cfg80211_rdev_from_attrs(genl_info_net(info), |
| 2093 | info->attrs); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2094 | if (IS_ERR(rdev)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2095 | return PTR_ERR(rdev); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2096 | wdev = NULL; |
| 2097 | netdev = NULL; |
| 2098 | result = 0; |
Johannes Berg | 71fe96b | 2012-10-24 10:04:58 +0200 | [diff] [blame] | 2099 | } else |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2100 | wdev = netdev->ieee80211_ptr; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2101 | |
| 2102 | /* |
| 2103 | * end workaround code, by now the rdev is available |
| 2104 | * and locked, and wdev may or may not be NULL. |
| 2105 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2106 | |
| 2107 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2108 | result = cfg80211_dev_rename( |
| 2109 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2110 | |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2111 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2112 | return result; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2113 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2114 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { |
| 2115 | struct ieee80211_txq_params txq_params; |
| 2116 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; |
| 2117 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2118 | if (!rdev->ops->set_txq_params) |
| 2119 | return -EOPNOTSUPP; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2120 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2121 | if (!netdev) |
| 2122 | return -EINVAL; |
Eliad Peller | f70f01c | 2011-09-25 20:06:53 +0300 | [diff] [blame] | 2123 | |
Johannes Berg | 133a3ff | 2011-11-03 14:50:13 +0100 | [diff] [blame] | 2124 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2125 | netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2126 | return -EINVAL; |
Johannes Berg | 133a3ff | 2011-11-03 14:50:13 +0100 | [diff] [blame] | 2127 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2128 | if (!netif_running(netdev)) |
| 2129 | return -ENETDOWN; |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 2130 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2131 | nla_for_each_nested(nl_txq_params, |
| 2132 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], |
| 2133 | rem_txq_params) { |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 2134 | result = nla_parse(tb, NL80211_TXQ_ATTR_MAX, |
| 2135 | nla_data(nl_txq_params), |
| 2136 | nla_len(nl_txq_params), |
| 2137 | txq_params_policy); |
| 2138 | if (result) |
| 2139 | return result; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2140 | result = parse_txq_params(tb, &txq_params); |
| 2141 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2142 | return result; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2143 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2144 | result = rdev_set_txq_params(rdev, netdev, |
| 2145 | &txq_params); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2146 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2147 | return result; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2148 | } |
| 2149 | } |
| 2150 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2151 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2152 | result = __nl80211_set_channel( |
| 2153 | rdev, |
| 2154 | nl80211_can_set_dev_channel(wdev) ? netdev : NULL, |
| 2155 | info); |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2156 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2157 | return result; |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2158 | } |
| 2159 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2160 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2161 | struct wireless_dev *txp_wdev = wdev; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2162 | enum nl80211_tx_power_setting type; |
| 2163 | int idx, mbm = 0; |
| 2164 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2165 | if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER)) |
| 2166 | txp_wdev = NULL; |
| 2167 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2168 | if (!rdev->ops->set_tx_power) |
| 2169 | return -EOPNOTSUPP; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2170 | |
| 2171 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; |
| 2172 | type = nla_get_u32(info->attrs[idx]); |
| 2173 | |
| 2174 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2175 | (type != NL80211_TX_POWER_AUTOMATIC)) |
| 2176 | return -EINVAL; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2177 | |
| 2178 | if (type != NL80211_TX_POWER_AUTOMATIC) { |
| 2179 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; |
| 2180 | mbm = nla_get_u32(info->attrs[idx]); |
| 2181 | } |
| 2182 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2183 | result = rdev_set_tx_power(rdev, txp_wdev, type, mbm); |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2184 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2185 | return result; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2186 | } |
| 2187 | |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2188 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
| 2189 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { |
| 2190 | u32 tx_ant, rx_ant; |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2191 | if ((!rdev->wiphy.available_antennas_tx && |
| 2192 | !rdev->wiphy.available_antennas_rx) || |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2193 | !rdev->ops->set_antenna) |
| 2194 | return -EOPNOTSUPP; |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2195 | |
| 2196 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); |
| 2197 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); |
| 2198 | |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2199 | /* reject antenna configurations which don't match the |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2200 | * available antenna masks, except for the "all" mask */ |
| 2201 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2202 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) |
| 2203 | return -EINVAL; |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2204 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2205 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
| 2206 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2207 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2208 | result = rdev_set_antenna(rdev, tx_ant, rx_ant); |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2209 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2210 | return result; |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2211 | } |
| 2212 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2213 | changed = 0; |
| 2214 | |
| 2215 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { |
| 2216 | retry_short = nla_get_u8( |
| 2217 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2218 | if (retry_short == 0) |
| 2219 | return -EINVAL; |
| 2220 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2221 | changed |= WIPHY_PARAM_RETRY_SHORT; |
| 2222 | } |
| 2223 | |
| 2224 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { |
| 2225 | retry_long = nla_get_u8( |
| 2226 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2227 | if (retry_long == 0) |
| 2228 | return -EINVAL; |
| 2229 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2230 | changed |= WIPHY_PARAM_RETRY_LONG; |
| 2231 | } |
| 2232 | |
| 2233 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { |
| 2234 | frag_threshold = nla_get_u32( |
| 2235 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2236 | if (frag_threshold < 256) |
| 2237 | return -EINVAL; |
| 2238 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2239 | if (frag_threshold != (u32) -1) { |
| 2240 | /* |
| 2241 | * Fragments (apart from the last one) are required to |
| 2242 | * have even length. Make the fragmentation code |
| 2243 | * simpler by stripping LSB should someone try to use |
| 2244 | * odd threshold value. |
| 2245 | */ |
| 2246 | frag_threshold &= ~0x1; |
| 2247 | } |
| 2248 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; |
| 2249 | } |
| 2250 | |
| 2251 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { |
| 2252 | rts_threshold = nla_get_u32( |
| 2253 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); |
| 2254 | changed |= WIPHY_PARAM_RTS_THRESHOLD; |
| 2255 | } |
| 2256 | |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2257 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
Lorenzo Bianconi | 3057dbf | 2014-09-04 23:57:40 +0200 | [diff] [blame] | 2258 | if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) |
| 2259 | return -EINVAL; |
| 2260 | |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2261 | coverage_class = nla_get_u8( |
| 2262 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); |
| 2263 | changed |= WIPHY_PARAM_COVERAGE_CLASS; |
| 2264 | } |
| 2265 | |
Lorenzo Bianconi | 3057dbf | 2014-09-04 23:57:40 +0200 | [diff] [blame] | 2266 | if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) { |
| 2267 | if (!(rdev->wiphy.features & NL80211_FEATURE_ACKTO_ESTIMATION)) |
| 2268 | return -EOPNOTSUPP; |
| 2269 | |
| 2270 | changed |= WIPHY_PARAM_DYN_ACK; |
| 2271 | } |
| 2272 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2273 | if (changed) { |
| 2274 | u8 old_retry_short, old_retry_long; |
| 2275 | u32 old_frag_threshold, old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2276 | u8 old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2277 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2278 | if (!rdev->ops->set_wiphy_params) |
| 2279 | return -EOPNOTSUPP; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2280 | |
| 2281 | old_retry_short = rdev->wiphy.retry_short; |
| 2282 | old_retry_long = rdev->wiphy.retry_long; |
| 2283 | old_frag_threshold = rdev->wiphy.frag_threshold; |
| 2284 | old_rts_threshold = rdev->wiphy.rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2285 | old_coverage_class = rdev->wiphy.coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2286 | |
| 2287 | if (changed & WIPHY_PARAM_RETRY_SHORT) |
| 2288 | rdev->wiphy.retry_short = retry_short; |
| 2289 | if (changed & WIPHY_PARAM_RETRY_LONG) |
| 2290 | rdev->wiphy.retry_long = retry_long; |
| 2291 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) |
| 2292 | rdev->wiphy.frag_threshold = frag_threshold; |
| 2293 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) |
| 2294 | rdev->wiphy.rts_threshold = rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2295 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
| 2296 | rdev->wiphy.coverage_class = coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2297 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2298 | result = rdev_set_wiphy_params(rdev, changed); |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2299 | if (result) { |
| 2300 | rdev->wiphy.retry_short = old_retry_short; |
| 2301 | rdev->wiphy.retry_long = old_retry_long; |
| 2302 | rdev->wiphy.frag_threshold = old_frag_threshold; |
| 2303 | rdev->wiphy.rts_threshold = old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2304 | rdev->wiphy.coverage_class = old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2305 | } |
| 2306 | } |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2307 | return 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2308 | } |
| 2309 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 2310 | static inline u64 wdev_id(struct wireless_dev *wdev) |
| 2311 | { |
| 2312 | return (u64)wdev->identifier | |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 2313 | ((u64)wiphy_to_rdev(wdev->wiphy)->wiphy_idx << 32); |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 2314 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2315 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2316 | static int nl80211_send_chandef(struct sk_buff *msg, |
Janusz Dziedzic | d2859df | 2013-11-06 13:55:51 +0100 | [diff] [blame] | 2317 | const struct cfg80211_chan_def *chandef) |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2318 | { |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 2319 | WARN_ON(!cfg80211_chandef_valid(chandef)); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2320 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2321 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
| 2322 | chandef->chan->center_freq)) |
| 2323 | return -ENOBUFS; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2324 | switch (chandef->width) { |
| 2325 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 2326 | case NL80211_CHAN_WIDTH_20: |
| 2327 | case NL80211_CHAN_WIDTH_40: |
| 2328 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 2329 | cfg80211_get_chandef_type(chandef))) |
| 2330 | return -ENOBUFS; |
| 2331 | break; |
| 2332 | default: |
| 2333 | break; |
| 2334 | } |
| 2335 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width)) |
| 2336 | return -ENOBUFS; |
| 2337 | if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1)) |
| 2338 | return -ENOBUFS; |
| 2339 | if (chandef->center_freq2 && |
| 2340 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2)) |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2341 | return -ENOBUFS; |
| 2342 | return 0; |
| 2343 | } |
| 2344 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2345 | 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] | 2346 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2347 | struct wireless_dev *wdev) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2348 | { |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2349 | struct net_device *dev = wdev->netdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2350 | void *hdr; |
| 2351 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2352 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_INTERFACE); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2353 | if (!hdr) |
| 2354 | return -1; |
| 2355 | |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2356 | if (dev && |
| 2357 | (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2358 | nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name))) |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2359 | goto nla_put_failure; |
| 2360 | |
| 2361 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 2362 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 2363 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2364 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2365 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
| 2366 | rdev->devlist_generation ^ |
| 2367 | (cfg80211_rdev_list_generation << 2))) |
| 2368 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2369 | |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 2370 | if (rdev->ops->get_channel) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2371 | int ret; |
| 2372 | struct cfg80211_chan_def chandef; |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 2373 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2374 | ret = rdev_get_channel(rdev, wdev, &chandef); |
| 2375 | if (ret == 0) { |
| 2376 | if (nl80211_send_chandef(msg, &chandef)) |
| 2377 | goto nla_put_failure; |
| 2378 | } |
Pontus Fuchs | d91df0e | 2012-04-03 16:39:58 +0200 | [diff] [blame] | 2379 | } |
| 2380 | |
Antonio Quartulli | b84e7a0 | 2012-11-07 12:52:20 +0100 | [diff] [blame] | 2381 | if (wdev->ssid_len) { |
| 2382 | if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid)) |
| 2383 | goto nla_put_failure; |
| 2384 | } |
| 2385 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2386 | return genlmsg_end(msg, hdr); |
| 2387 | |
| 2388 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 2389 | genlmsg_cancel(msg, hdr); |
| 2390 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2391 | } |
| 2392 | |
| 2393 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) |
| 2394 | { |
| 2395 | int wp_idx = 0; |
| 2396 | int if_idx = 0; |
| 2397 | int wp_start = cb->args[0]; |
| 2398 | int if_start = cb->args[1]; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2399 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2400 | struct wireless_dev *wdev; |
| 2401 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2402 | rtnl_lock(); |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2403 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 2404 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2405 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2406 | if (wp_idx < wp_start) { |
| 2407 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2408 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2409 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2410 | if_idx = 0; |
| 2411 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 2412 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2413 | if (if_idx < if_start) { |
| 2414 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2415 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2416 | } |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2417 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2418 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2419 | rdev, wdev) < 0) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2420 | goto out; |
| 2421 | } |
| 2422 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2423 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2424 | |
| 2425 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2426 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2427 | out: |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2428 | rtnl_unlock(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2429 | |
| 2430 | cb->args[0] = wp_idx; |
| 2431 | cb->args[1] = if_idx; |
| 2432 | |
| 2433 | return skb->len; |
| 2434 | } |
| 2435 | |
| 2436 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) |
| 2437 | { |
| 2438 | struct sk_buff *msg; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2439 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2440 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2441 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2442 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2443 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2444 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2445 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2446 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2447 | rdev, wdev) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2448 | nlmsg_free(msg); |
| 2449 | return -ENOBUFS; |
| 2450 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2451 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 2452 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2453 | } |
| 2454 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2455 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
| 2456 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, |
| 2457 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, |
| 2458 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, |
| 2459 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, |
| 2460 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2461 | [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG }, |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2462 | }; |
| 2463 | |
| 2464 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) |
| 2465 | { |
| 2466 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; |
| 2467 | int flag; |
| 2468 | |
| 2469 | *mntrflags = 0; |
| 2470 | |
| 2471 | if (!nla) |
| 2472 | return -EINVAL; |
| 2473 | |
| 2474 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, |
| 2475 | nla, mntr_flags_policy)) |
| 2476 | return -EINVAL; |
| 2477 | |
| 2478 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) |
| 2479 | if (flags[flag]) |
| 2480 | *mntrflags |= (1<<flag); |
| 2481 | |
| 2482 | return 0; |
| 2483 | } |
| 2484 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2485 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2486 | struct net_device *netdev, u8 use_4addr, |
| 2487 | enum nl80211_iftype iftype) |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2488 | { |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2489 | if (!use_4addr) { |
Jiri Pirko | f350a0a8 | 2010-06-15 06:50:45 +0000 | [diff] [blame] | 2490 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2491 | return -EBUSY; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2492 | return 0; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2493 | } |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2494 | |
| 2495 | switch (iftype) { |
| 2496 | case NL80211_IFTYPE_AP_VLAN: |
| 2497 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) |
| 2498 | return 0; |
| 2499 | break; |
| 2500 | case NL80211_IFTYPE_STATION: |
| 2501 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) |
| 2502 | return 0; |
| 2503 | break; |
| 2504 | default: |
| 2505 | break; |
| 2506 | } |
| 2507 | |
| 2508 | return -EOPNOTSUPP; |
| 2509 | } |
| 2510 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2511 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
| 2512 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2513 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2514 | struct vif_params params; |
Johannes Berg | e36d56b | 2009-06-09 21:04:43 +0200 | [diff] [blame] | 2515 | int err; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2516 | enum nl80211_iftype otype, ntype; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2517 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2518 | u32 _flags, *flags = NULL; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2519 | bool change = false; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2520 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2521 | memset(¶ms, 0, sizeof(params)); |
| 2522 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2523 | otype = ntype = dev->ieee80211_ptr->iftype; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2524 | |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 2525 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2526 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2527 | if (otype != ntype) |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2528 | change = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2529 | if (ntype > NL80211_IFTYPE_MAX) |
| 2530 | return -EINVAL; |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 2531 | } |
| 2532 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2533 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2534 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2535 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2536 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
| 2537 | return -EINVAL; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2538 | if (netif_running(dev)) |
| 2539 | return -EBUSY; |
| 2540 | |
| 2541 | wdev_lock(wdev); |
| 2542 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 2543 | IEEE80211_MAX_MESH_ID_LEN); |
| 2544 | wdev->mesh_id_up_len = |
| 2545 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 2546 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 2547 | wdev->mesh_id_up_len); |
| 2548 | wdev_unlock(wdev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2549 | } |
| 2550 | |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2551 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
| 2552 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
| 2553 | change = true; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2554 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2555 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2556 | return err; |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2557 | } else { |
| 2558 | params.use_4addr = -1; |
| 2559 | } |
| 2560 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2561 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2562 | if (ntype != NL80211_IFTYPE_MONITOR) |
| 2563 | return -EINVAL; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2564 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
| 2565 | &_flags); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2566 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2567 | return err; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2568 | |
| 2569 | flags = &_flags; |
| 2570 | change = true; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2571 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2572 | |
Luciano Coelho | 1800329 | 2013-08-29 13:26:57 +0300 | [diff] [blame] | 2573 | if (flags && (*flags & MONITOR_FLAG_ACTIVE) && |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2574 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
| 2575 | return -EOPNOTSUPP; |
| 2576 | |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2577 | if (change) |
Johannes Berg | 3d54d25 | 2009-08-21 14:51:05 +0200 | [diff] [blame] | 2578 | err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2579 | else |
| 2580 | err = 0; |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 2581 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2582 | if (!err && params.use_4addr != -1) |
| 2583 | dev->ieee80211_ptr->use_4addr = params.use_4addr; |
| 2584 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2585 | return err; |
| 2586 | } |
| 2587 | |
| 2588 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) |
| 2589 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2590 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2591 | struct vif_params params; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2592 | struct wireless_dev *wdev; |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2593 | struct sk_buff *msg; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2594 | int err; |
| 2595 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2596 | u32 flags; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2597 | |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 2598 | /* to avoid failing a new interface creation due to pending removal */ |
| 2599 | cfg80211_destroy_ifaces(rdev); |
| 2600 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2601 | memset(¶ms, 0, sizeof(params)); |
| 2602 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2603 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
| 2604 | return -EINVAL; |
| 2605 | |
| 2606 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
| 2607 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
| 2608 | if (type > NL80211_IFTYPE_MAX) |
| 2609 | return -EINVAL; |
| 2610 | } |
| 2611 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2612 | if (!rdev->ops->add_virtual_intf || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2613 | !(rdev->wiphy.interface_modes & (1 << type))) |
| 2614 | return -EOPNOTSUPP; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2615 | |
Ben Greear | e8f479b | 2014-10-22 12:23:05 -0700 | [diff] [blame] | 2616 | if ((type == NL80211_IFTYPE_P2P_DEVICE || |
| 2617 | rdev->wiphy.features & NL80211_FEATURE_MAC_ON_CREATE) && |
| 2618 | info->attrs[NL80211_ATTR_MAC]) { |
Arend van Spriel | 1c18f14 | 2013-01-08 10:17:27 +0100 | [diff] [blame] | 2619 | nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC], |
| 2620 | ETH_ALEN); |
| 2621 | if (!is_valid_ether_addr(params.macaddr)) |
| 2622 | return -EADDRNOTAVAIL; |
| 2623 | } |
| 2624 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2625 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2626 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2627 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2628 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2629 | return err; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2630 | } |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2631 | |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2632 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 2633 | if (!msg) |
| 2634 | return -ENOMEM; |
| 2635 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2636 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
| 2637 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, |
| 2638 | &flags); |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2639 | |
Luciano Coelho | 1800329 | 2013-08-29 13:26:57 +0300 | [diff] [blame] | 2640 | if (!err && (flags & MONITOR_FLAG_ACTIVE) && |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2641 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
| 2642 | return -EOPNOTSUPP; |
| 2643 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2644 | wdev = rdev_add_virtual_intf(rdev, |
| 2645 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), |
| 2646 | type, err ? NULL : &flags, ¶ms); |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2647 | if (IS_ERR(wdev)) { |
| 2648 | nlmsg_free(msg); |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2649 | return PTR_ERR(wdev); |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2650 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2651 | |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 2652 | if (info->attrs[NL80211_ATTR_IFACE_SOCKET_OWNER]) |
| 2653 | wdev->owner_nlportid = info->snd_portid; |
| 2654 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2655 | switch (type) { |
| 2656 | case NL80211_IFTYPE_MESH_POINT: |
| 2657 | if (!info->attrs[NL80211_ATTR_MESH_ID]) |
| 2658 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2659 | wdev_lock(wdev); |
| 2660 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 2661 | IEEE80211_MAX_MESH_ID_LEN); |
| 2662 | wdev->mesh_id_up_len = |
| 2663 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 2664 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 2665 | wdev->mesh_id_up_len); |
| 2666 | wdev_unlock(wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2667 | break; |
| 2668 | case NL80211_IFTYPE_P2P_DEVICE: |
| 2669 | /* |
| 2670 | * P2P Device doesn't have a netdev, so doesn't go |
| 2671 | * through the netdev notifier and must be added here |
| 2672 | */ |
| 2673 | mutex_init(&wdev->mtx); |
| 2674 | INIT_LIST_HEAD(&wdev->event_list); |
| 2675 | spin_lock_init(&wdev->event_lock); |
| 2676 | INIT_LIST_HEAD(&wdev->mgmt_registrations); |
| 2677 | spin_lock_init(&wdev->mgmt_registrations_lock); |
| 2678 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2679 | wdev->identifier = ++rdev->wdev_id; |
| 2680 | list_add_rcu(&wdev->list, &rdev->wdev_list); |
| 2681 | rdev->devlist_generation++; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2682 | break; |
| 2683 | default: |
| 2684 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2685 | } |
| 2686 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2687 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2688 | rdev, wdev) < 0) { |
| 2689 | nlmsg_free(msg); |
| 2690 | return -ENOBUFS; |
| 2691 | } |
| 2692 | |
| 2693 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2694 | } |
| 2695 | |
| 2696 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) |
| 2697 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2698 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2699 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2700 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2701 | if (!rdev->ops->del_virtual_intf) |
| 2702 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2703 | |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2704 | /* |
| 2705 | * If we remove a wireless device without a netdev then clear |
| 2706 | * user_ptr[1] so that nl80211_post_doit won't dereference it |
| 2707 | * to check if it needs to do dev_put(). Otherwise it crashes |
| 2708 | * since the wdev has been freed, unlike with a netdev where |
| 2709 | * we need the dev_put() for the netdev to really be freed. |
| 2710 | */ |
| 2711 | if (!wdev->netdev) |
| 2712 | info->user_ptr[1] = NULL; |
| 2713 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2714 | return rdev_del_virtual_intf(rdev, wdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2715 | } |
| 2716 | |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 2717 | static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info) |
| 2718 | { |
| 2719 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2720 | struct net_device *dev = info->user_ptr[1]; |
| 2721 | u16 noack_map; |
| 2722 | |
| 2723 | if (!info->attrs[NL80211_ATTR_NOACK_MAP]) |
| 2724 | return -EINVAL; |
| 2725 | |
| 2726 | if (!rdev->ops->set_noack_map) |
| 2727 | return -EOPNOTSUPP; |
| 2728 | |
| 2729 | noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]); |
| 2730 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2731 | return rdev_set_noack_map(rdev, dev, noack_map); |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 2732 | } |
| 2733 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2734 | struct get_key_cookie { |
| 2735 | struct sk_buff *msg; |
| 2736 | int error; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2737 | int idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2738 | }; |
| 2739 | |
| 2740 | static void get_key_callback(void *c, struct key_params *params) |
| 2741 | { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2742 | struct nlattr *key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2743 | struct get_key_cookie *cookie = c; |
| 2744 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2745 | if ((params->key && |
| 2746 | nla_put(cookie->msg, NL80211_ATTR_KEY_DATA, |
| 2747 | params->key_len, params->key)) || |
| 2748 | (params->seq && |
| 2749 | nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ, |
| 2750 | params->seq_len, params->seq)) || |
| 2751 | (params->cipher && |
| 2752 | nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER, |
| 2753 | params->cipher))) |
| 2754 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2755 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2756 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
| 2757 | if (!key) |
| 2758 | goto nla_put_failure; |
| 2759 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2760 | if ((params->key && |
| 2761 | nla_put(cookie->msg, NL80211_KEY_DATA, |
| 2762 | params->key_len, params->key)) || |
| 2763 | (params->seq && |
| 2764 | nla_put(cookie->msg, NL80211_KEY_SEQ, |
| 2765 | params->seq_len, params->seq)) || |
| 2766 | (params->cipher && |
| 2767 | nla_put_u32(cookie->msg, NL80211_KEY_CIPHER, |
| 2768 | params->cipher))) |
| 2769 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2770 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2771 | if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx)) |
| 2772 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2773 | |
| 2774 | nla_nest_end(cookie->msg, key); |
| 2775 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2776 | return; |
| 2777 | nla_put_failure: |
| 2778 | cookie->error = 1; |
| 2779 | } |
| 2780 | |
| 2781 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) |
| 2782 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2783 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2784 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2785 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2786 | u8 key_idx = 0; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2787 | const u8 *mac_addr = NULL; |
| 2788 | bool pairwise; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2789 | struct get_key_cookie cookie = { |
| 2790 | .error = 0, |
| 2791 | }; |
| 2792 | void *hdr; |
| 2793 | struct sk_buff *msg; |
| 2794 | |
| 2795 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 2796 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 2797 | |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 2798 | if (key_idx > 5) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2799 | return -EINVAL; |
| 2800 | |
| 2801 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2802 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2803 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2804 | pairwise = !!mac_addr; |
| 2805 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 2806 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 2807 | if (kt >= NUM_NL80211_KEYTYPES) |
| 2808 | return -EINVAL; |
| 2809 | if (kt != NL80211_KEYTYPE_GROUP && |
| 2810 | kt != NL80211_KEYTYPE_PAIRWISE) |
| 2811 | return -EINVAL; |
| 2812 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; |
| 2813 | } |
| 2814 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2815 | if (!rdev->ops->get_key) |
| 2816 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2817 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2818 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2819 | if (!msg) |
| 2820 | return -ENOMEM; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2821 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2822 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2823 | NL80211_CMD_NEW_KEY); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 2824 | if (!hdr) |
Johannes Berg | 9fe271a | 2013-10-25 11:15:12 +0200 | [diff] [blame] | 2825 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2826 | |
| 2827 | cookie.msg = msg; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2828 | cookie.idx = key_idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2829 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2830 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 2831 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) |
| 2832 | goto nla_put_failure; |
| 2833 | if (mac_addr && |
| 2834 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 2835 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2836 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2837 | if (pairwise && mac_addr && |
| 2838 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 2839 | return -ENOENT; |
| 2840 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2841 | err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie, |
| 2842 | get_key_callback); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2843 | |
| 2844 | if (err) |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 2845 | goto free_msg; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2846 | |
| 2847 | if (cookie.error) |
| 2848 | goto nla_put_failure; |
| 2849 | |
| 2850 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2851 | return genlmsg_reply(msg, info); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2852 | |
| 2853 | nla_put_failure: |
| 2854 | err = -ENOBUFS; |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 2855 | free_msg: |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2856 | nlmsg_free(msg); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2857 | return err; |
| 2858 | } |
| 2859 | |
| 2860 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) |
| 2861 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2862 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2863 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2864 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2865 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2866 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2867 | err = nl80211_parse_key(info, &key); |
| 2868 | if (err) |
| 2869 | return err; |
| 2870 | |
| 2871 | if (key.idx < 0) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2872 | return -EINVAL; |
| 2873 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2874 | /* only support setting default key */ |
| 2875 | if (!key.def && !key.defmgmt) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2876 | return -EINVAL; |
| 2877 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2878 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2879 | |
| 2880 | if (key.def) { |
| 2881 | if (!rdev->ops->set_default_key) { |
| 2882 | err = -EOPNOTSUPP; |
| 2883 | goto out; |
| 2884 | } |
| 2885 | |
| 2886 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2887 | if (err) |
| 2888 | goto out; |
| 2889 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2890 | err = rdev_set_default_key(rdev, dev, key.idx, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2891 | key.def_uni, key.def_multi); |
| 2892 | |
| 2893 | if (err) |
| 2894 | goto out; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2895 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 2896 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2897 | dev->ieee80211_ptr->wext.default_key = key.idx; |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2898 | #endif |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2899 | } else { |
| 2900 | if (key.def_uni || !key.def_multi) { |
| 2901 | err = -EINVAL; |
| 2902 | goto out; |
| 2903 | } |
| 2904 | |
| 2905 | if (!rdev->ops->set_default_mgmt_key) { |
| 2906 | err = -EOPNOTSUPP; |
| 2907 | goto out; |
| 2908 | } |
| 2909 | |
| 2910 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2911 | if (err) |
| 2912 | goto out; |
| 2913 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2914 | err = rdev_set_default_mgmt_key(rdev, dev, key.idx); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2915 | if (err) |
| 2916 | goto out; |
| 2917 | |
| 2918 | #ifdef CONFIG_CFG80211_WEXT |
| 2919 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; |
| 2920 | #endif |
| 2921 | } |
| 2922 | |
| 2923 | out: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2924 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2925 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2926 | return err; |
| 2927 | } |
| 2928 | |
| 2929 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) |
| 2930 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2931 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2932 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2933 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2934 | struct key_parse key; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2935 | const u8 *mac_addr = NULL; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2936 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2937 | err = nl80211_parse_key(info, &key); |
| 2938 | if (err) |
| 2939 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2940 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2941 | if (!key.p.key) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2942 | return -EINVAL; |
| 2943 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2944 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2945 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2946 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2947 | if (key.type == -1) { |
| 2948 | if (mac_addr) |
| 2949 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 2950 | else |
| 2951 | key.type = NL80211_KEYTYPE_GROUP; |
| 2952 | } |
| 2953 | |
| 2954 | /* for now */ |
| 2955 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 2956 | key.type != NL80211_KEYTYPE_GROUP) |
| 2957 | return -EINVAL; |
| 2958 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2959 | if (!rdev->ops->add_key) |
| 2960 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2961 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2962 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
| 2963 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2964 | mac_addr)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2965 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2966 | |
| 2967 | wdev_lock(dev->ieee80211_ptr); |
| 2968 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2969 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2970 | err = rdev_add_key(rdev, dev, key.idx, |
| 2971 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2972 | mac_addr, &key.p); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2973 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2974 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2975 | return err; |
| 2976 | } |
| 2977 | |
| 2978 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) |
| 2979 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2980 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2981 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2982 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2983 | u8 *mac_addr = NULL; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2984 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2985 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2986 | err = nl80211_parse_key(info, &key); |
| 2987 | if (err) |
| 2988 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2989 | |
| 2990 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2991 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2992 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2993 | if (key.type == -1) { |
| 2994 | if (mac_addr) |
| 2995 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 2996 | else |
| 2997 | key.type = NL80211_KEYTYPE_GROUP; |
| 2998 | } |
| 2999 | |
| 3000 | /* for now */ |
| 3001 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 3002 | key.type != NL80211_KEYTYPE_GROUP) |
| 3003 | return -EINVAL; |
| 3004 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3005 | if (!rdev->ops->del_key) |
| 3006 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3007 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3008 | wdev_lock(dev->ieee80211_ptr); |
| 3009 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3010 | |
| 3011 | if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr && |
| 3012 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 3013 | err = -ENOENT; |
| 3014 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3015 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3016 | err = rdev_del_key(rdev, dev, key.idx, |
| 3017 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 3018 | mac_addr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3019 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 3020 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 3021 | if (!err) { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3022 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 3023 | dev->ieee80211_ptr->wext.default_key = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3024 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 3025 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
| 3026 | } |
| 3027 | #endif |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3028 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 3029 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3030 | return err; |
| 3031 | } |
| 3032 | |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 3033 | /* This function returns an error or the number of nested attributes */ |
| 3034 | static int validate_acl_mac_addrs(struct nlattr *nl_attr) |
| 3035 | { |
| 3036 | struct nlattr *attr; |
| 3037 | int n_entries = 0, tmp; |
| 3038 | |
| 3039 | nla_for_each_nested(attr, nl_attr, tmp) { |
| 3040 | if (nla_len(attr) != ETH_ALEN) |
| 3041 | return -EINVAL; |
| 3042 | |
| 3043 | n_entries++; |
| 3044 | } |
| 3045 | |
| 3046 | return n_entries; |
| 3047 | } |
| 3048 | |
| 3049 | /* |
| 3050 | * This function parses ACL information and allocates memory for ACL data. |
| 3051 | * On successful return, the calling function is responsible to free the |
| 3052 | * ACL buffer returned by this function. |
| 3053 | */ |
| 3054 | static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy, |
| 3055 | struct genl_info *info) |
| 3056 | { |
| 3057 | enum nl80211_acl_policy acl_policy; |
| 3058 | struct nlattr *attr; |
| 3059 | struct cfg80211_acl_data *acl; |
| 3060 | int i = 0, n_entries, tmp; |
| 3061 | |
| 3062 | if (!wiphy->max_acl_mac_addrs) |
| 3063 | return ERR_PTR(-EOPNOTSUPP); |
| 3064 | |
| 3065 | if (!info->attrs[NL80211_ATTR_ACL_POLICY]) |
| 3066 | return ERR_PTR(-EINVAL); |
| 3067 | |
| 3068 | acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]); |
| 3069 | if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED && |
| 3070 | acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED) |
| 3071 | return ERR_PTR(-EINVAL); |
| 3072 | |
| 3073 | if (!info->attrs[NL80211_ATTR_MAC_ADDRS]) |
| 3074 | return ERR_PTR(-EINVAL); |
| 3075 | |
| 3076 | n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]); |
| 3077 | if (n_entries < 0) |
| 3078 | return ERR_PTR(n_entries); |
| 3079 | |
| 3080 | if (n_entries > wiphy->max_acl_mac_addrs) |
| 3081 | return ERR_PTR(-ENOTSUPP); |
| 3082 | |
| 3083 | acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries), |
| 3084 | GFP_KERNEL); |
| 3085 | if (!acl) |
| 3086 | return ERR_PTR(-ENOMEM); |
| 3087 | |
| 3088 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) { |
| 3089 | memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN); |
| 3090 | i++; |
| 3091 | } |
| 3092 | |
| 3093 | acl->n_acl_entries = n_entries; |
| 3094 | acl->acl_policy = acl_policy; |
| 3095 | |
| 3096 | return acl; |
| 3097 | } |
| 3098 | |
| 3099 | static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info) |
| 3100 | { |
| 3101 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3102 | struct net_device *dev = info->user_ptr[1]; |
| 3103 | struct cfg80211_acl_data *acl; |
| 3104 | int err; |
| 3105 | |
| 3106 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3107 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3108 | return -EOPNOTSUPP; |
| 3109 | |
| 3110 | if (!dev->ieee80211_ptr->beacon_interval) |
| 3111 | return -EINVAL; |
| 3112 | |
| 3113 | acl = parse_acl_data(&rdev->wiphy, info); |
| 3114 | if (IS_ERR(acl)) |
| 3115 | return PTR_ERR(acl); |
| 3116 | |
| 3117 | err = rdev_set_mac_acl(rdev, dev, acl); |
| 3118 | |
| 3119 | kfree(acl); |
| 3120 | |
| 3121 | return err; |
| 3122 | } |
| 3123 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3124 | static int nl80211_parse_beacon(struct nlattr *attrs[], |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3125 | struct cfg80211_beacon_data *bcn) |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3126 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3127 | bool haveinfo = false; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3128 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3129 | if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) || |
| 3130 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) || |
| 3131 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) || |
| 3132 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP])) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 3133 | return -EINVAL; |
| 3134 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3135 | memset(bcn, 0, sizeof(*bcn)); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3136 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3137 | if (attrs[NL80211_ATTR_BEACON_HEAD]) { |
| 3138 | bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]); |
| 3139 | bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3140 | if (!bcn->head_len) |
| 3141 | return -EINVAL; |
| 3142 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3143 | } |
| 3144 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3145 | if (attrs[NL80211_ATTR_BEACON_TAIL]) { |
| 3146 | bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]); |
| 3147 | bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3148 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3149 | } |
| 3150 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3151 | if (!haveinfo) |
| 3152 | return -EINVAL; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3153 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3154 | if (attrs[NL80211_ATTR_IE]) { |
| 3155 | bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]); |
| 3156 | bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 3157 | } |
| 3158 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3159 | if (attrs[NL80211_ATTR_IE_PROBE_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3160 | bcn->proberesp_ies = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3161 | nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3162 | bcn->proberesp_ies_len = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3163 | nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 3164 | } |
| 3165 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3166 | if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3167 | bcn->assocresp_ies = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3168 | nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3169 | bcn->assocresp_ies_len = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3170 | nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 3171 | } |
| 3172 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3173 | if (attrs[NL80211_ATTR_PROBE_RESP]) { |
| 3174 | bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]); |
| 3175 | bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]); |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 3176 | } |
| 3177 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3178 | return 0; |
| 3179 | } |
| 3180 | |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3181 | static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev, |
| 3182 | struct cfg80211_ap_settings *params) |
| 3183 | { |
| 3184 | struct wireless_dev *wdev; |
| 3185 | bool ret = false; |
| 3186 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 3187 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3188 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 3189 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 3190 | continue; |
| 3191 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3192 | if (!wdev->preset_chandef.chan) |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3193 | continue; |
| 3194 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3195 | params->chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3196 | ret = true; |
| 3197 | break; |
| 3198 | } |
| 3199 | |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3200 | return ret; |
| 3201 | } |
| 3202 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 3203 | static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev, |
| 3204 | enum nl80211_auth_type auth_type, |
| 3205 | enum nl80211_commands cmd) |
| 3206 | { |
| 3207 | if (auth_type > NL80211_AUTHTYPE_MAX) |
| 3208 | return false; |
| 3209 | |
| 3210 | switch (cmd) { |
| 3211 | case NL80211_CMD_AUTHENTICATE: |
| 3212 | if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && |
| 3213 | auth_type == NL80211_AUTHTYPE_SAE) |
| 3214 | return false; |
| 3215 | return true; |
| 3216 | case NL80211_CMD_CONNECT: |
| 3217 | case NL80211_CMD_START_AP: |
| 3218 | /* SAE not supported yet */ |
| 3219 | if (auth_type == NL80211_AUTHTYPE_SAE) |
| 3220 | return false; |
| 3221 | return true; |
| 3222 | default: |
| 3223 | return false; |
| 3224 | } |
| 3225 | } |
| 3226 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3227 | static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) |
| 3228 | { |
| 3229 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3230 | struct net_device *dev = info->user_ptr[1]; |
| 3231 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3232 | struct cfg80211_ap_settings params; |
| 3233 | int err; |
| 3234 | |
| 3235 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3236 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3237 | return -EOPNOTSUPP; |
| 3238 | |
| 3239 | if (!rdev->ops->start_ap) |
| 3240 | return -EOPNOTSUPP; |
| 3241 | |
| 3242 | if (wdev->beacon_interval) |
| 3243 | return -EALREADY; |
| 3244 | |
| 3245 | memset(¶ms, 0, sizeof(params)); |
| 3246 | |
| 3247 | /* these are required for START_AP */ |
| 3248 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || |
| 3249 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || |
| 3250 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) |
| 3251 | return -EINVAL; |
| 3252 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3253 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3254 | if (err) |
| 3255 | return err; |
| 3256 | |
| 3257 | params.beacon_interval = |
| 3258 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 3259 | params.dtim_period = |
| 3260 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 3261 | |
| 3262 | err = cfg80211_validate_beacon_int(rdev, params.beacon_interval); |
| 3263 | if (err) |
| 3264 | return err; |
| 3265 | |
| 3266 | /* |
| 3267 | * In theory, some of these attributes should be required here |
| 3268 | * but since they were not used when the command was originally |
| 3269 | * added, keep them optional for old user space programs to let |
| 3270 | * them continue to work with drivers that do not need the |
| 3271 | * additional information -- drivers must check! |
| 3272 | */ |
| 3273 | if (info->attrs[NL80211_ATTR_SSID]) { |
| 3274 | params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 3275 | params.ssid_len = |
| 3276 | nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 3277 | if (params.ssid_len == 0 || |
| 3278 | params.ssid_len > IEEE80211_MAX_SSID_LEN) |
| 3279 | return -EINVAL; |
| 3280 | } |
| 3281 | |
| 3282 | if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) { |
| 3283 | params.hidden_ssid = nla_get_u32( |
| 3284 | info->attrs[NL80211_ATTR_HIDDEN_SSID]); |
| 3285 | if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE && |
| 3286 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN && |
| 3287 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS) |
| 3288 | return -EINVAL; |
| 3289 | } |
| 3290 | |
| 3291 | params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
| 3292 | |
| 3293 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 3294 | params.auth_type = nla_get_u32( |
| 3295 | info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 3296 | if (!nl80211_valid_auth_type(rdev, params.auth_type, |
| 3297 | NL80211_CMD_START_AP)) |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3298 | return -EINVAL; |
| 3299 | } else |
| 3300 | params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 3301 | |
| 3302 | err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, |
| 3303 | NL80211_MAX_NR_CIPHER_SUITES); |
| 3304 | if (err) |
| 3305 | return err; |
| 3306 | |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 3307 | if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) { |
| 3308 | if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER)) |
| 3309 | return -EOPNOTSUPP; |
| 3310 | params.inactivity_timeout = nla_get_u16( |
| 3311 | info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]); |
| 3312 | } |
| 3313 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 3314 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 3315 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3316 | return -EINVAL; |
| 3317 | params.p2p_ctwindow = |
| 3318 | nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
| 3319 | if (params.p2p_ctwindow > 127) |
| 3320 | return -EINVAL; |
| 3321 | if (params.p2p_ctwindow != 0 && |
| 3322 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 3323 | return -EINVAL; |
| 3324 | } |
| 3325 | |
| 3326 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 3327 | u8 tmp; |
| 3328 | |
| 3329 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3330 | return -EINVAL; |
| 3331 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
| 3332 | if (tmp > 1) |
| 3333 | return -EINVAL; |
| 3334 | params.p2p_opp_ps = tmp; |
| 3335 | if (params.p2p_opp_ps != 0 && |
| 3336 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 3337 | return -EINVAL; |
| 3338 | } |
| 3339 | |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3340 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3341 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
| 3342 | if (err) |
| 3343 | return err; |
| 3344 | } else if (wdev->preset_chandef.chan) { |
| 3345 | params.chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3346 | } else if (!nl80211_get_ap_channel(rdev, ¶ms)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3347 | return -EINVAL; |
| 3348 | |
Ilan Peer | 174e0cd | 2014-02-23 09:13:01 +0200 | [diff] [blame] | 3349 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, ¶ms.chandef, |
| 3350 | wdev->iftype)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3351 | return -EINVAL; |
| 3352 | |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 3353 | if (info->attrs[NL80211_ATTR_ACL_POLICY]) { |
| 3354 | params.acl = parse_acl_data(&rdev->wiphy, info); |
| 3355 | if (IS_ERR(params.acl)) |
| 3356 | return PTR_ERR(params.acl); |
| 3357 | } |
| 3358 | |
Eliad Peller | 18998c3 | 2014-09-10 14:07:34 +0300 | [diff] [blame] | 3359 | if (info->attrs[NL80211_ATTR_SMPS_MODE]) { |
| 3360 | params.smps_mode = |
| 3361 | nla_get_u8(info->attrs[NL80211_ATTR_SMPS_MODE]); |
| 3362 | switch (params.smps_mode) { |
| 3363 | case NL80211_SMPS_OFF: |
| 3364 | break; |
| 3365 | case NL80211_SMPS_STATIC: |
| 3366 | if (!(rdev->wiphy.features & |
| 3367 | NL80211_FEATURE_STATIC_SMPS)) |
| 3368 | return -EINVAL; |
| 3369 | break; |
| 3370 | case NL80211_SMPS_DYNAMIC: |
| 3371 | if (!(rdev->wiphy.features & |
| 3372 | NL80211_FEATURE_DYNAMIC_SMPS)) |
| 3373 | return -EINVAL; |
| 3374 | break; |
| 3375 | default: |
| 3376 | return -EINVAL; |
| 3377 | } |
| 3378 | } else { |
| 3379 | params.smps_mode = NL80211_SMPS_OFF; |
| 3380 | } |
| 3381 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 3382 | wdev_lock(wdev); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3383 | err = rdev_start_ap(rdev, dev, ¶ms); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3384 | if (!err) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3385 | wdev->preset_chandef = params.chandef; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3386 | wdev->beacon_interval = params.beacon_interval; |
Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 3387 | wdev->chandef = params.chandef; |
Antonio Quartulli | 06e191e | 2012-11-07 12:52:19 +0100 | [diff] [blame] | 3388 | wdev->ssid_len = params.ssid_len; |
| 3389 | memcpy(wdev->ssid, params.ssid, wdev->ssid_len); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3390 | } |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 3391 | wdev_unlock(wdev); |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 3392 | |
| 3393 | kfree(params.acl); |
| 3394 | |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 3395 | return err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3396 | } |
| 3397 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3398 | static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info) |
| 3399 | { |
| 3400 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3401 | struct net_device *dev = info->user_ptr[1]; |
| 3402 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3403 | struct cfg80211_beacon_data params; |
| 3404 | int err; |
| 3405 | |
| 3406 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3407 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3408 | return -EOPNOTSUPP; |
| 3409 | |
| 3410 | if (!rdev->ops->change_beacon) |
| 3411 | return -EOPNOTSUPP; |
| 3412 | |
| 3413 | if (!wdev->beacon_interval) |
| 3414 | return -EINVAL; |
| 3415 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3416 | err = nl80211_parse_beacon(info->attrs, ¶ms); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3417 | if (err) |
| 3418 | return err; |
| 3419 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 3420 | wdev_lock(wdev); |
| 3421 | err = rdev_change_beacon(rdev, dev, ¶ms); |
| 3422 | wdev_unlock(wdev); |
| 3423 | |
| 3424 | return err; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3425 | } |
| 3426 | |
| 3427 | 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] | 3428 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3429 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3430 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3431 | |
Ilan Peer | 7c8d5e0 | 2014-02-25 15:33:38 +0200 | [diff] [blame] | 3432 | return cfg80211_stop_ap(rdev, dev, false); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3433 | } |
| 3434 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3435 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
| 3436 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, |
| 3437 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, |
| 3438 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, |
Jouni Malinen | 0e46724 | 2009-05-11 21:57:55 +0300 | [diff] [blame] | 3439 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 3440 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
Johannes Berg | d83023d | 2011-12-14 09:29:15 +0100 | [diff] [blame] | 3441 | [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3442 | }; |
| 3443 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3444 | static int parse_station_flags(struct genl_info *info, |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3445 | enum nl80211_iftype iftype, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3446 | struct station_parameters *params) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3447 | { |
| 3448 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3449 | struct nlattr *nla; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3450 | int flag; |
| 3451 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3452 | /* |
| 3453 | * Try parsing the new attribute first so userspace |
| 3454 | * can specify both for older kernels. |
| 3455 | */ |
| 3456 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; |
| 3457 | if (nla) { |
| 3458 | struct nl80211_sta_flag_update *sta_flags; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3459 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3460 | sta_flags = nla_data(nla); |
| 3461 | params->sta_flags_mask = sta_flags->mask; |
| 3462 | params->sta_flags_set = sta_flags->set; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3463 | params->sta_flags_set &= params->sta_flags_mask; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3464 | if ((params->sta_flags_mask | |
| 3465 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) |
| 3466 | return -EINVAL; |
| 3467 | return 0; |
| 3468 | } |
| 3469 | |
| 3470 | /* if present, parse the old attribute */ |
| 3471 | |
| 3472 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3473 | if (!nla) |
| 3474 | return 0; |
| 3475 | |
| 3476 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, |
| 3477 | nla, sta_flags_policy)) |
| 3478 | return -EINVAL; |
| 3479 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3480 | /* |
| 3481 | * Only allow certain flags for interface types so that |
| 3482 | * other attributes are silently ignored. Remember that |
| 3483 | * this is backward compatibility code with old userspace |
| 3484 | * and shouldn't be hit in other cases anyway. |
| 3485 | */ |
| 3486 | switch (iftype) { |
| 3487 | case NL80211_IFTYPE_AP: |
| 3488 | case NL80211_IFTYPE_AP_VLAN: |
| 3489 | case NL80211_IFTYPE_P2P_GO: |
| 3490 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3491 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 3492 | BIT(NL80211_STA_FLAG_WME) | |
| 3493 | BIT(NL80211_STA_FLAG_MFP); |
| 3494 | break; |
| 3495 | case NL80211_IFTYPE_P2P_CLIENT: |
| 3496 | case NL80211_IFTYPE_STATION: |
| 3497 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3498 | BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3499 | break; |
| 3500 | case NL80211_IFTYPE_MESH_POINT: |
| 3501 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3502 | BIT(NL80211_STA_FLAG_MFP) | |
| 3503 | BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 3504 | default: |
| 3505 | return -EINVAL; |
| 3506 | } |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3507 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 3508 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) { |
| 3509 | if (flags[flag]) { |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3510 | params->sta_flags_set |= (1<<flag); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3511 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 3512 | /* no longer support new API additions in old API */ |
| 3513 | if (flag > NL80211_STA_FLAG_MAX_OLD_API) |
| 3514 | return -EINVAL; |
| 3515 | } |
| 3516 | } |
| 3517 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3518 | return 0; |
| 3519 | } |
| 3520 | |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3521 | static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, |
| 3522 | int attr) |
| 3523 | { |
| 3524 | struct nlattr *rate; |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 3525 | u32 bitrate; |
| 3526 | u16 bitrate_compat; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3527 | |
| 3528 | rate = nla_nest_start(msg, attr); |
| 3529 | if (!rate) |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 3530 | return false; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3531 | |
| 3532 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ |
| 3533 | bitrate = cfg80211_calculate_bitrate(info); |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 3534 | /* report 16-bit bitrate only if we can */ |
| 3535 | bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 3536 | if (bitrate > 0 && |
| 3537 | nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate)) |
| 3538 | return false; |
| 3539 | if (bitrate_compat > 0 && |
| 3540 | nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat)) |
| 3541 | return false; |
| 3542 | |
| 3543 | if (info->flags & RATE_INFO_FLAGS_MCS) { |
| 3544 | if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) |
| 3545 | return false; |
| 3546 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && |
| 3547 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) |
| 3548 | return false; |
| 3549 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 3550 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 3551 | return false; |
| 3552 | } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) { |
| 3553 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs)) |
| 3554 | return false; |
| 3555 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss)) |
| 3556 | return false; |
| 3557 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && |
| 3558 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) |
| 3559 | return false; |
| 3560 | if (info->flags & RATE_INFO_FLAGS_80_MHZ_WIDTH && |
| 3561 | nla_put_flag(msg, NL80211_RATE_INFO_80_MHZ_WIDTH)) |
| 3562 | return false; |
| 3563 | if (info->flags & RATE_INFO_FLAGS_80P80_MHZ_WIDTH && |
| 3564 | nla_put_flag(msg, NL80211_RATE_INFO_80P80_MHZ_WIDTH)) |
| 3565 | return false; |
| 3566 | if (info->flags & RATE_INFO_FLAGS_160_MHZ_WIDTH && |
| 3567 | nla_put_flag(msg, NL80211_RATE_INFO_160_MHZ_WIDTH)) |
| 3568 | return false; |
| 3569 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 3570 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 3571 | return false; |
| 3572 | } |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3573 | |
| 3574 | nla_nest_end(msg, rate); |
| 3575 | return true; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3576 | } |
| 3577 | |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 3578 | static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal, |
| 3579 | int id) |
| 3580 | { |
| 3581 | void *attr; |
| 3582 | int i = 0; |
| 3583 | |
| 3584 | if (!mask) |
| 3585 | return true; |
| 3586 | |
| 3587 | attr = nla_nest_start(msg, id); |
| 3588 | if (!attr) |
| 3589 | return false; |
| 3590 | |
| 3591 | for (i = 0; i < IEEE80211_MAX_CHAINS; i++) { |
| 3592 | if (!(mask & BIT(i))) |
| 3593 | continue; |
| 3594 | |
| 3595 | if (nla_put_u8(msg, i, signal[i])) |
| 3596 | return false; |
| 3597 | } |
| 3598 | |
| 3599 | nla_nest_end(msg, attr); |
| 3600 | |
| 3601 | return true; |
| 3602 | } |
| 3603 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3604 | 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] | 3605 | int flags, |
| 3606 | struct cfg80211_registered_device *rdev, |
| 3607 | struct net_device *dev, |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 3608 | const u8 *mac_addr, struct station_info *sinfo) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3609 | { |
| 3610 | void *hdr; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3611 | struct nlattr *sinfoattr, *bss_param; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3612 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3613 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3614 | if (!hdr) |
| 3615 | return -1; |
| 3616 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3617 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 3618 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 3619 | nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation)) |
| 3620 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 3621 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3622 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
| 3623 | if (!sinfoattr) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3624 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3625 | if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) && |
| 3626 | nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME, |
| 3627 | sinfo->connected_time)) |
| 3628 | goto nla_put_failure; |
| 3629 | if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) && |
| 3630 | nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME, |
| 3631 | sinfo->inactive_time)) |
| 3632 | goto nla_put_failure; |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3633 | if ((sinfo->filled & (STATION_INFO_RX_BYTES | |
| 3634 | STATION_INFO_RX_BYTES64)) && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3635 | nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES, |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3636 | (u32)sinfo->rx_bytes)) |
| 3637 | goto nla_put_failure; |
| 3638 | if ((sinfo->filled & (STATION_INFO_TX_BYTES | |
Felix Fietkau | 4325d72 | 2013-05-23 15:05:59 +0200 | [diff] [blame] | 3639 | STATION_INFO_TX_BYTES64)) && |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3640 | nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES, |
| 3641 | (u32)sinfo->tx_bytes)) |
| 3642 | goto nla_put_failure; |
| 3643 | if ((sinfo->filled & STATION_INFO_RX_BYTES64) && |
| 3644 | nla_put_u64(msg, NL80211_STA_INFO_RX_BYTES64, |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3645 | sinfo->rx_bytes)) |
| 3646 | goto nla_put_failure; |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3647 | if ((sinfo->filled & STATION_INFO_TX_BYTES64) && |
| 3648 | nla_put_u64(msg, NL80211_STA_INFO_TX_BYTES64, |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3649 | sinfo->tx_bytes)) |
| 3650 | goto nla_put_failure; |
| 3651 | if ((sinfo->filled & STATION_INFO_LLID) && |
| 3652 | nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid)) |
| 3653 | goto nla_put_failure; |
| 3654 | if ((sinfo->filled & STATION_INFO_PLID) && |
| 3655 | nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid)) |
| 3656 | goto nla_put_failure; |
| 3657 | if ((sinfo->filled & STATION_INFO_PLINK_STATE) && |
| 3658 | nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE, |
| 3659 | sinfo->plink_state)) |
| 3660 | goto nla_put_failure; |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3661 | switch (rdev->wiphy.signal_type) { |
| 3662 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3663 | if ((sinfo->filled & STATION_INFO_SIGNAL) && |
| 3664 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL, |
| 3665 | sinfo->signal)) |
| 3666 | goto nla_put_failure; |
| 3667 | if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) && |
| 3668 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG, |
| 3669 | sinfo->signal_avg)) |
| 3670 | goto nla_put_failure; |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3671 | break; |
| 3672 | default: |
| 3673 | break; |
| 3674 | } |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 3675 | if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL) { |
| 3676 | if (!nl80211_put_signal(msg, sinfo->chains, |
| 3677 | sinfo->chain_signal, |
| 3678 | NL80211_STA_INFO_CHAIN_SIGNAL)) |
| 3679 | goto nla_put_failure; |
| 3680 | } |
| 3681 | if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL_AVG) { |
| 3682 | if (!nl80211_put_signal(msg, sinfo->chains, |
| 3683 | sinfo->chain_signal_avg, |
| 3684 | NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) |
| 3685 | goto nla_put_failure; |
| 3686 | } |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3687 | if (sinfo->filled & STATION_INFO_TX_BITRATE) { |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3688 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
| 3689 | NL80211_STA_INFO_TX_BITRATE)) |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3690 | goto nla_put_failure; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3691 | } |
| 3692 | if (sinfo->filled & STATION_INFO_RX_BITRATE) { |
| 3693 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, |
| 3694 | NL80211_STA_INFO_RX_BITRATE)) |
| 3695 | goto nla_put_failure; |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3696 | } |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3697 | if ((sinfo->filled & STATION_INFO_RX_PACKETS) && |
| 3698 | nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS, |
| 3699 | sinfo->rx_packets)) |
| 3700 | goto nla_put_failure; |
| 3701 | if ((sinfo->filled & STATION_INFO_TX_PACKETS) && |
| 3702 | nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS, |
| 3703 | sinfo->tx_packets)) |
| 3704 | goto nla_put_failure; |
| 3705 | if ((sinfo->filled & STATION_INFO_TX_RETRIES) && |
| 3706 | nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES, |
| 3707 | sinfo->tx_retries)) |
| 3708 | goto nla_put_failure; |
| 3709 | if ((sinfo->filled & STATION_INFO_TX_FAILED) && |
| 3710 | nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED, |
| 3711 | sinfo->tx_failed)) |
| 3712 | goto nla_put_failure; |
Antonio Quartulli | 867d849 | 2014-05-19 21:53:19 +0200 | [diff] [blame] | 3713 | if ((sinfo->filled & STATION_INFO_EXPECTED_THROUGHPUT) && |
| 3714 | nla_put_u32(msg, NL80211_STA_INFO_EXPECTED_THROUGHPUT, |
| 3715 | sinfo->expected_throughput)) |
| 3716 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3717 | if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) && |
| 3718 | nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS, |
| 3719 | sinfo->beacon_loss_count)) |
| 3720 | goto nla_put_failure; |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 3721 | if ((sinfo->filled & STATION_INFO_LOCAL_PM) && |
| 3722 | nla_put_u32(msg, NL80211_STA_INFO_LOCAL_PM, |
| 3723 | sinfo->local_pm)) |
| 3724 | goto nla_put_failure; |
| 3725 | if ((sinfo->filled & STATION_INFO_PEER_PM) && |
| 3726 | nla_put_u32(msg, NL80211_STA_INFO_PEER_PM, |
| 3727 | sinfo->peer_pm)) |
| 3728 | goto nla_put_failure; |
| 3729 | if ((sinfo->filled & STATION_INFO_NONPEER_PM) && |
| 3730 | nla_put_u32(msg, NL80211_STA_INFO_NONPEER_PM, |
| 3731 | sinfo->nonpeer_pm)) |
| 3732 | goto nla_put_failure; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3733 | if (sinfo->filled & STATION_INFO_BSS_PARAM) { |
| 3734 | bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); |
| 3735 | if (!bss_param) |
| 3736 | goto nla_put_failure; |
| 3737 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3738 | if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) && |
| 3739 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) || |
| 3740 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) && |
| 3741 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) || |
| 3742 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) && |
| 3743 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) || |
| 3744 | nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, |
| 3745 | sinfo->bss_param.dtim_period) || |
| 3746 | nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, |
| 3747 | sinfo->bss_param.beacon_interval)) |
| 3748 | goto nla_put_failure; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3749 | |
| 3750 | nla_nest_end(msg, bss_param); |
| 3751 | } |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3752 | if ((sinfo->filled & STATION_INFO_STA_FLAGS) && |
| 3753 | nla_put(msg, NL80211_STA_INFO_STA_FLAGS, |
| 3754 | sizeof(struct nl80211_sta_flag_update), |
| 3755 | &sinfo->sta_flags)) |
| 3756 | goto nla_put_failure; |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 3757 | if ((sinfo->filled & STATION_INFO_T_OFFSET) && |
| 3758 | nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET, |
| 3759 | sinfo->t_offset)) |
| 3760 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3761 | nla_nest_end(msg, sinfoattr); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3762 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3763 | if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) && |
| 3764 | nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, |
| 3765 | sinfo->assoc_req_ies)) |
| 3766 | goto nla_put_failure; |
Jouni Malinen | 50d3dfb | 2011-08-08 12:11:52 +0300 | [diff] [blame] | 3767 | |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3768 | return genlmsg_end(msg, hdr); |
| 3769 | |
| 3770 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 3771 | genlmsg_cancel(msg, hdr); |
| 3772 | return -EMSGSIZE; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3773 | } |
| 3774 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3775 | static int nl80211_dump_station(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3776 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3777 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3778 | struct station_info sinfo; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 3779 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3780 | struct wireless_dev *wdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3781 | u8 mac_addr[ETH_ALEN]; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3782 | int sta_idx = cb->args[2]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3783 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3784 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 3785 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3786 | if (err) |
| 3787 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3788 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3789 | if (!wdev->netdev) { |
| 3790 | err = -EINVAL; |
| 3791 | goto out_err; |
| 3792 | } |
| 3793 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 3794 | if (!rdev->ops->dump_station) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3795 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3796 | goto out_err; |
| 3797 | } |
| 3798 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3799 | while (1) { |
Jouni Malinen | f612ced | 2011-08-11 11:46:22 +0300 | [diff] [blame] | 3800 | memset(&sinfo, 0, sizeof(sinfo)); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 3801 | err = rdev_dump_station(rdev, wdev->netdev, sta_idx, |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3802 | mac_addr, &sinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3803 | if (err == -ENOENT) |
| 3804 | break; |
| 3805 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3806 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3807 | |
| 3808 | if (nl80211_send_station(skb, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3809 | NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3810 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 3811 | rdev, wdev->netdev, mac_addr, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3812 | &sinfo) < 0) |
| 3813 | goto out; |
| 3814 | |
| 3815 | sta_idx++; |
| 3816 | } |
| 3817 | |
| 3818 | |
| 3819 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3820 | cb->args[2] = sta_idx; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3821 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3822 | out_err: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 3823 | nl80211_finish_wdev_dump(rdev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3824 | |
| 3825 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3826 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3827 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3828 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
| 3829 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3830 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3831 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3832 | struct station_info sinfo; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3833 | struct sk_buff *msg; |
| 3834 | u8 *mac_addr = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3835 | int err; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3836 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3837 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3838 | |
| 3839 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3840 | return -EINVAL; |
| 3841 | |
| 3842 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3843 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3844 | if (!rdev->ops->get_station) |
| 3845 | return -EOPNOTSUPP; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3846 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3847 | err = rdev_get_station(rdev, dev, mac_addr, &sinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3848 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3849 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3850 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3851 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3852 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3853 | return -ENOMEM; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3854 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3855 | 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] | 3856 | rdev, dev, mac_addr, &sinfo) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3857 | nlmsg_free(msg); |
| 3858 | return -ENOBUFS; |
| 3859 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3860 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3861 | return genlmsg_reply(msg, info); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3862 | } |
| 3863 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3864 | int cfg80211_check_station_change(struct wiphy *wiphy, |
| 3865 | struct station_parameters *params, |
| 3866 | enum cfg80211_station_type statype) |
| 3867 | { |
| 3868 | if (params->listen_interval != -1) |
| 3869 | return -EINVAL; |
Arik Nemtsov | c72e114 | 2014-07-17 17:14:29 +0300 | [diff] [blame] | 3870 | if (params->aid && |
| 3871 | !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3872 | return -EINVAL; |
| 3873 | |
| 3874 | /* When you run into this, adjust the code below for the new flag */ |
| 3875 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); |
| 3876 | |
| 3877 | switch (statype) { |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 3878 | case CFG80211_STA_MESH_PEER_KERNEL: |
| 3879 | case CFG80211_STA_MESH_PEER_USER: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3880 | /* |
| 3881 | * No ignoring the TDLS flag here -- the userspace mesh |
| 3882 | * code doesn't have the bug of including TDLS in the |
| 3883 | * mask everywhere. |
| 3884 | */ |
| 3885 | if (params->sta_flags_mask & |
| 3886 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3887 | BIT(NL80211_STA_FLAG_MFP) | |
| 3888 | BIT(NL80211_STA_FLAG_AUTHORIZED))) |
| 3889 | return -EINVAL; |
| 3890 | break; |
| 3891 | case CFG80211_STA_TDLS_PEER_SETUP: |
| 3892 | case CFG80211_STA_TDLS_PEER_ACTIVE: |
| 3893 | if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 3894 | return -EINVAL; |
| 3895 | /* ignore since it can't change */ |
| 3896 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3897 | break; |
| 3898 | default: |
| 3899 | /* disallow mesh-specific things */ |
| 3900 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) |
| 3901 | return -EINVAL; |
| 3902 | if (params->local_pm) |
| 3903 | return -EINVAL; |
| 3904 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
| 3905 | return -EINVAL; |
| 3906 | } |
| 3907 | |
| 3908 | if (statype != CFG80211_STA_TDLS_PEER_SETUP && |
| 3909 | statype != CFG80211_STA_TDLS_PEER_ACTIVE) { |
| 3910 | /* TDLS can't be set, ... */ |
| 3911 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
| 3912 | return -EINVAL; |
| 3913 | /* |
| 3914 | * ... but don't bother the driver with it. This works around |
| 3915 | * a hostapd/wpa_supplicant issue -- it always includes the |
| 3916 | * TLDS_PEER flag in the mask even for AP mode. |
| 3917 | */ |
| 3918 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3919 | } |
| 3920 | |
| 3921 | if (statype != CFG80211_STA_TDLS_PEER_SETUP) { |
| 3922 | /* reject other things that can't change */ |
| 3923 | if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) |
| 3924 | return -EINVAL; |
| 3925 | if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY) |
| 3926 | return -EINVAL; |
| 3927 | if (params->supported_rates) |
| 3928 | return -EINVAL; |
| 3929 | if (params->ext_capab || params->ht_capa || params->vht_capa) |
| 3930 | return -EINVAL; |
| 3931 | } |
| 3932 | |
| 3933 | if (statype != CFG80211_STA_AP_CLIENT) { |
| 3934 | if (params->vlan) |
| 3935 | return -EINVAL; |
| 3936 | } |
| 3937 | |
| 3938 | switch (statype) { |
| 3939 | case CFG80211_STA_AP_MLME_CLIENT: |
| 3940 | /* Use this only for authorizing/unauthorizing a station */ |
| 3941 | if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))) |
| 3942 | return -EOPNOTSUPP; |
| 3943 | break; |
| 3944 | case CFG80211_STA_AP_CLIENT: |
| 3945 | /* accept only the listed bits */ |
| 3946 | if (params->sta_flags_mask & |
| 3947 | ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3948 | BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3949 | BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 3950 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 3951 | BIT(NL80211_STA_FLAG_WME) | |
| 3952 | BIT(NL80211_STA_FLAG_MFP))) |
| 3953 | return -EINVAL; |
| 3954 | |
| 3955 | /* but authenticated/associated only if driver handles it */ |
| 3956 | if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
| 3957 | params->sta_flags_mask & |
| 3958 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3959 | BIT(NL80211_STA_FLAG_ASSOCIATED))) |
| 3960 | return -EINVAL; |
| 3961 | break; |
| 3962 | case CFG80211_STA_IBSS: |
| 3963 | case CFG80211_STA_AP_STA: |
| 3964 | /* reject any changes other than AUTHORIZED */ |
| 3965 | if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) |
| 3966 | return -EINVAL; |
| 3967 | break; |
| 3968 | case CFG80211_STA_TDLS_PEER_SETUP: |
| 3969 | /* reject any changes other than AUTHORIZED or WME */ |
| 3970 | if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3971 | BIT(NL80211_STA_FLAG_WME))) |
| 3972 | return -EINVAL; |
| 3973 | /* force (at least) rates when authorizing */ |
| 3974 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) && |
| 3975 | !params->supported_rates) |
| 3976 | return -EINVAL; |
| 3977 | break; |
| 3978 | case CFG80211_STA_TDLS_PEER_ACTIVE: |
| 3979 | /* reject any changes */ |
| 3980 | return -EINVAL; |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 3981 | case CFG80211_STA_MESH_PEER_KERNEL: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3982 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
| 3983 | return -EINVAL; |
| 3984 | break; |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 3985 | case CFG80211_STA_MESH_PEER_USER: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3986 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) |
| 3987 | return -EINVAL; |
| 3988 | break; |
| 3989 | } |
| 3990 | |
| 3991 | return 0; |
| 3992 | } |
| 3993 | EXPORT_SYMBOL(cfg80211_check_station_change); |
| 3994 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3995 | /* |
Felix Fietkau | c258d2d | 2009-11-11 17:23:31 +0100 | [diff] [blame] | 3996 | * 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] | 3997 | */ |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3998 | static struct net_device *get_vlan(struct genl_info *info, |
| 3999 | struct cfg80211_registered_device *rdev) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4000 | { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4001 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 4002 | struct net_device *v; |
| 4003 | int ret; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4004 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 4005 | if (!vlanattr) |
| 4006 | return NULL; |
| 4007 | |
| 4008 | v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); |
| 4009 | if (!v) |
| 4010 | return ERR_PTR(-ENODEV); |
| 4011 | |
| 4012 | if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { |
| 4013 | ret = -EINVAL; |
| 4014 | goto error; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4015 | } |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 4016 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4017 | if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
| 4018 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 4019 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { |
| 4020 | ret = -EINVAL; |
| 4021 | goto error; |
| 4022 | } |
| 4023 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 4024 | if (!netif_running(v)) { |
| 4025 | ret = -ENETDOWN; |
| 4026 | goto error; |
| 4027 | } |
| 4028 | |
| 4029 | return v; |
| 4030 | error: |
| 4031 | dev_put(v); |
| 4032 | return ERR_PTR(ret); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4033 | } |
| 4034 | |
Johannes Berg | 94e860f | 2014-01-20 23:58:15 +0100 | [diff] [blame] | 4035 | static const struct nla_policy |
| 4036 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = { |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 4037 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, |
| 4038 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, |
| 4039 | }; |
| 4040 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4041 | static int nl80211_parse_sta_wme(struct genl_info *info, |
| 4042 | struct station_parameters *params) |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 4043 | { |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 4044 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; |
| 4045 | struct nlattr *nla; |
| 4046 | int err; |
| 4047 | |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 4048 | /* parse WME attributes if present */ |
| 4049 | if (!info->attrs[NL80211_ATTR_STA_WME]) |
| 4050 | return 0; |
| 4051 | |
| 4052 | nla = info->attrs[NL80211_ATTR_STA_WME]; |
| 4053 | err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla, |
| 4054 | nl80211_sta_wme_policy); |
| 4055 | if (err) |
| 4056 | return err; |
| 4057 | |
| 4058 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) |
| 4059 | params->uapsd_queues = nla_get_u8( |
| 4060 | tb[NL80211_STA_WME_UAPSD_QUEUES]); |
| 4061 | if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) |
| 4062 | return -EINVAL; |
| 4063 | |
| 4064 | if (tb[NL80211_STA_WME_MAX_SP]) |
| 4065 | params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); |
| 4066 | |
| 4067 | if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) |
| 4068 | return -EINVAL; |
| 4069 | |
| 4070 | params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; |
| 4071 | |
| 4072 | return 0; |
| 4073 | } |
| 4074 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 4075 | static int nl80211_parse_sta_channel_info(struct genl_info *info, |
| 4076 | struct station_parameters *params) |
| 4077 | { |
| 4078 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) { |
| 4079 | params->supported_channels = |
| 4080 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); |
| 4081 | params->supported_channels_len = |
| 4082 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); |
| 4083 | /* |
| 4084 | * Need to include at least one (first channel, number of |
| 4085 | * channels) tuple for each subband, and must have proper |
| 4086 | * tuples for the rest of the data as well. |
| 4087 | */ |
| 4088 | if (params->supported_channels_len < 2) |
| 4089 | return -EINVAL; |
| 4090 | if (params->supported_channels_len % 2) |
| 4091 | return -EINVAL; |
| 4092 | } |
| 4093 | |
| 4094 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) { |
| 4095 | params->supported_oper_classes = |
| 4096 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); |
| 4097 | params->supported_oper_classes_len = |
| 4098 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); |
| 4099 | /* |
| 4100 | * The value of the Length field of the Supported Operating |
| 4101 | * Classes element is between 2 and 253. |
| 4102 | */ |
| 4103 | if (params->supported_oper_classes_len < 2 || |
| 4104 | params->supported_oper_classes_len > 253) |
| 4105 | return -EINVAL; |
| 4106 | } |
| 4107 | return 0; |
| 4108 | } |
| 4109 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4110 | static int nl80211_set_station_tdls(struct genl_info *info, |
| 4111 | struct station_parameters *params) |
| 4112 | { |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 4113 | int err; |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4114 | /* Dummy STA entry gets updated once the peer capabilities are known */ |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 4115 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
| 4116 | params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4117 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 4118 | params->ht_capa = |
| 4119 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
| 4120 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 4121 | params->vht_capa = |
| 4122 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 4123 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 4124 | err = nl80211_parse_sta_channel_info(info, params); |
| 4125 | if (err) |
| 4126 | return err; |
| 4127 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4128 | return nl80211_parse_sta_wme(info, params); |
| 4129 | } |
| 4130 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4131 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
| 4132 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4133 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4134 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4135 | struct station_parameters params; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4136 | u8 *mac_addr; |
| 4137 | int err; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4138 | |
| 4139 | memset(¶ms, 0, sizeof(params)); |
| 4140 | |
| 4141 | params.listen_interval = -1; |
| 4142 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4143 | if (!rdev->ops->change_station) |
| 4144 | return -EOPNOTSUPP; |
| 4145 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4146 | if (info->attrs[NL80211_ATTR_STA_AID]) |
| 4147 | return -EINVAL; |
| 4148 | |
| 4149 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4150 | return -EINVAL; |
| 4151 | |
| 4152 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4153 | |
| 4154 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { |
| 4155 | params.supported_rates = |
| 4156 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4157 | params.supported_rates_len = |
| 4158 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4159 | } |
| 4160 | |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 4161 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
| 4162 | params.capability = |
| 4163 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); |
| 4164 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; |
| 4165 | } |
| 4166 | |
| 4167 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { |
| 4168 | params.ext_capab = |
| 4169 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4170 | params.ext_capab_len = |
| 4171 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4172 | } |
| 4173 | |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 4174 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
Johannes Berg | ba23d20 | 2012-12-27 17:32:09 +0100 | [diff] [blame] | 4175 | return -EINVAL; |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 4176 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 4177 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4178 | return -EINVAL; |
| 4179 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4180 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4181 | params.plink_action = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4182 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 4183 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) |
| 4184 | return -EINVAL; |
| 4185 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4186 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4187 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) { |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 4188 | params.plink_state = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4189 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
| 4190 | if (params.plink_state >= NUM_NL80211_PLINK_STATES) |
| 4191 | return -EINVAL; |
| 4192 | params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE; |
| 4193 | } |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 4194 | |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4195 | if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) { |
| 4196 | enum nl80211_mesh_power_mode pm = nla_get_u32( |
| 4197 | info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]); |
| 4198 | |
| 4199 | if (pm <= NL80211_MESH_POWER_UNKNOWN || |
| 4200 | pm > NL80211_MESH_POWER_MAX) |
| 4201 | return -EINVAL; |
| 4202 | |
| 4203 | params.local_pm = pm; |
| 4204 | } |
| 4205 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4206 | /* Include parameters for TDLS peer (will check later) */ |
| 4207 | err = nl80211_set_station_tdls(info, ¶ms); |
| 4208 | if (err) |
| 4209 | return err; |
| 4210 | |
| 4211 | params.vlan = get_vlan(info, rdev); |
| 4212 | if (IS_ERR(params.vlan)) |
| 4213 | return PTR_ERR(params.vlan); |
| 4214 | |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4215 | switch (dev->ieee80211_ptr->iftype) { |
| 4216 | case NL80211_IFTYPE_AP: |
| 4217 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4218 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4219 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4220 | case NL80211_IFTYPE_STATION: |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 4221 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4222 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4223 | break; |
| 4224 | default: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4225 | err = -EOPNOTSUPP; |
| 4226 | goto out_put_vlan; |
Johannes Berg | 034d655 | 2009-05-27 10:35:29 +0200 | [diff] [blame] | 4227 | } |
| 4228 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4229 | /* driver will call cfg80211_check_station_change() */ |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4230 | err = rdev_change_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4231 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4232 | out_put_vlan: |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4233 | if (params.vlan) |
| 4234 | dev_put(params.vlan); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4235 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4236 | return err; |
| 4237 | } |
| 4238 | |
| 4239 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) |
| 4240 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4241 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4242 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4243 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4244 | struct station_parameters params; |
| 4245 | u8 *mac_addr = NULL; |
| 4246 | |
| 4247 | memset(¶ms, 0, sizeof(params)); |
| 4248 | |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4249 | if (!rdev->ops->add_station) |
| 4250 | return -EOPNOTSUPP; |
| 4251 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4252 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4253 | return -EINVAL; |
| 4254 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4255 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 4256 | return -EINVAL; |
| 4257 | |
| 4258 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) |
| 4259 | return -EINVAL; |
| 4260 | |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 4261 | if (!info->attrs[NL80211_ATTR_STA_AID] && |
| 4262 | !info->attrs[NL80211_ATTR_PEER_AID]) |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 4263 | return -EINVAL; |
| 4264 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4265 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4266 | params.supported_rates = |
| 4267 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4268 | params.supported_rates_len = |
| 4269 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4270 | params.listen_interval = |
| 4271 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 4272 | |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4273 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 4274 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4275 | else |
| 4276 | 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] | 4277 | if (!params.aid || params.aid > IEEE80211_MAX_AID) |
| 4278 | return -EINVAL; |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 4279 | |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 4280 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
| 4281 | params.capability = |
| 4282 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); |
| 4283 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; |
| 4284 | } |
| 4285 | |
| 4286 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { |
| 4287 | params.ext_capab = |
| 4288 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4289 | params.ext_capab_len = |
| 4290 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4291 | } |
| 4292 | |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 4293 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 4294 | params.ht_capa = |
| 4295 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4296 | |
Mahesh Palivela | f461be3e | 2012-10-11 08:04:52 +0000 | [diff] [blame] | 4297 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 4298 | params.vht_capa = |
| 4299 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 4300 | |
Marek Kwaczynski | 60f4a7b | 2013-12-03 10:04:59 +0100 | [diff] [blame] | 4301 | if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) { |
| 4302 | params.opmode_notif_used = true; |
| 4303 | params.opmode_notif = |
| 4304 | nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]); |
| 4305 | } |
| 4306 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4307 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 4308 | params.plink_action = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4309 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 4310 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) |
| 4311 | return -EINVAL; |
| 4312 | } |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 4313 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 4314 | err = nl80211_parse_sta_channel_info(info, ¶ms); |
| 4315 | if (err) |
| 4316 | return err; |
| 4317 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4318 | err = nl80211_parse_sta_wme(info, ¶ms); |
| 4319 | if (err) |
| 4320 | return err; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4321 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 4322 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4323 | return -EINVAL; |
| 4324 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4325 | /* When you run into this, adjust the code below for the new flag */ |
| 4326 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); |
| 4327 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4328 | switch (dev->ieee80211_ptr->iftype) { |
| 4329 | case NL80211_IFTYPE_AP: |
| 4330 | case NL80211_IFTYPE_AP_VLAN: |
| 4331 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4332 | /* ignore WME attributes if iface/sta is not capable */ |
| 4333 | if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) || |
| 4334 | !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) |
| 4335 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4336 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4337 | /* TDLS peers cannot be added */ |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4338 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
| 4339 | info->attrs[NL80211_ATTR_PEER_AID]) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 4340 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4341 | /* but don't bother the driver with it */ |
| 4342 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4343 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4344 | /* allow authenticated/associated only if driver handles it */ |
| 4345 | if (!(rdev->wiphy.features & |
| 4346 | NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
| 4347 | params.sta_flags_mask & |
| 4348 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 4349 | BIT(NL80211_STA_FLAG_ASSOCIATED))) |
| 4350 | return -EINVAL; |
| 4351 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4352 | /* must be last in here for error handling */ |
| 4353 | params.vlan = get_vlan(info, rdev); |
| 4354 | if (IS_ERR(params.vlan)) |
| 4355 | return PTR_ERR(params.vlan); |
| 4356 | break; |
| 4357 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4358 | /* ignore uAPSD data */ |
| 4359 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
| 4360 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4361 | /* associated is disallowed */ |
| 4362 | if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) |
| 4363 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4364 | /* TDLS peers cannot be added */ |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4365 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
| 4366 | info->attrs[NL80211_ATTR_PEER_AID]) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 4367 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4368 | break; |
| 4369 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 93d08f0 | 2013-03-04 09:29:46 +0100 | [diff] [blame] | 4370 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4371 | /* ignore uAPSD data */ |
| 4372 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
| 4373 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4374 | /* these are disallowed */ |
| 4375 | if (params.sta_flags_mask & |
| 4376 | (BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 4377 | BIT(NL80211_STA_FLAG_AUTHENTICATED))) |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4378 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4379 | /* Only TDLS peers can be added */ |
| 4380 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 4381 | return -EINVAL; |
| 4382 | /* Can only add if TDLS ... */ |
| 4383 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) |
| 4384 | return -EOPNOTSUPP; |
| 4385 | /* ... with external setup is supported */ |
| 4386 | if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) |
| 4387 | return -EOPNOTSUPP; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4388 | /* |
| 4389 | * Older wpa_supplicant versions always mark the TDLS peer |
| 4390 | * as authorized, but it shouldn't yet be. |
| 4391 | */ |
| 4392 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED); |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4393 | break; |
| 4394 | default: |
| 4395 | return -EOPNOTSUPP; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4396 | } |
| 4397 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4398 | /* be aware of params.vlan when changing code here */ |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4399 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4400 | err = rdev_add_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4401 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4402 | if (params.vlan) |
| 4403 | dev_put(params.vlan); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4404 | return err; |
| 4405 | } |
| 4406 | |
| 4407 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) |
| 4408 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4409 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4410 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 89c771e | 2014-10-10 20:52:40 +0300 | [diff] [blame] | 4411 | struct station_del_parameters params; |
| 4412 | |
| 4413 | memset(¶ms, 0, sizeof(params)); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4414 | |
| 4415 | if (info->attrs[NL80211_ATTR_MAC]) |
Jouni Malinen | 89c771e | 2014-10-10 20:52:40 +0300 | [diff] [blame] | 4416 | params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4417 | |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 4418 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Marco Porsch | d5d9de0 | 2010-03-30 10:00:16 +0200 | [diff] [blame] | 4419 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4420 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4421 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4422 | return -EINVAL; |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 4423 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4424 | if (!rdev->ops->del_station) |
| 4425 | return -EOPNOTSUPP; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4426 | |
Jouni Malinen | 9885686 | 2014-10-20 13:20:45 +0300 | [diff] [blame] | 4427 | if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) { |
| 4428 | params.subtype = |
| 4429 | nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]); |
| 4430 | if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 && |
| 4431 | params.subtype != IEEE80211_STYPE_DEAUTH >> 4) |
| 4432 | return -EINVAL; |
| 4433 | } else { |
| 4434 | /* Default to Deauthentication frame */ |
| 4435 | params.subtype = IEEE80211_STYPE_DEAUTH >> 4; |
| 4436 | } |
| 4437 | |
| 4438 | if (info->attrs[NL80211_ATTR_REASON_CODE]) { |
| 4439 | params.reason_code = |
| 4440 | nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 4441 | if (params.reason_code == 0) |
| 4442 | return -EINVAL; /* 0 is reserved */ |
| 4443 | } else { |
| 4444 | /* Default to reason code 2 */ |
| 4445 | params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID; |
| 4446 | } |
| 4447 | |
Jouni Malinen | 89c771e | 2014-10-10 20:52:40 +0300 | [diff] [blame] | 4448 | return rdev_del_station(rdev, dev, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4449 | } |
| 4450 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4451 | 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] | 4452 | int flags, struct net_device *dev, |
| 4453 | u8 *dst, u8 *next_hop, |
| 4454 | struct mpath_info *pinfo) |
| 4455 | { |
| 4456 | void *hdr; |
| 4457 | struct nlattr *pinfoattr; |
| 4458 | |
Henning Rogge | 1ef4c85 | 2014-11-04 16:14:58 +0100 | [diff] [blame] | 4459 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_MPATH); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4460 | if (!hdr) |
| 4461 | return -1; |
| 4462 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4463 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 4464 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || |
| 4465 | nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) || |
| 4466 | nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation)) |
| 4467 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 4468 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4469 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
| 4470 | if (!pinfoattr) |
| 4471 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4472 | if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) && |
| 4473 | nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN, |
| 4474 | pinfo->frame_qlen)) |
| 4475 | goto nla_put_failure; |
| 4476 | if (((pinfo->filled & MPATH_INFO_SN) && |
| 4477 | nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) || |
| 4478 | ((pinfo->filled & MPATH_INFO_METRIC) && |
| 4479 | nla_put_u32(msg, NL80211_MPATH_INFO_METRIC, |
| 4480 | pinfo->metric)) || |
| 4481 | ((pinfo->filled & MPATH_INFO_EXPTIME) && |
| 4482 | nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME, |
| 4483 | pinfo->exptime)) || |
| 4484 | ((pinfo->filled & MPATH_INFO_FLAGS) && |
| 4485 | nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS, |
| 4486 | pinfo->flags)) || |
| 4487 | ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) && |
| 4488 | nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, |
| 4489 | pinfo->discovery_timeout)) || |
| 4490 | ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) && |
| 4491 | nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, |
| 4492 | pinfo->discovery_retries))) |
| 4493 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4494 | |
| 4495 | nla_nest_end(msg, pinfoattr); |
| 4496 | |
| 4497 | return genlmsg_end(msg, hdr); |
| 4498 | |
| 4499 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 4500 | genlmsg_cancel(msg, hdr); |
| 4501 | return -EMSGSIZE; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4502 | } |
| 4503 | |
| 4504 | static int nl80211_dump_mpath(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4505 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4506 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4507 | struct mpath_info pinfo; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4508 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4509 | struct wireless_dev *wdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4510 | u8 dst[ETH_ALEN]; |
| 4511 | u8 next_hop[ETH_ALEN]; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4512 | int path_idx = cb->args[2]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4513 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4514 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4515 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4516 | if (err) |
| 4517 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4518 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4519 | if (!rdev->ops->dump_mpath) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4520 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4521 | goto out_err; |
| 4522 | } |
| 4523 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4524 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4525 | err = -EOPNOTSUPP; |
Roel Kluin | 0448b5f | 2009-08-22 21:15:49 +0200 | [diff] [blame] | 4526 | goto out_err; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4527 | } |
| 4528 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4529 | while (1) { |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4530 | err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4531 | next_hop, &pinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4532 | if (err == -ENOENT) |
| 4533 | break; |
| 4534 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4535 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4536 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4537 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4538 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4539 | wdev->netdev, dst, next_hop, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4540 | &pinfo) < 0) |
| 4541 | goto out; |
| 4542 | |
| 4543 | path_idx++; |
| 4544 | } |
| 4545 | |
| 4546 | |
| 4547 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4548 | cb->args[2] = path_idx; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4549 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4550 | out_err: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4551 | nl80211_finish_wdev_dump(rdev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4552 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4553 | } |
| 4554 | |
| 4555 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4556 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4557 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4558 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4559 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4560 | struct mpath_info pinfo; |
| 4561 | struct sk_buff *msg; |
| 4562 | u8 *dst = NULL; |
| 4563 | u8 next_hop[ETH_ALEN]; |
| 4564 | |
| 4565 | memset(&pinfo, 0, sizeof(pinfo)); |
| 4566 | |
| 4567 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4568 | return -EINVAL; |
| 4569 | |
| 4570 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4571 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4572 | if (!rdev->ops->get_mpath) |
| 4573 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4574 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4575 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4576 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4577 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4578 | err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4579 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4580 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4581 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4582 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4583 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4584 | return -ENOMEM; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4585 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4586 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4587 | dev, dst, next_hop, &pinfo) < 0) { |
| 4588 | nlmsg_free(msg); |
| 4589 | return -ENOBUFS; |
| 4590 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4591 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4592 | return genlmsg_reply(msg, info); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4593 | } |
| 4594 | |
| 4595 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4596 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4597 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4598 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4599 | u8 *dst = NULL; |
| 4600 | u8 *next_hop = NULL; |
| 4601 | |
| 4602 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4603 | return -EINVAL; |
| 4604 | |
| 4605 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 4606 | return -EINVAL; |
| 4607 | |
| 4608 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4609 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 4610 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4611 | if (!rdev->ops->change_mpath) |
| 4612 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4613 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4614 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4615 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4616 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4617 | return rdev_change_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4618 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4619 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4620 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4621 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4622 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4623 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4624 | u8 *dst = NULL; |
| 4625 | u8 *next_hop = NULL; |
| 4626 | |
| 4627 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4628 | return -EINVAL; |
| 4629 | |
| 4630 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 4631 | return -EINVAL; |
| 4632 | |
| 4633 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4634 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 4635 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4636 | if (!rdev->ops->add_mpath) |
| 4637 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4638 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4639 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4640 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4641 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4642 | return rdev_add_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4643 | } |
| 4644 | |
| 4645 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4646 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4647 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4648 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4649 | u8 *dst = NULL; |
| 4650 | |
| 4651 | if (info->attrs[NL80211_ATTR_MAC]) |
| 4652 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4653 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4654 | if (!rdev->ops->del_mpath) |
| 4655 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4656 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4657 | return rdev_del_mpath(rdev, dev, dst); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4658 | } |
| 4659 | |
Henning Rogge | 66be7d2 | 2014-09-12 08:58:49 +0200 | [diff] [blame] | 4660 | static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info) |
| 4661 | { |
| 4662 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4663 | int err; |
| 4664 | struct net_device *dev = info->user_ptr[1]; |
| 4665 | struct mpath_info pinfo; |
| 4666 | struct sk_buff *msg; |
| 4667 | u8 *dst = NULL; |
| 4668 | u8 mpp[ETH_ALEN]; |
| 4669 | |
| 4670 | memset(&pinfo, 0, sizeof(pinfo)); |
| 4671 | |
| 4672 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4673 | return -EINVAL; |
| 4674 | |
| 4675 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4676 | |
| 4677 | if (!rdev->ops->get_mpp) |
| 4678 | return -EOPNOTSUPP; |
| 4679 | |
| 4680 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4681 | return -EOPNOTSUPP; |
| 4682 | |
| 4683 | err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo); |
| 4684 | if (err) |
| 4685 | return err; |
| 4686 | |
| 4687 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 4688 | if (!msg) |
| 4689 | return -ENOMEM; |
| 4690 | |
| 4691 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
| 4692 | dev, dst, mpp, &pinfo) < 0) { |
| 4693 | nlmsg_free(msg); |
| 4694 | return -ENOBUFS; |
| 4695 | } |
| 4696 | |
| 4697 | return genlmsg_reply(msg, info); |
| 4698 | } |
| 4699 | |
| 4700 | static int nl80211_dump_mpp(struct sk_buff *skb, |
| 4701 | struct netlink_callback *cb) |
| 4702 | { |
| 4703 | struct mpath_info pinfo; |
| 4704 | struct cfg80211_registered_device *rdev; |
| 4705 | struct wireless_dev *wdev; |
| 4706 | u8 dst[ETH_ALEN]; |
| 4707 | u8 mpp[ETH_ALEN]; |
| 4708 | int path_idx = cb->args[2]; |
| 4709 | int err; |
| 4710 | |
| 4711 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
| 4712 | if (err) |
| 4713 | return err; |
| 4714 | |
| 4715 | if (!rdev->ops->dump_mpp) { |
| 4716 | err = -EOPNOTSUPP; |
| 4717 | goto out_err; |
| 4718 | } |
| 4719 | |
| 4720 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { |
| 4721 | err = -EOPNOTSUPP; |
| 4722 | goto out_err; |
| 4723 | } |
| 4724 | |
| 4725 | while (1) { |
| 4726 | err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst, |
| 4727 | mpp, &pinfo); |
| 4728 | if (err == -ENOENT) |
| 4729 | break; |
| 4730 | if (err) |
| 4731 | goto out_err; |
| 4732 | |
| 4733 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
| 4734 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 4735 | wdev->netdev, dst, mpp, |
| 4736 | &pinfo) < 0) |
| 4737 | goto out; |
| 4738 | |
| 4739 | path_idx++; |
| 4740 | } |
| 4741 | |
| 4742 | out: |
| 4743 | cb->args[2] = path_idx; |
| 4744 | err = skb->len; |
| 4745 | out_err: |
| 4746 | nl80211_finish_wdev_dump(rdev); |
| 4747 | return err; |
| 4748 | } |
| 4749 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4750 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
| 4751 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4752 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4753 | struct net_device *dev = info->user_ptr[1]; |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 4754 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4755 | struct bss_parameters params; |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 4756 | int err; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4757 | |
| 4758 | memset(¶ms, 0, sizeof(params)); |
| 4759 | /* default to not changing parameters */ |
| 4760 | params.use_cts_prot = -1; |
| 4761 | params.use_short_preamble = -1; |
| 4762 | params.use_short_slot_time = -1; |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 4763 | params.ap_isolate = -1; |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 4764 | params.ht_opmode = -1; |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 4765 | params.p2p_ctwindow = -1; |
| 4766 | params.p2p_opp_ps = -1; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4767 | |
| 4768 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) |
| 4769 | params.use_cts_prot = |
| 4770 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); |
| 4771 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) |
| 4772 | params.use_short_preamble = |
| 4773 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); |
| 4774 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) |
| 4775 | params.use_short_slot_time = |
| 4776 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 4777 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 4778 | params.basic_rates = |
| 4779 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 4780 | params.basic_rates_len = |
| 4781 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 4782 | } |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 4783 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
| 4784 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 4785 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
| 4786 | params.ht_opmode = |
| 4787 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4788 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 4789 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 4790 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4791 | return -EINVAL; |
| 4792 | params.p2p_ctwindow = |
| 4793 | nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
| 4794 | if (params.p2p_ctwindow < 0) |
| 4795 | return -EINVAL; |
| 4796 | if (params.p2p_ctwindow != 0 && |
| 4797 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 4798 | return -EINVAL; |
| 4799 | } |
| 4800 | |
| 4801 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 4802 | u8 tmp; |
| 4803 | |
| 4804 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4805 | return -EINVAL; |
| 4806 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
| 4807 | if (tmp > 1) |
| 4808 | return -EINVAL; |
| 4809 | params.p2p_opp_ps = tmp; |
| 4810 | if (params.p2p_opp_ps && |
| 4811 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 4812 | return -EINVAL; |
| 4813 | } |
| 4814 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4815 | if (!rdev->ops->change_bss) |
| 4816 | return -EOPNOTSUPP; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4817 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4818 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4819 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4820 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4821 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 4822 | wdev_lock(wdev); |
| 4823 | err = rdev_change_bss(rdev, dev, ¶ms); |
| 4824 | wdev_unlock(wdev); |
| 4825 | |
| 4826 | return err; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4827 | } |
| 4828 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 4829 | 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] | 4830 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
| 4831 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, |
| 4832 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, |
| 4833 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, |
| 4834 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, |
| 4835 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, |
Janusz Dziedzic | 089027e | 2014-02-21 19:46:12 +0100 | [diff] [blame] | 4836 | [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 }, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4837 | }; |
| 4838 | |
| 4839 | static int parse_reg_rule(struct nlattr *tb[], |
| 4840 | struct ieee80211_reg_rule *reg_rule) |
| 4841 | { |
| 4842 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; |
| 4843 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; |
| 4844 | |
| 4845 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) |
| 4846 | return -EINVAL; |
| 4847 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) |
| 4848 | return -EINVAL; |
| 4849 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) |
| 4850 | return -EINVAL; |
Janusz Dziedzic | b0dfd2e | 2014-02-20 13:52:16 +0100 | [diff] [blame] | 4851 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) |
| 4852 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4853 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) |
| 4854 | return -EINVAL; |
| 4855 | |
| 4856 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); |
| 4857 | |
| 4858 | freq_range->start_freq_khz = |
| 4859 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); |
| 4860 | freq_range->end_freq_khz = |
| 4861 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); |
Janusz Dziedzic | b0dfd2e | 2014-02-20 13:52:16 +0100 | [diff] [blame] | 4862 | freq_range->max_bandwidth_khz = |
| 4863 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4864 | |
| 4865 | power_rule->max_eirp = |
| 4866 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); |
| 4867 | |
| 4868 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) |
| 4869 | power_rule->max_antenna_gain = |
| 4870 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); |
| 4871 | |
Janusz Dziedzic | 089027e | 2014-02-21 19:46:12 +0100 | [diff] [blame] | 4872 | if (tb[NL80211_ATTR_DFS_CAC_TIME]) |
| 4873 | reg_rule->dfs_cac_ms = |
| 4874 | nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]); |
| 4875 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4876 | return 0; |
| 4877 | } |
| 4878 | |
| 4879 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 4880 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4881 | char *data = NULL; |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4882 | enum nl80211_user_reg_hint_type user_reg_hint_type; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4883 | |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 4884 | /* |
| 4885 | * You should only get this when cfg80211 hasn't yet initialized |
| 4886 | * completely when built-in to the kernel right between the time |
| 4887 | * window between nl80211_init() and regulatory_init(), if that is |
| 4888 | * even possible. |
| 4889 | */ |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4890 | if (unlikely(!rcu_access_pointer(cfg80211_regdomain))) |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 4891 | return -EINPROGRESS; |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 4892 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4893 | if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]) |
| 4894 | user_reg_hint_type = |
| 4895 | nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]); |
| 4896 | else |
| 4897 | user_reg_hint_type = NL80211_USER_REG_HINT_USER; |
| 4898 | |
| 4899 | switch (user_reg_hint_type) { |
| 4900 | case NL80211_USER_REG_HINT_USER: |
| 4901 | case NL80211_USER_REG_HINT_CELL_BASE: |
Ilan Peer | 52616f2 | 2014-02-25 16:26:00 +0200 | [diff] [blame] | 4902 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 4903 | return -EINVAL; |
| 4904 | |
| 4905 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 4906 | return regulatory_hint_user(data, user_reg_hint_type); |
| 4907 | case NL80211_USER_REG_HINT_INDOOR: |
| 4908 | return regulatory_hint_indoor_user(); |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4909 | default: |
| 4910 | return -EINVAL; |
| 4911 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4912 | } |
| 4913 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4914 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4915 | struct genl_info *info) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4916 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4917 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4918 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4919 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 4920 | struct mesh_config cur_params; |
| 4921 | int err = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4922 | void *hdr; |
| 4923 | struct nlattr *pinfoattr; |
| 4924 | struct sk_buff *msg; |
| 4925 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4926 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4927 | return -EOPNOTSUPP; |
| 4928 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4929 | if (!rdev->ops->get_mesh_config) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4930 | return -EOPNOTSUPP; |
Jouni Malinen | f3f9258 | 2009-03-20 17:57:36 +0200 | [diff] [blame] | 4931 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4932 | wdev_lock(wdev); |
| 4933 | /* If not connected, get default parameters */ |
| 4934 | if (!wdev->mesh_id_len) |
| 4935 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); |
| 4936 | else |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4937 | err = rdev_get_mesh_config(rdev, dev, &cur_params); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4938 | wdev_unlock(wdev); |
| 4939 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4940 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4941 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4942 | |
| 4943 | /* Draw up a netlink message to send back */ |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4944 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4945 | if (!msg) |
| 4946 | return -ENOMEM; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4947 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4948 | NL80211_CMD_GET_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4949 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4950 | goto out; |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4951 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4952 | if (!pinfoattr) |
| 4953 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4954 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 4955 | nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 4956 | cur_params.dot11MeshRetryTimeout) || |
| 4957 | nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 4958 | cur_params.dot11MeshConfirmTimeout) || |
| 4959 | nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 4960 | cur_params.dot11MeshHoldingTimeout) || |
| 4961 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 4962 | cur_params.dot11MeshMaxPeerLinks) || |
| 4963 | nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES, |
| 4964 | cur_params.dot11MeshMaxRetries) || |
| 4965 | nla_put_u8(msg, NL80211_MESHCONF_TTL, |
| 4966 | cur_params.dot11MeshTTL) || |
| 4967 | nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL, |
| 4968 | cur_params.element_ttl) || |
| 4969 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 4970 | cur_params.auto_open_plinks) || |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 4971 | nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 4972 | cur_params.dot11MeshNbrOffsetMaxNeighbor) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4973 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 4974 | cur_params.dot11MeshHWMPmaxPREQretries) || |
| 4975 | nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 4976 | cur_params.path_refresh_time) || |
| 4977 | nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 4978 | cur_params.min_discovery_timeout) || |
| 4979 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 4980 | cur_params.dot11MeshHWMPactivePathTimeout) || |
| 4981 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 4982 | cur_params.dot11MeshHWMPpreqMinInterval) || |
| 4983 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
| 4984 | cur_params.dot11MeshHWMPperrMinInterval) || |
| 4985 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 4986 | cur_params.dot11MeshHWMPnetDiameterTraversalTime) || |
| 4987 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 4988 | cur_params.dot11MeshHWMPRootMode) || |
| 4989 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
| 4990 | cur_params.dot11MeshHWMPRannInterval) || |
| 4991 | nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
| 4992 | cur_params.dot11MeshGateAnnouncementProtocol) || |
| 4993 | nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, |
| 4994 | cur_params.dot11MeshForwarding) || |
| 4995 | nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, |
Ashok Nagarajan | 70c33ea | 2012-04-30 14:20:32 -0700 | [diff] [blame] | 4996 | cur_params.rssi_threshold) || |
| 4997 | nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4998 | cur_params.ht_opmode) || |
| 4999 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 5000 | cur_params.dot11MeshHWMPactivePathToRootTimeout) || |
| 5001 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 5002 | cur_params.dot11MeshHWMProotInterval) || |
| 5003 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 5004 | cur_params.dot11MeshHWMPconfirmationInterval) || |
| 5005 | nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE, |
| 5006 | cur_params.power_mode) || |
| 5007 | nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW, |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 5008 | cur_params.dot11MeshAwakeWindowDuration) || |
| 5009 | nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT, |
| 5010 | cur_params.plink_timeout)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5011 | goto nla_put_failure; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5012 | nla_nest_end(msg, pinfoattr); |
| 5013 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5014 | return genlmsg_reply(msg, info); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5015 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 5016 | nla_put_failure: |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5017 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 5018 | out: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 5019 | nlmsg_free(msg); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5020 | return -ENOBUFS; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5021 | } |
| 5022 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 5023 | 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] | 5024 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
| 5025 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, |
| 5026 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, |
| 5027 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, |
| 5028 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, |
| 5029 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 5030 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5031 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 5032 | [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5033 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
| 5034 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, |
| 5035 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, |
| 5036 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, |
| 5037 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 5038 | [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5039 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
Javier Cardona | 699403d | 2011-08-09 16:45:09 -0700 | [diff] [blame] | 5040 | [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 }, |
Javier Cardona | 0507e15 | 2011-08-09 16:45:10 -0700 | [diff] [blame] | 5041 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 }, |
Javier Cardona | 16dd726 | 2011-08-09 16:45:11 -0700 | [diff] [blame] | 5042 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | 94f9065 | 2012-01-21 01:02:16 +0800 | [diff] [blame] | 5043 | [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5044 | [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 }, |
| 5045 | [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 5046 | [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 }, |
| 5047 | [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 5048 | [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 }, |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 5049 | [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 }, |
| 5050 | [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 }, |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 5051 | [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5052 | }; |
| 5053 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5054 | static const struct nla_policy |
| 5055 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 5056 | [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5057 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
| 5058 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 5059 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
Colleen Twitty | 6e16d90 | 2013-05-08 11:45:59 -0700 | [diff] [blame] | 5060 | [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 }, |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 5061 | [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG }, |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 5062 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5063 | .len = IEEE80211_MAX_DATA_LEN }, |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 5064 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5065 | }; |
| 5066 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5067 | static int nl80211_parse_mesh_config(struct genl_info *info, |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5068 | struct mesh_config *cfg, |
| 5069 | u32 *mask_out) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5070 | { |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5071 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5072 | u32 mask = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5073 | |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5074 | #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \ |
| 5075 | do { \ |
| 5076 | if (tb[attr]) { \ |
| 5077 | if (fn(tb[attr]) < min || fn(tb[attr]) > max) \ |
| 5078 | return -EINVAL; \ |
| 5079 | cfg->param = fn(tb[attr]); \ |
| 5080 | mask |= (1 << (attr - 1)); \ |
| 5081 | } \ |
| 5082 | } while (0) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5083 | |
| 5084 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5085 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5086 | return -EINVAL; |
| 5087 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5088 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5089 | nl80211_meshconf_params_policy)) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5090 | return -EINVAL; |
| 5091 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5092 | /* This makes sure that there aren't more than 32 mesh config |
| 5093 | * parameters (otherwise our bitfield scheme would not work.) */ |
| 5094 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); |
| 5095 | |
| 5096 | /* Fill in the params struct */ |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5097 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5098 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 5099 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5100 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5101 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 5102 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5103 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5104 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 5105 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5106 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5107 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 5108 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5109 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5110 | mask, NL80211_MESHCONF_MAX_RETRIES, |
| 5111 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5112 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5113 | mask, NL80211_MESHCONF_TTL, nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5114 | 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] | 5115 | mask, NL80211_MESHCONF_ELEMENT_TTL, |
| 5116 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5117 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5118 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 5119 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5120 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, |
| 5121 | 1, 255, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5122 | NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 5123 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5124 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5125 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 5126 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5127 | 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] | 5128 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 5129 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5130 | 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] | 5131 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 5132 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5133 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
| 5134 | 1, 65535, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5135 | NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 5136 | nla_get_u32); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5137 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5138 | 1, 65535, mask, |
| 5139 | NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5140 | nla_get_u16); |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 5141 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5142 | 1, 65535, mask, |
| 5143 | NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5144 | nla_get_u16); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5145 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5146 | dot11MeshHWMPnetDiameterTraversalTime, |
| 5147 | 1, 65535, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5148 | NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 5149 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5150 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4, |
| 5151 | mask, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 5152 | nla_get_u8); |
| 5153 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535, |
| 5154 | mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5155 | nla_get_u16); |
Rui Paulo | 63c5723 | 2009-11-09 23:46:57 +0000 | [diff] [blame] | 5156 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5157 | dot11MeshGateAnnouncementProtocol, 0, 1, |
| 5158 | mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5159 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5160 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5161 | mask, NL80211_MESHCONF_FORWARDING, |
| 5162 | nla_get_u8); |
Chun-Yeow Yeoh | 83374fe | 2013-07-11 18:24:03 +0800 | [diff] [blame] | 5163 | 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] | 5164 | mask, NL80211_MESHCONF_RSSI_THRESHOLD, |
Chun-Yeow Yeoh | 83374fe | 2013-07-11 18:24:03 +0800 | [diff] [blame] | 5165 | nla_get_s32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5166 | 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] | 5167 | mask, NL80211_MESHCONF_HT_OPMODE, |
| 5168 | nla_get_u16); |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 5169 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5170 | 1, 65535, mask, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 5171 | NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 5172 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5173 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 5174 | mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
| 5175 | nla_get_u16); |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 5176 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5177 | dot11MeshHWMPconfirmationInterval, |
| 5178 | 1, 65535, mask, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 5179 | NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
| 5180 | nla_get_u16); |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 5181 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode, |
| 5182 | NL80211_MESH_POWER_ACTIVE, |
| 5183 | NL80211_MESH_POWER_MAX, |
| 5184 | mask, NL80211_MESHCONF_POWER_MODE, |
| 5185 | nla_get_u32); |
| 5186 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration, |
| 5187 | 0, 65535, mask, |
| 5188 | NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16); |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 5189 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 1, 0xffffffff, |
| 5190 | mask, NL80211_MESHCONF_PLINK_TIMEOUT, |
| 5191 | nla_get_u32); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5192 | if (mask_out) |
| 5193 | *mask_out = mask; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5194 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5195 | return 0; |
| 5196 | |
| 5197 | #undef FILL_IN_MESH_PARAM_IF_SET |
| 5198 | } |
| 5199 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5200 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
| 5201 | struct mesh_setup *setup) |
| 5202 | { |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 5203 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5204 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
| 5205 | |
| 5206 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) |
| 5207 | return -EINVAL; |
| 5208 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, |
| 5209 | info->attrs[NL80211_ATTR_MESH_SETUP], |
| 5210 | nl80211_mesh_setup_params_policy)) |
| 5211 | return -EINVAL; |
| 5212 | |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 5213 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC]) |
| 5214 | setup->sync_method = |
| 5215 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ? |
| 5216 | IEEE80211_SYNC_METHOD_VENDOR : |
| 5217 | IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET; |
| 5218 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5219 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
| 5220 | setup->path_sel_proto = |
| 5221 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? |
| 5222 | IEEE80211_PATH_PROTOCOL_VENDOR : |
| 5223 | IEEE80211_PATH_PROTOCOL_HWMP; |
| 5224 | |
| 5225 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) |
| 5226 | setup->path_metric = |
| 5227 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? |
| 5228 | IEEE80211_PATH_METRIC_VENDOR : |
| 5229 | IEEE80211_PATH_METRIC_AIRTIME; |
| 5230 | |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 5231 | |
| 5232 | if (tb[NL80211_MESH_SETUP_IE]) { |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5233 | struct nlattr *ieattr = |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 5234 | tb[NL80211_MESH_SETUP_IE]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5235 | if (!is_valid_ie_attr(ieattr)) |
| 5236 | return -EINVAL; |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 5237 | setup->ie = nla_data(ieattr); |
| 5238 | setup->ie_len = nla_len(ieattr); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5239 | } |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 5240 | if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] && |
| 5241 | !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM)) |
| 5242 | return -EINVAL; |
| 5243 | setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]); |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 5244 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
| 5245 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 5246 | if (setup->is_secure) |
| 5247 | setup->user_mpm = true; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5248 | |
Colleen Twitty | 6e16d90 | 2013-05-08 11:45:59 -0700 | [diff] [blame] | 5249 | if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) { |
| 5250 | if (!setup->user_mpm) |
| 5251 | return -EINVAL; |
| 5252 | setup->auth_id = |
| 5253 | nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]); |
| 5254 | } |
| 5255 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5256 | return 0; |
| 5257 | } |
| 5258 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5259 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5260 | struct genl_info *info) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5261 | { |
| 5262 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5263 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5264 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5265 | struct mesh_config cfg; |
| 5266 | u32 mask; |
| 5267 | int err; |
| 5268 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5269 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 5270 | return -EOPNOTSUPP; |
| 5271 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5272 | if (!rdev->ops->update_mesh_config) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5273 | return -EOPNOTSUPP; |
| 5274 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5275 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5276 | if (err) |
| 5277 | return err; |
| 5278 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5279 | wdev_lock(wdev); |
| 5280 | if (!wdev->mesh_id_len) |
| 5281 | err = -ENOLINK; |
| 5282 | |
| 5283 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5284 | err = rdev_update_mesh_config(rdev, dev, mask, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5285 | |
| 5286 | wdev_unlock(wdev); |
| 5287 | |
| 5288 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5289 | } |
| 5290 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5291 | static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info) |
| 5292 | { |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5293 | const struct ieee80211_regdomain *regdom; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5294 | struct sk_buff *msg; |
| 5295 | void *hdr = NULL; |
| 5296 | struct nlattr *nl_reg_rules; |
| 5297 | unsigned int i; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5298 | |
| 5299 | if (!cfg80211_regdomain) |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5300 | return -EINVAL; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5301 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 5302 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5303 | if (!msg) |
| 5304 | return -ENOBUFS; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5305 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5306 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5307 | NL80211_CMD_GET_REG); |
| 5308 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 5309 | goto put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5310 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 5311 | if (reg_last_request_cell_base() && |
| 5312 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, |
| 5313 | NL80211_USER_REG_HINT_CELL_BASE)) |
| 5314 | goto nla_put_failure; |
| 5315 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5316 | rcu_read_lock(); |
| 5317 | regdom = rcu_dereference(cfg80211_regdomain); |
| 5318 | |
| 5319 | if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) || |
| 5320 | (regdom->dfs_region && |
| 5321 | nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region))) |
| 5322 | goto nla_put_failure_rcu; |
| 5323 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5324 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
| 5325 | if (!nl_reg_rules) |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5326 | goto nla_put_failure_rcu; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5327 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5328 | for (i = 0; i < regdom->n_reg_rules; i++) { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5329 | struct nlattr *nl_reg_rule; |
| 5330 | const struct ieee80211_reg_rule *reg_rule; |
| 5331 | const struct ieee80211_freq_range *freq_range; |
| 5332 | const struct ieee80211_power_rule *power_rule; |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 5333 | unsigned int max_bandwidth_khz; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5334 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5335 | reg_rule = ®dom->reg_rules[i]; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5336 | freq_range = ®_rule->freq_range; |
| 5337 | power_rule = ®_rule->power_rule; |
| 5338 | |
| 5339 | nl_reg_rule = nla_nest_start(msg, i); |
| 5340 | if (!nl_reg_rule) |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5341 | goto nla_put_failure_rcu; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5342 | |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 5343 | max_bandwidth_khz = freq_range->max_bandwidth_khz; |
| 5344 | if (!max_bandwidth_khz) |
| 5345 | max_bandwidth_khz = reg_get_max_bandwidth(regdom, |
| 5346 | reg_rule); |
| 5347 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5348 | if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
| 5349 | reg_rule->flags) || |
| 5350 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START, |
| 5351 | freq_range->start_freq_khz) || |
| 5352 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END, |
| 5353 | freq_range->end_freq_khz) || |
| 5354 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 5355 | max_bandwidth_khz) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5356 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
| 5357 | power_rule->max_antenna_gain) || |
| 5358 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, |
Janusz Dziedzic | 089027e | 2014-02-21 19:46:12 +0100 | [diff] [blame] | 5359 | power_rule->max_eirp) || |
| 5360 | nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME, |
| 5361 | reg_rule->dfs_cac_ms)) |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5362 | goto nla_put_failure_rcu; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5363 | |
| 5364 | nla_nest_end(msg, nl_reg_rule); |
| 5365 | } |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5366 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5367 | |
| 5368 | nla_nest_end(msg, nl_reg_rules); |
| 5369 | |
| 5370 | genlmsg_end(msg, hdr); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5371 | return genlmsg_reply(msg, info); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5372 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5373 | nla_put_failure_rcu: |
| 5374 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5375 | nla_put_failure: |
| 5376 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 5377 | put_failure: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 5378 | nlmsg_free(msg); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5379 | return -EMSGSIZE; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5380 | } |
| 5381 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5382 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 5383 | { |
| 5384 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; |
| 5385 | struct nlattr *nl_reg_rule; |
| 5386 | char *alpha2 = NULL; |
| 5387 | int rem_reg_rules = 0, r = 0; |
| 5388 | u32 num_rules = 0, rule_idx = 0, size_of_regd; |
Luis R. Rodriguez | 4c7d398 | 2013-11-13 18:54:02 +0100 | [diff] [blame] | 5389 | enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5390 | struct ieee80211_regdomain *rd = NULL; |
| 5391 | |
| 5392 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 5393 | return -EINVAL; |
| 5394 | |
| 5395 | if (!info->attrs[NL80211_ATTR_REG_RULES]) |
| 5396 | return -EINVAL; |
| 5397 | |
| 5398 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 5399 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 5400 | if (info->attrs[NL80211_ATTR_DFS_REGION]) |
| 5401 | dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); |
| 5402 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5403 | 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] | 5404 | rem_reg_rules) { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5405 | num_rules++; |
| 5406 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) |
Luis R. Rodriguez | 4776c6e | 2009-05-13 17:04:39 -0400 | [diff] [blame] | 5407 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5408 | } |
| 5409 | |
Luis R. Rodriguez | e438768 | 2013-11-05 09:18:01 -0800 | [diff] [blame] | 5410 | if (!reg_is_valid_request(alpha2)) |
| 5411 | return -EINVAL; |
| 5412 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5413 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 5414 | num_rules * sizeof(struct ieee80211_reg_rule); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5415 | |
| 5416 | rd = kzalloc(size_of_regd, GFP_KERNEL); |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 5417 | if (!rd) |
| 5418 | return -ENOMEM; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5419 | |
| 5420 | rd->n_reg_rules = num_rules; |
| 5421 | rd->alpha2[0] = alpha2[0]; |
| 5422 | rd->alpha2[1] = alpha2[1]; |
| 5423 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 5424 | /* |
| 5425 | * Disable DFS master mode if the DFS region was |
| 5426 | * not supported or known on this kernel. |
| 5427 | */ |
| 5428 | if (reg_supported_dfs_region(dfs_region)) |
| 5429 | rd->dfs_region = dfs_region; |
| 5430 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5431 | 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] | 5432 | rem_reg_rules) { |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 5433 | r = nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, |
| 5434 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), |
| 5435 | reg_rule_policy); |
| 5436 | if (r) |
| 5437 | goto bad_reg; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5438 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
| 5439 | if (r) |
| 5440 | goto bad_reg; |
| 5441 | |
| 5442 | rule_idx++; |
| 5443 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 5444 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
| 5445 | r = -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5446 | goto bad_reg; |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 5447 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5448 | } |
| 5449 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5450 | r = set_regdom(rd); |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 5451 | /* set_regdom took ownership */ |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 5452 | rd = NULL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5453 | |
Johannes Berg | d2372b3 | 2008-10-24 20:32:20 +0200 | [diff] [blame] | 5454 | bad_reg: |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5455 | kfree(rd); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 5456 | return r; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5457 | } |
| 5458 | |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5459 | static int validate_scan_freqs(struct nlattr *freqs) |
| 5460 | { |
| 5461 | struct nlattr *attr1, *attr2; |
| 5462 | int n_channels = 0, tmp1, tmp2; |
| 5463 | |
| 5464 | nla_for_each_nested(attr1, freqs, tmp1) { |
| 5465 | n_channels++; |
| 5466 | /* |
| 5467 | * Some hardware has a limited channel list for |
| 5468 | * scanning, and it is pretty much nonsensical |
| 5469 | * to scan for a channel twice, so disallow that |
| 5470 | * and don't require drivers to check that the |
| 5471 | * channel list they get isn't longer than what |
| 5472 | * they can scan, as long as they can scan all |
| 5473 | * the channels they registered at once. |
| 5474 | */ |
| 5475 | nla_for_each_nested(attr2, freqs, tmp2) |
| 5476 | if (attr1 != attr2 && |
| 5477 | nla_get_u32(attr1) == nla_get_u32(attr2)) |
| 5478 | return 0; |
| 5479 | } |
| 5480 | |
| 5481 | return n_channels; |
| 5482 | } |
| 5483 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5484 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
| 5485 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5486 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 5487 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5488 | struct cfg80211_scan_request *request; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5489 | struct nlattr *attr; |
| 5490 | struct wiphy *wiphy; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5491 | int err, tmp, n_ssids = 0, n_channels, i; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5492 | size_t ie_len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5493 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5494 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5495 | return -EINVAL; |
| 5496 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5497 | wiphy = &rdev->wiphy; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5498 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5499 | if (!rdev->ops->scan) |
| 5500 | return -EOPNOTSUPP; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5501 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 5502 | if (rdev->scan_req || rdev->scan_msg) { |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5503 | err = -EBUSY; |
| 5504 | goto unlock; |
| 5505 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5506 | |
| 5507 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5508 | n_channels = validate_scan_freqs( |
| 5509 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5510 | if (!n_channels) { |
| 5511 | err = -EINVAL; |
| 5512 | goto unlock; |
| 5513 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5514 | } else { |
Ilan Peer | bdfbec2 | 2014-01-09 11:37:23 +0200 | [diff] [blame] | 5515 | n_channels = ieee80211_get_num_supported_channels(wiphy); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5516 | } |
| 5517 | |
| 5518 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 5519 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) |
| 5520 | n_ssids++; |
| 5521 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5522 | if (n_ssids > wiphy->max_scan_ssids) { |
| 5523 | err = -EINVAL; |
| 5524 | goto unlock; |
| 5525 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5526 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5527 | if (info->attrs[NL80211_ATTR_IE]) |
| 5528 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5529 | else |
| 5530 | ie_len = 0; |
| 5531 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5532 | if (ie_len > wiphy->max_scan_ie_len) { |
| 5533 | err = -EINVAL; |
| 5534 | goto unlock; |
| 5535 | } |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 5536 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5537 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 5538 | + sizeof(*request->ssids) * n_ssids |
| 5539 | + sizeof(*request->channels) * n_channels |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5540 | + ie_len, GFP_KERNEL); |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5541 | if (!request) { |
| 5542 | err = -ENOMEM; |
| 5543 | goto unlock; |
| 5544 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5545 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5546 | if (n_ssids) |
Johannes Berg | 5ba6353 | 2009-08-07 17:54:07 +0200 | [diff] [blame] | 5547 | request->ssids = (void *)&request->channels[n_channels]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5548 | request->n_ssids = n_ssids; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5549 | if (ie_len) { |
| 5550 | if (request->ssids) |
| 5551 | request->ie = (void *)(request->ssids + n_ssids); |
| 5552 | else |
| 5553 | request->ie = (void *)(request->channels + n_channels); |
| 5554 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5555 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5556 | i = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5557 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 5558 | /* user specified, bail out if channel not found */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5559 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5560 | struct ieee80211_channel *chan; |
| 5561 | |
| 5562 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 5563 | |
| 5564 | if (!chan) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5565 | err = -EINVAL; |
| 5566 | goto out_free; |
| 5567 | } |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5568 | |
| 5569 | /* ignore disabled channels */ |
| 5570 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5571 | continue; |
| 5572 | |
| 5573 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5574 | i++; |
| 5575 | } |
| 5576 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5577 | enum ieee80211_band band; |
| 5578 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5579 | /* all channels */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5580 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 5581 | int j; |
| 5582 | if (!wiphy->bands[band]) |
| 5583 | continue; |
| 5584 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5585 | struct ieee80211_channel *chan; |
| 5586 | |
| 5587 | chan = &wiphy->bands[band]->channels[j]; |
| 5588 | |
| 5589 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5590 | continue; |
| 5591 | |
| 5592 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5593 | i++; |
| 5594 | } |
| 5595 | } |
| 5596 | } |
| 5597 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5598 | if (!i) { |
| 5599 | err = -EINVAL; |
| 5600 | goto out_free; |
| 5601 | } |
| 5602 | |
| 5603 | request->n_channels = i; |
| 5604 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5605 | i = 0; |
| 5606 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 5607 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5608 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5609 | err = -EINVAL; |
| 5610 | goto out_free; |
| 5611 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5612 | request->ssids[i].ssid_len = nla_len(attr); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5613 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5614 | i++; |
| 5615 | } |
| 5616 | } |
| 5617 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5618 | if (info->attrs[NL80211_ATTR_IE]) { |
| 5619 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Johannes Berg | de95a54 | 2009-04-01 11:58:36 +0200 | [diff] [blame] | 5620 | memcpy((void *)request->ie, |
| 5621 | nla_data(info->attrs[NL80211_ATTR_IE]), |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5622 | request->ie_len); |
| 5623 | } |
| 5624 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5625 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) |
Johannes Berg | a401d2b | 2011-07-20 00:52:16 +0200 | [diff] [blame] | 5626 | if (wiphy->bands[i]) |
| 5627 | request->rates[i] = |
| 5628 | (1 << wiphy->bands[i]->n_bitrates) - 1; |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5629 | |
| 5630 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { |
| 5631 | nla_for_each_nested(attr, |
| 5632 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], |
| 5633 | tmp) { |
| 5634 | enum ieee80211_band band = nla_type(attr); |
| 5635 | |
Dan Carpenter | 8440462 | 2011-07-29 11:52:18 +0300 | [diff] [blame] | 5636 | if (band < 0 || band >= IEEE80211_NUM_BANDS) { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5637 | err = -EINVAL; |
| 5638 | goto out_free; |
| 5639 | } |
Felix Fietkau | 1b09cd8 | 2013-11-20 19:40:41 +0100 | [diff] [blame] | 5640 | |
| 5641 | if (!wiphy->bands[band]) |
| 5642 | continue; |
| 5643 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5644 | err = ieee80211_get_ratemask(wiphy->bands[band], |
| 5645 | nla_data(attr), |
| 5646 | nla_len(attr), |
| 5647 | &request->rates[band]); |
| 5648 | if (err) |
| 5649 | goto out_free; |
| 5650 | } |
| 5651 | } |
| 5652 | |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5653 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5654 | request->flags = nla_get_u32( |
| 5655 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); |
Johannes Berg | 00c3a6e | 2013-10-26 17:14:38 +0200 | [diff] [blame] | 5656 | if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 5657 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) { |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5658 | err = -EOPNOTSUPP; |
| 5659 | goto out_free; |
| 5660 | } |
| 5661 | } |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5662 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 5663 | request->no_cck = |
| 5664 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 5665 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 5666 | request->wdev = wdev; |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5667 | request->wiphy = &rdev->wiphy; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 5668 | request->scan_start = jiffies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5669 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5670 | rdev->scan_req = request; |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5671 | err = rdev_scan(rdev, request); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5672 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5673 | if (!err) { |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 5674 | nl80211_send_scan_start(rdev, wdev); |
| 5675 | if (wdev->netdev) |
| 5676 | dev_hold(wdev->netdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5677 | } else { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5678 | out_free: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5679 | rdev->scan_req = NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5680 | kfree(request); |
| 5681 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 5682 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5683 | unlock: |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5684 | return err; |
| 5685 | } |
| 5686 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 5687 | static struct cfg80211_sched_scan_request * |
| 5688 | nl80211_parse_sched_scan(struct wiphy *wiphy, |
| 5689 | struct nlattr **attrs) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5690 | { |
| 5691 | struct cfg80211_sched_scan_request *request; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5692 | struct nlattr *attr; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5693 | 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] | 5694 | u32 interval; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5695 | enum ieee80211_band band; |
| 5696 | size_t ie_len; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5697 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 5698 | s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5699 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 5700 | if (!is_valid_ie_attr(attrs[NL80211_ATTR_IE])) |
| 5701 | return ERR_PTR(-EINVAL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5702 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 5703 | if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
| 5704 | return ERR_PTR(-EINVAL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5705 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 5706 | interval = nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 5707 | if (interval == 0) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 5708 | return ERR_PTR(-EINVAL); |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 5709 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 5710 | if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5711 | n_channels = validate_scan_freqs( |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 5712 | attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5713 | if (!n_channels) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 5714 | return ERR_PTR(-EINVAL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5715 | } else { |
Ilan Peer | bdfbec2 | 2014-01-09 11:37:23 +0200 | [diff] [blame] | 5716 | n_channels = ieee80211_get_num_supported_channels(wiphy); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5717 | } |
| 5718 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 5719 | if (attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 5720 | nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS], |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5721 | tmp) |
| 5722 | n_ssids++; |
| 5723 | |
Luciano Coelho | 93b6aa6 | 2011-07-13 14:57:28 +0300 | [diff] [blame] | 5724 | if (n_ssids > wiphy->max_sched_scan_ssids) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 5725 | return ERR_PTR(-EINVAL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5726 | |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 5727 | /* |
| 5728 | * First, count the number of 'real' matchsets. Due to an issue with |
| 5729 | * the old implementation, matchsets containing only the RSSI attribute |
| 5730 | * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default' |
| 5731 | * RSSI for all matchsets, rather than their own matchset for reporting |
| 5732 | * all APs with a strong RSSI. This is needed to be compatible with |
| 5733 | * older userspace that treated a matchset with only the RSSI as the |
| 5734 | * global RSSI for all other matchsets - if there are other matchsets. |
| 5735 | */ |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 5736 | if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5737 | nla_for_each_nested(attr, |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 5738 | attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 5739 | tmp) { |
| 5740 | struct nlattr *rssi; |
| 5741 | |
| 5742 | err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
| 5743 | nla_data(attr), nla_len(attr), |
| 5744 | nl80211_match_policy); |
| 5745 | if (err) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 5746 | return ERR_PTR(err); |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 5747 | /* add other standalone attributes here */ |
| 5748 | if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]) { |
| 5749 | n_match_sets++; |
| 5750 | continue; |
| 5751 | } |
| 5752 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; |
| 5753 | if (rssi) |
| 5754 | default_match_rssi = nla_get_s32(rssi); |
| 5755 | } |
| 5756 | } |
| 5757 | |
| 5758 | /* However, if there's no other matchset, add the RSSI one */ |
| 5759 | if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF) |
| 5760 | n_match_sets = 1; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5761 | |
| 5762 | if (n_match_sets > wiphy->max_match_sets) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 5763 | return ERR_PTR(-EINVAL); |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5764 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 5765 | if (attrs[NL80211_ATTR_IE]) |
| 5766 | ie_len = nla_len(attrs[NL80211_ATTR_IE]); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5767 | else |
| 5768 | ie_len = 0; |
| 5769 | |
Luciano Coelho | 5a865ba | 2011-07-13 14:57:29 +0300 | [diff] [blame] | 5770 | if (ie_len > wiphy->max_sched_scan_ie_len) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 5771 | return ERR_PTR(-EINVAL); |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 5772 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5773 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 5774 | + sizeof(*request->ssids) * n_ssids |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5775 | + sizeof(*request->match_sets) * n_match_sets |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 5776 | + sizeof(*request->channels) * n_channels |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5777 | + ie_len, GFP_KERNEL); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 5778 | if (!request) |
| 5779 | return ERR_PTR(-ENOMEM); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5780 | |
| 5781 | if (n_ssids) |
| 5782 | request->ssids = (void *)&request->channels[n_channels]; |
| 5783 | request->n_ssids = n_ssids; |
| 5784 | if (ie_len) { |
| 5785 | if (request->ssids) |
| 5786 | request->ie = (void *)(request->ssids + n_ssids); |
| 5787 | else |
| 5788 | request->ie = (void *)(request->channels + n_channels); |
| 5789 | } |
| 5790 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5791 | if (n_match_sets) { |
| 5792 | if (request->ie) |
| 5793 | request->match_sets = (void *)(request->ie + ie_len); |
| 5794 | else if (request->ssids) |
| 5795 | request->match_sets = |
| 5796 | (void *)(request->ssids + n_ssids); |
| 5797 | else |
| 5798 | request->match_sets = |
| 5799 | (void *)(request->channels + n_channels); |
| 5800 | } |
| 5801 | request->n_match_sets = n_match_sets; |
| 5802 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5803 | i = 0; |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 5804 | if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5805 | /* user specified, bail out if channel not found */ |
| 5806 | nla_for_each_nested(attr, |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 5807 | attrs[NL80211_ATTR_SCAN_FREQUENCIES], |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5808 | tmp) { |
| 5809 | struct ieee80211_channel *chan; |
| 5810 | |
| 5811 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 5812 | |
| 5813 | if (!chan) { |
| 5814 | err = -EINVAL; |
| 5815 | goto out_free; |
| 5816 | } |
| 5817 | |
| 5818 | /* ignore disabled channels */ |
| 5819 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5820 | continue; |
| 5821 | |
| 5822 | request->channels[i] = chan; |
| 5823 | i++; |
| 5824 | } |
| 5825 | } else { |
| 5826 | /* all channels */ |
| 5827 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 5828 | int j; |
| 5829 | if (!wiphy->bands[band]) |
| 5830 | continue; |
| 5831 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
| 5832 | struct ieee80211_channel *chan; |
| 5833 | |
| 5834 | chan = &wiphy->bands[band]->channels[j]; |
| 5835 | |
| 5836 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5837 | continue; |
| 5838 | |
| 5839 | request->channels[i] = chan; |
| 5840 | i++; |
| 5841 | } |
| 5842 | } |
| 5843 | } |
| 5844 | |
| 5845 | if (!i) { |
| 5846 | err = -EINVAL; |
| 5847 | goto out_free; |
| 5848 | } |
| 5849 | |
| 5850 | request->n_channels = i; |
| 5851 | |
| 5852 | i = 0; |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 5853 | if (attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 5854 | nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS], |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5855 | tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5856 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5857 | err = -EINVAL; |
| 5858 | goto out_free; |
| 5859 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5860 | request->ssids[i].ssid_len = nla_len(attr); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5861 | memcpy(request->ssids[i].ssid, nla_data(attr), |
| 5862 | nla_len(attr)); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5863 | i++; |
| 5864 | } |
| 5865 | } |
| 5866 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5867 | i = 0; |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 5868 | if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5869 | nla_for_each_nested(attr, |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 5870 | attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5871 | tmp) { |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 5872 | struct nlattr *ssid, *rssi; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5873 | |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 5874 | err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
| 5875 | nla_data(attr), nla_len(attr), |
| 5876 | nl80211_match_policy); |
| 5877 | if (err) |
| 5878 | goto out_free; |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 5879 | ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5880 | if (ssid) { |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 5881 | if (WARN_ON(i >= n_match_sets)) { |
| 5882 | /* this indicates a programming error, |
| 5883 | * the loop above should have verified |
| 5884 | * things properly |
| 5885 | */ |
| 5886 | err = -EINVAL; |
| 5887 | goto out_free; |
| 5888 | } |
| 5889 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5890 | if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) { |
| 5891 | err = -EINVAL; |
| 5892 | goto out_free; |
| 5893 | } |
| 5894 | memcpy(request->match_sets[i].ssid.ssid, |
| 5895 | nla_data(ssid), nla_len(ssid)); |
| 5896 | request->match_sets[i].ssid.ssid_len = |
| 5897 | nla_len(ssid); |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 5898 | /* special attribute - old implemenation w/a */ |
| 5899 | request->match_sets[i].rssi_thold = |
| 5900 | default_match_rssi; |
| 5901 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; |
| 5902 | if (rssi) |
| 5903 | request->match_sets[i].rssi_thold = |
| 5904 | nla_get_s32(rssi); |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5905 | } |
| 5906 | i++; |
| 5907 | } |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 5908 | |
| 5909 | /* there was no other matchset, so the RSSI one is alone */ |
| 5910 | if (i == 0) |
| 5911 | request->match_sets[0].rssi_thold = default_match_rssi; |
| 5912 | |
| 5913 | request->min_rssi_thold = INT_MAX; |
| 5914 | for (i = 0; i < n_match_sets; i++) |
| 5915 | request->min_rssi_thold = |
| 5916 | min(request->match_sets[i].rssi_thold, |
| 5917 | request->min_rssi_thold); |
| 5918 | } else { |
| 5919 | request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5920 | } |
| 5921 | |
Johannes Berg | 9900e48 | 2014-02-04 21:01:25 +0100 | [diff] [blame] | 5922 | if (ie_len) { |
| 5923 | request->ie_len = ie_len; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5924 | memcpy((void *)request->ie, |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 5925 | nla_data(attrs[NL80211_ATTR_IE]), |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5926 | request->ie_len); |
| 5927 | } |
| 5928 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 5929 | if (attrs[NL80211_ATTR_SCAN_FLAGS]) { |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5930 | request->flags = nla_get_u32( |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 5931 | attrs[NL80211_ATTR_SCAN_FLAGS]); |
Johannes Berg | 00c3a6e | 2013-10-26 17:14:38 +0200 | [diff] [blame] | 5932 | if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 5933 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) { |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5934 | err = -EOPNOTSUPP; |
| 5935 | goto out_free; |
| 5936 | } |
| 5937 | } |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5938 | |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 5939 | request->interval = interval; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 5940 | request->scan_start = jiffies; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5941 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 5942 | return request; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5943 | |
| 5944 | out_free: |
| 5945 | kfree(request); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 5946 | return ERR_PTR(err); |
| 5947 | } |
| 5948 | |
| 5949 | static int nl80211_start_sched_scan(struct sk_buff *skb, |
| 5950 | struct genl_info *info) |
| 5951 | { |
| 5952 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5953 | struct net_device *dev = info->user_ptr[1]; |
| 5954 | int err; |
| 5955 | |
| 5956 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 5957 | !rdev->ops->sched_scan_start) |
| 5958 | return -EOPNOTSUPP; |
| 5959 | |
| 5960 | if (rdev->sched_scan_req) |
| 5961 | return -EINPROGRESS; |
| 5962 | |
| 5963 | rdev->sched_scan_req = nl80211_parse_sched_scan(&rdev->wiphy, |
| 5964 | info->attrs); |
| 5965 | err = PTR_ERR_OR_ZERO(rdev->sched_scan_req); |
| 5966 | if (err) |
| 5967 | goto out_err; |
| 5968 | |
| 5969 | err = rdev_sched_scan_start(rdev, dev, rdev->sched_scan_req); |
| 5970 | if (err) |
| 5971 | goto out_free; |
| 5972 | |
| 5973 | rdev->sched_scan_req->dev = dev; |
| 5974 | rdev->sched_scan_req->wiphy = &rdev->wiphy; |
| 5975 | |
| 5976 | nl80211_send_sched_scan(rdev, dev, |
| 5977 | NL80211_CMD_START_SCHED_SCAN); |
| 5978 | return 0; |
| 5979 | |
| 5980 | out_free: |
| 5981 | kfree(rdev->sched_scan_req); |
| 5982 | out_err: |
| 5983 | rdev->sched_scan_req = NULL; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5984 | return err; |
| 5985 | } |
| 5986 | |
| 5987 | static int nl80211_stop_sched_scan(struct sk_buff *skb, |
| 5988 | struct genl_info *info) |
| 5989 | { |
| 5990 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5991 | |
| 5992 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 5993 | !rdev->ops->sched_scan_stop) |
| 5994 | return -EOPNOTSUPP; |
| 5995 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5996 | return __cfg80211_stop_sched_scan(rdev, false); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5997 | } |
| 5998 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5999 | static int nl80211_start_radar_detection(struct sk_buff *skb, |
| 6000 | struct genl_info *info) |
| 6001 | { |
| 6002 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6003 | struct net_device *dev = info->user_ptr[1]; |
| 6004 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 6005 | struct cfg80211_chan_def chandef; |
Luis R. Rodriguez | 55f7435 | 2013-11-25 20:56:10 +0100 | [diff] [blame] | 6006 | enum nl80211_dfs_regions dfs_region; |
Janusz Dziedzic | 31559f3 | 2014-02-21 19:46:13 +0100 | [diff] [blame] | 6007 | unsigned int cac_time_ms; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6008 | int err; |
| 6009 | |
Luis R. Rodriguez | 55f7435 | 2013-11-25 20:56:10 +0100 | [diff] [blame] | 6010 | dfs_region = reg_get_dfs_region(wdev->wiphy); |
| 6011 | if (dfs_region == NL80211_DFS_UNSET) |
| 6012 | return -EINVAL; |
| 6013 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6014 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 6015 | if (err) |
| 6016 | return err; |
| 6017 | |
Simon Wunderlich | ff311bc | 2013-09-03 19:43:18 +0200 | [diff] [blame] | 6018 | if (netif_carrier_ok(dev)) |
| 6019 | return -EBUSY; |
| 6020 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6021 | if (wdev->cac_started) |
| 6022 | return -EBUSY; |
| 6023 | |
Luciano Coelho | 2beb6dab | 2014-02-18 11:40:36 +0200 | [diff] [blame] | 6024 | err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, |
Luciano Coelho | 00ec75f | 2014-05-15 13:05:39 +0300 | [diff] [blame] | 6025 | wdev->iftype); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6026 | if (err < 0) |
| 6027 | return err; |
| 6028 | |
| 6029 | if (err == 0) |
| 6030 | return -EINVAL; |
| 6031 | |
Janusz Dziedzic | fe7c3a1 | 2013-11-05 14:48:48 +0100 | [diff] [blame] | 6032 | if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef)) |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6033 | return -EINVAL; |
| 6034 | |
| 6035 | if (!rdev->ops->start_radar_detection) |
| 6036 | return -EOPNOTSUPP; |
| 6037 | |
Janusz Dziedzic | 31559f3 | 2014-02-21 19:46:13 +0100 | [diff] [blame] | 6038 | cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef); |
| 6039 | if (WARN_ON(!cac_time_ms)) |
| 6040 | cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS; |
| 6041 | |
| 6042 | err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef, |
| 6043 | cac_time_ms); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6044 | if (!err) { |
Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 6045 | wdev->chandef = chandef; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6046 | wdev->cac_started = true; |
| 6047 | wdev->cac_start_time = jiffies; |
Janusz Dziedzic | 31559f3 | 2014-02-21 19:46:13 +0100 | [diff] [blame] | 6048 | wdev->cac_time_ms = cac_time_ms; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6049 | } |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6050 | return err; |
| 6051 | } |
| 6052 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6053 | static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info) |
| 6054 | { |
| 6055 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6056 | struct net_device *dev = info->user_ptr[1]; |
| 6057 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 6058 | struct cfg80211_csa_settings params; |
| 6059 | /* csa_attrs is defined static to avoid waste of stack size - this |
| 6060 | * function is called under RTNL lock, so this should not be a problem. |
| 6061 | */ |
| 6062 | static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1]; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6063 | int err; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 6064 | bool need_new_beacon = false; |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 6065 | int len, i; |
Luciano Coelho | 252e07c | 2014-10-08 09:48:34 +0300 | [diff] [blame] | 6066 | u32 cs_count; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6067 | |
| 6068 | if (!rdev->ops->channel_switch || |
| 6069 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)) |
| 6070 | return -EOPNOTSUPP; |
| 6071 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 6072 | switch (dev->ieee80211_ptr->iftype) { |
| 6073 | case NL80211_IFTYPE_AP: |
| 6074 | case NL80211_IFTYPE_P2P_GO: |
| 6075 | need_new_beacon = true; |
| 6076 | |
| 6077 | /* useless if AP is not running */ |
| 6078 | if (!wdev->beacon_interval) |
Johannes Berg | 1ff79df | 2014-01-22 10:05:27 +0100 | [diff] [blame] | 6079 | return -ENOTCONN; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 6080 | break; |
| 6081 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | 1ff79df | 2014-01-22 10:05:27 +0100 | [diff] [blame] | 6082 | if (!wdev->ssid_len) |
| 6083 | return -ENOTCONN; |
| 6084 | break; |
Chun-Yeow Yeoh | c6da674 | 2013-10-14 19:08:28 -0700 | [diff] [blame] | 6085 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 1ff79df | 2014-01-22 10:05:27 +0100 | [diff] [blame] | 6086 | if (!wdev->mesh_id_len) |
| 6087 | return -ENOTCONN; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 6088 | break; |
| 6089 | default: |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6090 | return -EOPNOTSUPP; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 6091 | } |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6092 | |
| 6093 | memset(¶ms, 0, sizeof(params)); |
| 6094 | |
| 6095 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 6096 | !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]) |
| 6097 | return -EINVAL; |
| 6098 | |
| 6099 | /* only important for AP, IBSS and mesh create IEs internally */ |
Andrei Otcheretianski | d0a361a | 2013-10-17 10:52:17 +0200 | [diff] [blame] | 6100 | if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES]) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6101 | return -EINVAL; |
| 6102 | |
Luciano Coelho | 252e07c | 2014-10-08 09:48:34 +0300 | [diff] [blame] | 6103 | /* Even though the attribute is u32, the specification says |
| 6104 | * u8, so let's make sure we don't overflow. |
| 6105 | */ |
| 6106 | cs_count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]); |
| 6107 | if (cs_count > 255) |
| 6108 | return -EINVAL; |
| 6109 | |
| 6110 | params.count = cs_count; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6111 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 6112 | if (!need_new_beacon) |
| 6113 | goto skip_beacons; |
| 6114 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6115 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon_after); |
| 6116 | if (err) |
| 6117 | return err; |
| 6118 | |
| 6119 | err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX, |
| 6120 | info->attrs[NL80211_ATTR_CSA_IES], |
| 6121 | nl80211_policy); |
| 6122 | if (err) |
| 6123 | return err; |
| 6124 | |
| 6125 | err = nl80211_parse_beacon(csa_attrs, ¶ms.beacon_csa); |
| 6126 | if (err) |
| 6127 | return err; |
| 6128 | |
| 6129 | if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]) |
| 6130 | return -EINVAL; |
| 6131 | |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 6132 | len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); |
| 6133 | if (!len || (len % sizeof(u16))) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6134 | return -EINVAL; |
| 6135 | |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 6136 | params.n_counter_offsets_beacon = len / sizeof(u16); |
| 6137 | if (rdev->wiphy.max_num_csa_counters && |
| 6138 | (params.n_counter_offsets_beacon > |
| 6139 | rdev->wiphy.max_num_csa_counters)) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6140 | return -EINVAL; |
| 6141 | |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 6142 | params.counter_offsets_beacon = |
| 6143 | nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); |
| 6144 | |
| 6145 | /* sanity checks - counters should fit and be the same */ |
| 6146 | for (i = 0; i < params.n_counter_offsets_beacon; i++) { |
| 6147 | u16 offset = params.counter_offsets_beacon[i]; |
| 6148 | |
| 6149 | if (offset >= params.beacon_csa.tail_len) |
| 6150 | return -EINVAL; |
| 6151 | |
| 6152 | if (params.beacon_csa.tail[offset] != params.count) |
| 6153 | return -EINVAL; |
| 6154 | } |
| 6155 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6156 | if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) { |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 6157 | len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); |
| 6158 | if (!len || (len % sizeof(u16))) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6159 | return -EINVAL; |
| 6160 | |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 6161 | params.n_counter_offsets_presp = len / sizeof(u16); |
| 6162 | if (rdev->wiphy.max_num_csa_counters && |
| 6163 | (params.n_counter_offsets_beacon > |
| 6164 | rdev->wiphy.max_num_csa_counters)) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6165 | return -EINVAL; |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 6166 | |
| 6167 | params.counter_offsets_presp = |
| 6168 | nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); |
| 6169 | |
| 6170 | /* sanity checks - counters should fit and be the same */ |
| 6171 | for (i = 0; i < params.n_counter_offsets_presp; i++) { |
| 6172 | u16 offset = params.counter_offsets_presp[i]; |
| 6173 | |
| 6174 | if (offset >= params.beacon_csa.probe_resp_len) |
| 6175 | return -EINVAL; |
| 6176 | |
| 6177 | if (params.beacon_csa.probe_resp[offset] != |
| 6178 | params.count) |
| 6179 | return -EINVAL; |
| 6180 | } |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6181 | } |
| 6182 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 6183 | skip_beacons: |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6184 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
| 6185 | if (err) |
| 6186 | return err; |
| 6187 | |
Ilan Peer | 174e0cd | 2014-02-23 09:13:01 +0200 | [diff] [blame] | 6188 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, ¶ms.chandef, |
| 6189 | wdev->iftype)) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6190 | return -EINVAL; |
| 6191 | |
Luciano Coelho | 2beb6dab | 2014-02-18 11:40:36 +0200 | [diff] [blame] | 6192 | err = cfg80211_chandef_dfs_required(wdev->wiphy, |
| 6193 | ¶ms.chandef, |
| 6194 | wdev->iftype); |
| 6195 | if (err < 0) |
| 6196 | return err; |
| 6197 | |
Fabian Frederick | dcc6c2f | 2014-10-25 17:57:35 +0200 | [diff] [blame] | 6198 | if (err > 0) |
Luciano Coelho | 2beb6dab | 2014-02-18 11:40:36 +0200 | [diff] [blame] | 6199 | params.radar_required = true; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6200 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6201 | if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX]) |
| 6202 | params.block_tx = true; |
| 6203 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 6204 | wdev_lock(wdev); |
| 6205 | err = rdev_channel_switch(rdev, dev, ¶ms); |
| 6206 | wdev_unlock(wdev); |
| 6207 | |
| 6208 | return err; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6209 | } |
| 6210 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 6211 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
| 6212 | u32 seq, int flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6213 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6214 | struct wireless_dev *wdev, |
| 6215 | struct cfg80211_internal_bss *intbss) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6216 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6217 | struct cfg80211_bss *res = &intbss->pub; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 6218 | const struct cfg80211_bss_ies *ies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6219 | void *hdr; |
| 6220 | struct nlattr *bss; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6221 | |
| 6222 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6223 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6224 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6225 | NL80211_CMD_NEW_SCAN_RESULTS); |
| 6226 | if (!hdr) |
| 6227 | return -1; |
| 6228 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 6229 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
| 6230 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6231 | if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation)) |
| 6232 | goto nla_put_failure; |
| 6233 | if (wdev->netdev && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6234 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex)) |
| 6235 | goto nla_put_failure; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6236 | if (nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 6237 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6238 | |
| 6239 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); |
| 6240 | if (!bss) |
| 6241 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6242 | if ((!is_zero_ether_addr(res->bssid) && |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 6243 | nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6244 | goto nla_put_failure; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 6245 | |
| 6246 | rcu_read_lock(); |
Johannes Berg | 0e22708 | 2014-08-12 20:34:30 +0200 | [diff] [blame] | 6247 | /* indicate whether we have probe response data or not */ |
| 6248 | if (rcu_access_pointer(res->proberesp_ies) && |
| 6249 | nla_put_flag(msg, NL80211_BSS_PRESP_DATA)) |
| 6250 | goto fail_unlock_rcu; |
| 6251 | |
| 6252 | /* this pointer prefers to be pointed to probe response data |
| 6253 | * but is always valid |
| 6254 | */ |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 6255 | ies = rcu_dereference(res->ies); |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 6256 | if (ies) { |
| 6257 | if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf)) |
| 6258 | goto fail_unlock_rcu; |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 6259 | if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS, |
| 6260 | ies->len, ies->data)) |
| 6261 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 6262 | } |
Johannes Berg | 0e22708 | 2014-08-12 20:34:30 +0200 | [diff] [blame] | 6263 | |
| 6264 | /* and this pointer is always (unless driver didn't know) beacon data */ |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 6265 | ies = rcu_dereference(res->beacon_ies); |
Johannes Berg | 0e22708 | 2014-08-12 20:34:30 +0200 | [diff] [blame] | 6266 | if (ies && ies->from_beacon) { |
| 6267 | if (nla_put_u64(msg, NL80211_BSS_BEACON_TSF, ies->tsf)) |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 6268 | goto fail_unlock_rcu; |
| 6269 | if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES, |
| 6270 | ies->len, ies->data)) |
| 6271 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 6272 | } |
| 6273 | rcu_read_unlock(); |
| 6274 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6275 | if (res->beacon_interval && |
| 6276 | nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval)) |
| 6277 | goto nla_put_failure; |
| 6278 | if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) || |
| 6279 | nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) || |
Simon Wunderlich | dcd6eac | 2013-07-08 16:55:49 +0200 | [diff] [blame] | 6280 | nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6281 | nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO, |
| 6282 | jiffies_to_msecs(jiffies - intbss->ts))) |
| 6283 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6284 | |
Johannes Berg | 77965c9 | 2009-02-18 18:45:06 +0100 | [diff] [blame] | 6285 | switch (rdev->wiphy.signal_type) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6286 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6287 | if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal)) |
| 6288 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6289 | break; |
| 6290 | case CFG80211_SIGNAL_TYPE_UNSPEC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6291 | if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal)) |
| 6292 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6293 | break; |
| 6294 | default: |
| 6295 | break; |
| 6296 | } |
| 6297 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6298 | switch (wdev->iftype) { |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6299 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6300 | case NL80211_IFTYPE_STATION: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6301 | if (intbss == wdev->current_bss && |
| 6302 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 6303 | NL80211_BSS_STATUS_ASSOCIATED)) |
| 6304 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6305 | break; |
| 6306 | case NL80211_IFTYPE_ADHOC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6307 | if (intbss == wdev->current_bss && |
| 6308 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 6309 | NL80211_BSS_STATUS_IBSS_JOINED)) |
| 6310 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6311 | break; |
| 6312 | default: |
| 6313 | break; |
| 6314 | } |
| 6315 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6316 | nla_nest_end(msg, bss); |
| 6317 | |
| 6318 | return genlmsg_end(msg, hdr); |
| 6319 | |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 6320 | fail_unlock_rcu: |
| 6321 | rcu_read_unlock(); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6322 | nla_put_failure: |
| 6323 | genlmsg_cancel(msg, hdr); |
| 6324 | return -EMSGSIZE; |
| 6325 | } |
| 6326 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6327 | 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] | 6328 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6329 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6330 | struct cfg80211_internal_bss *scan; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6331 | struct wireless_dev *wdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6332 | int start = cb->args[2], idx = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6333 | int err; |
| 6334 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6335 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 6336 | if (err) |
| 6337 | return err; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6338 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6339 | wdev_lock(wdev); |
| 6340 | spin_lock_bh(&rdev->bss_lock); |
| 6341 | cfg80211_bss_expire(rdev); |
| 6342 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 6343 | cb->seq = rdev->bss_generation; |
| 6344 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6345 | list_for_each_entry(scan, &rdev->bss_list, list) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6346 | if (++idx <= start) |
| 6347 | continue; |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 6348 | if (nl80211_send_bss(skb, cb, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6349 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6350 | rdev, wdev, scan) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6351 | idx--; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 6352 | break; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6353 | } |
| 6354 | } |
| 6355 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6356 | spin_unlock_bh(&rdev->bss_lock); |
| 6357 | wdev_unlock(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6358 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6359 | cb->args[2] = idx; |
| 6360 | nl80211_finish_wdev_dump(rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6361 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 6362 | return skb->len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6363 | } |
| 6364 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6365 | 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] | 6366 | int flags, struct net_device *dev, |
| 6367 | struct survey_info *survey) |
| 6368 | { |
| 6369 | void *hdr; |
| 6370 | struct nlattr *infoattr; |
| 6371 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6372 | hdr = nl80211hdr_put(msg, portid, seq, flags, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6373 | NL80211_CMD_NEW_SURVEY_RESULTS); |
| 6374 | if (!hdr) |
| 6375 | return -ENOMEM; |
| 6376 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6377 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
| 6378 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6379 | |
| 6380 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); |
| 6381 | if (!infoattr) |
| 6382 | goto nla_put_failure; |
| 6383 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6384 | if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY, |
| 6385 | survey->channel->center_freq)) |
| 6386 | goto nla_put_failure; |
| 6387 | |
| 6388 | if ((survey->filled & SURVEY_INFO_NOISE_DBM) && |
| 6389 | nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise)) |
| 6390 | goto nla_put_failure; |
| 6391 | if ((survey->filled & SURVEY_INFO_IN_USE) && |
| 6392 | nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE)) |
| 6393 | goto nla_put_failure; |
| 6394 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) && |
| 6395 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME, |
| 6396 | survey->channel_time)) |
| 6397 | goto nla_put_failure; |
| 6398 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) && |
| 6399 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY, |
| 6400 | survey->channel_time_busy)) |
| 6401 | goto nla_put_failure; |
| 6402 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) && |
| 6403 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY, |
| 6404 | survey->channel_time_ext_busy)) |
| 6405 | goto nla_put_failure; |
| 6406 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) && |
| 6407 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX, |
| 6408 | survey->channel_time_rx)) |
| 6409 | goto nla_put_failure; |
| 6410 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) && |
| 6411 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX, |
| 6412 | survey->channel_time_tx)) |
| 6413 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6414 | |
| 6415 | nla_nest_end(msg, infoattr); |
| 6416 | |
| 6417 | return genlmsg_end(msg, hdr); |
| 6418 | |
| 6419 | nla_put_failure: |
| 6420 | genlmsg_cancel(msg, hdr); |
| 6421 | return -EMSGSIZE; |
| 6422 | } |
| 6423 | |
| 6424 | static int nl80211_dump_survey(struct sk_buff *skb, |
| 6425 | struct netlink_callback *cb) |
| 6426 | { |
| 6427 | struct survey_info survey; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 6428 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6429 | struct wireless_dev *wdev; |
| 6430 | int survey_idx = cb->args[2]; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6431 | int res; |
| 6432 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 6433 | res = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 6434 | if (res) |
| 6435 | return res; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6436 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6437 | if (!wdev->netdev) { |
| 6438 | res = -EINVAL; |
| 6439 | goto out_err; |
| 6440 | } |
| 6441 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 6442 | if (!rdev->ops->dump_survey) { |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6443 | res = -EOPNOTSUPP; |
| 6444 | goto out_err; |
| 6445 | } |
| 6446 | |
| 6447 | while (1) { |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 6448 | struct ieee80211_channel *chan; |
| 6449 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 6450 | res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6451 | if (res == -ENOENT) |
| 6452 | break; |
| 6453 | if (res) |
| 6454 | goto out_err; |
| 6455 | |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 6456 | /* Survey without a channel doesn't make sense */ |
| 6457 | if (!survey.channel) { |
| 6458 | res = -EINVAL; |
| 6459 | goto out; |
| 6460 | } |
| 6461 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 6462 | chan = ieee80211_get_channel(&rdev->wiphy, |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 6463 | survey.channel->center_freq); |
| 6464 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) { |
| 6465 | survey_idx++; |
| 6466 | continue; |
| 6467 | } |
| 6468 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6469 | if (nl80211_send_survey(skb, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6470 | NETLINK_CB(cb->skb).portid, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6471 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6472 | wdev->netdev, &survey) < 0) |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6473 | goto out; |
| 6474 | survey_idx++; |
| 6475 | } |
| 6476 | |
| 6477 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6478 | cb->args[2] = survey_idx; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6479 | res = skb->len; |
| 6480 | out_err: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 6481 | nl80211_finish_wdev_dump(rdev); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6482 | return res; |
| 6483 | } |
| 6484 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6485 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
| 6486 | { |
| 6487 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | |
| 6488 | NL80211_WPA_VERSION_2)); |
| 6489 | } |
| 6490 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6491 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
| 6492 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6493 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6494 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6495 | struct ieee80211_channel *chan; |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 6496 | const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL; |
| 6497 | int err, ssid_len, ie_len = 0, sae_data_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6498 | enum nl80211_auth_type auth_type; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6499 | struct key_parse key; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6500 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6501 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6502 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6503 | return -EINVAL; |
| 6504 | |
| 6505 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6506 | return -EINVAL; |
| 6507 | |
Jouni Malinen | 1778092 | 2009-03-27 20:52:47 +0200 | [diff] [blame] | 6508 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
| 6509 | return -EINVAL; |
| 6510 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6511 | if (!info->attrs[NL80211_ATTR_SSID]) |
| 6512 | return -EINVAL; |
| 6513 | |
| 6514 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 6515 | return -EINVAL; |
| 6516 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6517 | err = nl80211_parse_key(info, &key); |
| 6518 | if (err) |
| 6519 | return err; |
| 6520 | |
| 6521 | if (key.idx >= 0) { |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 6522 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
| 6523 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6524 | if (!key.p.key || !key.p.key_len) |
| 6525 | return -EINVAL; |
| 6526 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || |
| 6527 | key.p.key_len != WLAN_KEY_LEN_WEP40) && |
| 6528 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || |
| 6529 | key.p.key_len != WLAN_KEY_LEN_WEP104)) |
| 6530 | return -EINVAL; |
| 6531 | if (key.idx > 4) |
| 6532 | return -EINVAL; |
| 6533 | } else { |
| 6534 | key.p.key_len = 0; |
| 6535 | key.p.key = NULL; |
| 6536 | } |
| 6537 | |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 6538 | if (key.idx >= 0) { |
| 6539 | int i; |
| 6540 | bool ok = false; |
| 6541 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { |
| 6542 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { |
| 6543 | ok = true; |
| 6544 | break; |
| 6545 | } |
| 6546 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6547 | if (!ok) |
| 6548 | return -EINVAL; |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 6549 | } |
| 6550 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6551 | if (!rdev->ops->auth) |
| 6552 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6553 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6554 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6555 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6556 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6557 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6558 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 6559 | chan = nl80211_get_valid_chan(&rdev->wiphy, |
| 6560 | info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 6561 | if (!chan) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6562 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6563 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6564 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 6565 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 6566 | |
| 6567 | if (info->attrs[NL80211_ATTR_IE]) { |
| 6568 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6569 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 6570 | } |
| 6571 | |
| 6572 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 6573 | if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6574 | return -EINVAL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6575 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 6576 | if (auth_type == NL80211_AUTHTYPE_SAE && |
| 6577 | !info->attrs[NL80211_ATTR_SAE_DATA]) |
| 6578 | return -EINVAL; |
| 6579 | |
| 6580 | if (info->attrs[NL80211_ATTR_SAE_DATA]) { |
| 6581 | if (auth_type != NL80211_AUTHTYPE_SAE) |
| 6582 | return -EINVAL; |
| 6583 | sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]); |
| 6584 | sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]); |
| 6585 | /* need to include at least Auth Transaction and Status Code */ |
| 6586 | if (sae_data_len < 4) |
| 6587 | return -EINVAL; |
| 6588 | } |
| 6589 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6590 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 6591 | |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 6592 | /* |
| 6593 | * Since we no longer track auth state, ignore |
| 6594 | * requests to only change local state. |
| 6595 | */ |
| 6596 | if (local_state_change) |
| 6597 | return 0; |
| 6598 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6599 | wdev_lock(dev->ieee80211_ptr); |
| 6600 | err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, |
| 6601 | ssid, ssid_len, ie, ie_len, |
| 6602 | key.p.key, key.p.key_len, key.idx, |
| 6603 | sae_data, sae_data_len); |
| 6604 | wdev_unlock(dev->ieee80211_ptr); |
| 6605 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6606 | } |
| 6607 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 6608 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 6609 | struct genl_info *info, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 6610 | struct cfg80211_crypto_settings *settings, |
| 6611 | int cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6612 | { |
Johannes Berg | c0b2bbd | 2009-07-25 16:54:36 +0200 | [diff] [blame] | 6613 | memset(settings, 0, sizeof(*settings)); |
| 6614 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6615 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
| 6616 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 6617 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
| 6618 | u16 proto; |
| 6619 | proto = nla_get_u16( |
| 6620 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); |
| 6621 | settings->control_port_ethertype = cpu_to_be16(proto); |
| 6622 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 6623 | proto != ETH_P_PAE) |
| 6624 | return -EINVAL; |
| 6625 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) |
| 6626 | settings->control_port_no_encrypt = true; |
| 6627 | } else |
| 6628 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); |
| 6629 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6630 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
| 6631 | void *data; |
| 6632 | int len, i; |
| 6633 | |
| 6634 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 6635 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 6636 | settings->n_ciphers_pairwise = len / sizeof(u32); |
| 6637 | |
| 6638 | if (len % sizeof(u32)) |
| 6639 | return -EINVAL; |
| 6640 | |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 6641 | if (settings->n_ciphers_pairwise > cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6642 | return -EINVAL; |
| 6643 | |
| 6644 | memcpy(settings->ciphers_pairwise, data, len); |
| 6645 | |
| 6646 | for (i = 0; i < settings->n_ciphers_pairwise; i++) |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 6647 | if (!cfg80211_supported_cipher_suite( |
| 6648 | &rdev->wiphy, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6649 | settings->ciphers_pairwise[i])) |
| 6650 | return -EINVAL; |
| 6651 | } |
| 6652 | |
| 6653 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { |
| 6654 | settings->cipher_group = |
| 6655 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 6656 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
| 6657 | settings->cipher_group)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6658 | return -EINVAL; |
| 6659 | } |
| 6660 | |
| 6661 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { |
| 6662 | settings->wpa_versions = |
| 6663 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); |
| 6664 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) |
| 6665 | return -EINVAL; |
| 6666 | } |
| 6667 | |
| 6668 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { |
| 6669 | void *data; |
Jouni Malinen | 6d30240 | 2011-09-21 18:11:33 +0300 | [diff] [blame] | 6670 | int len; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6671 | |
| 6672 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 6673 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 6674 | settings->n_akm_suites = len / sizeof(u32); |
| 6675 | |
| 6676 | if (len % sizeof(u32)) |
| 6677 | return -EINVAL; |
| 6678 | |
Jouni Malinen | 1b9ca02 | 2011-09-21 16:13:07 +0300 | [diff] [blame] | 6679 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) |
| 6680 | return -EINVAL; |
| 6681 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6682 | memcpy(settings->akm_suites, data, len); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6683 | } |
| 6684 | |
| 6685 | return 0; |
| 6686 | } |
| 6687 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6688 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
| 6689 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6690 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6691 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 6692 | struct ieee80211_channel *chan; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6693 | struct cfg80211_assoc_request req = {}; |
| 6694 | const u8 *bssid, *ssid; |
| 6695 | int err, ssid_len = 0; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6696 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6697 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6698 | return -EINVAL; |
| 6699 | |
| 6700 | if (!info->attrs[NL80211_ATTR_MAC] || |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6701 | !info->attrs[NL80211_ATTR_SSID] || |
| 6702 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6703 | return -EINVAL; |
| 6704 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6705 | if (!rdev->ops->assoc) |
| 6706 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6707 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6708 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6709 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6710 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6711 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6712 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6713 | |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 6714 | chan = nl80211_get_valid_chan(&rdev->wiphy, |
| 6715 | info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 6716 | if (!chan) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6717 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6718 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6719 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 6720 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6721 | |
| 6722 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6723 | req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6724 | req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6725 | } |
| 6726 | |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 6727 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 6728 | enum nl80211_mfp mfp = |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 6729 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 6730 | if (mfp == NL80211_MFP_REQUIRED) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6731 | req.use_mfp = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6732 | else if (mfp != NL80211_MFP_NO) |
| 6733 | return -EINVAL; |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 6734 | } |
| 6735 | |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 6736 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6737 | req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 6738 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6739 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6740 | req.flags |= ASSOC_REQ_DISABLE_HT; |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6741 | |
| 6742 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6743 | memcpy(&req.ht_capa_mask, |
| 6744 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 6745 | sizeof(req.ht_capa_mask)); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6746 | |
| 6747 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6748 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6749 | return -EINVAL; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6750 | memcpy(&req.ht_capa, |
| 6751 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 6752 | sizeof(req.ht_capa)); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6753 | } |
| 6754 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6755 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6756 | req.flags |= ASSOC_REQ_DISABLE_VHT; |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6757 | |
| 6758 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6759 | memcpy(&req.vht_capa_mask, |
| 6760 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), |
| 6761 | sizeof(req.vht_capa_mask)); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6762 | |
| 6763 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6764 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6765 | return -EINVAL; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6766 | memcpy(&req.vht_capa, |
| 6767 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), |
| 6768 | sizeof(req.vht_capa)); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6769 | } |
| 6770 | |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 6771 | if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) { |
| 6772 | if (!(rdev->wiphy.features & |
| 6773 | NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) || |
| 6774 | !(rdev->wiphy.features & NL80211_FEATURE_QUIET)) |
| 6775 | return -EINVAL; |
| 6776 | req.flags |= ASSOC_REQ_USE_RRM; |
| 6777 | } |
| 6778 | |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6779 | err = nl80211_crypto_settings(rdev, info, &req.crypto, 1); |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6780 | if (!err) { |
| 6781 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6782 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, |
| 6783 | ssid, ssid_len, &req); |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6784 | wdev_unlock(dev->ieee80211_ptr); |
| 6785 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6786 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6787 | return err; |
| 6788 | } |
| 6789 | |
| 6790 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) |
| 6791 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6792 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6793 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6794 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6795 | int ie_len = 0, err; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6796 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6797 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6798 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6799 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6800 | return -EINVAL; |
| 6801 | |
| 6802 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6803 | return -EINVAL; |
| 6804 | |
| 6805 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 6806 | return -EINVAL; |
| 6807 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6808 | if (!rdev->ops->deauth) |
| 6809 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6810 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6811 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6812 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6813 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6814 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6815 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6816 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6817 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 6818 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6819 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6820 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 6821 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6822 | |
| 6823 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6824 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6825 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6826 | } |
| 6827 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6828 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 6829 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6830 | wdev_lock(dev->ieee80211_ptr); |
| 6831 | err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, |
| 6832 | local_state_change); |
| 6833 | wdev_unlock(dev->ieee80211_ptr); |
| 6834 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6835 | } |
| 6836 | |
| 6837 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) |
| 6838 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6839 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6840 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6841 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6842 | int ie_len = 0, err; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6843 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6844 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6845 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6846 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6847 | return -EINVAL; |
| 6848 | |
| 6849 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6850 | return -EINVAL; |
| 6851 | |
| 6852 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 6853 | return -EINVAL; |
| 6854 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6855 | if (!rdev->ops->disassoc) |
| 6856 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6857 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6858 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6859 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6860 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6861 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6862 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6863 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6864 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 6865 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6866 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6867 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 6868 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6869 | |
| 6870 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6871 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6872 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6873 | } |
| 6874 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6875 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 6876 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6877 | wdev_lock(dev->ieee80211_ptr); |
| 6878 | err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, |
| 6879 | local_state_change); |
| 6880 | wdev_unlock(dev->ieee80211_ptr); |
| 6881 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6882 | } |
| 6883 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 6884 | static bool |
| 6885 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, |
| 6886 | int mcast_rate[IEEE80211_NUM_BANDS], |
| 6887 | int rateval) |
| 6888 | { |
| 6889 | struct wiphy *wiphy = &rdev->wiphy; |
| 6890 | bool found = false; |
| 6891 | int band, i; |
| 6892 | |
| 6893 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 6894 | struct ieee80211_supported_band *sband; |
| 6895 | |
| 6896 | sband = wiphy->bands[band]; |
| 6897 | if (!sband) |
| 6898 | continue; |
| 6899 | |
| 6900 | for (i = 0; i < sband->n_bitrates; i++) { |
| 6901 | if (sband->bitrates[i].bitrate == rateval) { |
| 6902 | mcast_rate[band] = i + 1; |
| 6903 | found = true; |
| 6904 | break; |
| 6905 | } |
| 6906 | } |
| 6907 | } |
| 6908 | |
| 6909 | return found; |
| 6910 | } |
| 6911 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6912 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
| 6913 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6914 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6915 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6916 | struct cfg80211_ibss_params ibss; |
| 6917 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6918 | struct cfg80211_cached_keys *connkeys = NULL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6919 | int err; |
| 6920 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 6921 | memset(&ibss, 0, sizeof(ibss)); |
| 6922 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6923 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6924 | return -EINVAL; |
| 6925 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6926 | if (!info->attrs[NL80211_ATTR_SSID] || |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6927 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 6928 | return -EINVAL; |
| 6929 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 6930 | ibss.beacon_interval = 100; |
| 6931 | |
| 6932 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 6933 | ibss.beacon_interval = |
| 6934 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 6935 | if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000) |
| 6936 | return -EINVAL; |
| 6937 | } |
| 6938 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6939 | if (!rdev->ops->join_ibss) |
| 6940 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6941 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6942 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 6943 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6944 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 6945 | wiphy = &rdev->wiphy; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6946 | |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 6947 | if (info->attrs[NL80211_ATTR_MAC]) { |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6948 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 6949 | |
| 6950 | if (!is_valid_ether_addr(ibss.bssid)) |
| 6951 | return -EINVAL; |
| 6952 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6953 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 6954 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 6955 | |
| 6956 | if (info->attrs[NL80211_ATTR_IE]) { |
| 6957 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6958 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 6959 | } |
| 6960 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6961 | err = nl80211_parse_chandef(rdev, info, &ibss.chandef); |
| 6962 | if (err) |
| 6963 | return err; |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 6964 | |
Ilan Peer | 174e0cd | 2014-02-23 09:13:01 +0200 | [diff] [blame] | 6965 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef, |
| 6966 | NL80211_IFTYPE_ADHOC)) |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 6967 | return -EINVAL; |
| 6968 | |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 6969 | switch (ibss.chandef.width) { |
Simon Wunderlich | bf37264 | 2013-07-08 16:55:58 +0200 | [diff] [blame] | 6970 | case NL80211_CHAN_WIDTH_5: |
| 6971 | case NL80211_CHAN_WIDTH_10: |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 6972 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 6973 | break; |
| 6974 | case NL80211_CHAN_WIDTH_20: |
| 6975 | case NL80211_CHAN_WIDTH_40: |
| 6976 | if (rdev->wiphy.features & NL80211_FEATURE_HT_IBSS) |
| 6977 | break; |
| 6978 | default: |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 6979 | return -EINVAL; |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 6980 | } |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 6981 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6982 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6983 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6984 | |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 6985 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 6986 | u8 *rates = |
| 6987 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 6988 | int n_rates = |
| 6989 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 6990 | struct ieee80211_supported_band *sband = |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6991 | wiphy->bands[ibss.chandef.chan->band]; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 6992 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 6993 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 6994 | &ibss.basic_rates); |
| 6995 | if (err) |
| 6996 | return err; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 6997 | } |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 6998 | |
Simon Wunderlich | 803768f | 2013-06-28 10:39:58 +0200 | [diff] [blame] | 6999 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 7000 | memcpy(&ibss.ht_capa_mask, |
| 7001 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 7002 | sizeof(ibss.ht_capa_mask)); |
| 7003 | |
| 7004 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
| 7005 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 7006 | return -EINVAL; |
| 7007 | memcpy(&ibss.ht_capa, |
| 7008 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 7009 | sizeof(ibss.ht_capa)); |
| 7010 | } |
| 7011 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 7012 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 7013 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, |
| 7014 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 7015 | return -EINVAL; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 7016 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7017 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 7018 | bool no_ht = false; |
| 7019 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7020 | connkeys = nl80211_parse_connkeys(rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 7021 | info->attrs[NL80211_ATTR_KEYS], |
| 7022 | &no_ht); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7023 | if (IS_ERR(connkeys)) |
| 7024 | return PTR_ERR(connkeys); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 7025 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 7026 | if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) && |
| 7027 | no_ht) { |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 7028 | kfree(connkeys); |
| 7029 | return -EINVAL; |
| 7030 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7031 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7032 | |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 7033 | ibss.control_port = |
| 7034 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]); |
| 7035 | |
Simon Wunderlich | 5336fa8 | 2013-10-07 18:41:05 +0200 | [diff] [blame] | 7036 | ibss.userspace_handles_dfs = |
| 7037 | nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]); |
| 7038 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7039 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7040 | if (err) |
Johannes Berg | b47f610 | 2014-09-10 13:39:54 +0300 | [diff] [blame] | 7041 | kzfree(connkeys); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7042 | return err; |
| 7043 | } |
| 7044 | |
| 7045 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) |
| 7046 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7047 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7048 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7049 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7050 | if (!rdev->ops->leave_ibss) |
| 7051 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7052 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7053 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 7054 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7055 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7056 | return cfg80211_leave_ibss(rdev, dev, false); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7057 | } |
| 7058 | |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 7059 | static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info) |
| 7060 | { |
| 7061 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7062 | struct net_device *dev = info->user_ptr[1]; |
| 7063 | int mcast_rate[IEEE80211_NUM_BANDS]; |
| 7064 | u32 nla_rate; |
| 7065 | int err; |
| 7066 | |
| 7067 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
| 7068 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 7069 | return -EOPNOTSUPP; |
| 7070 | |
| 7071 | if (!rdev->ops->set_mcast_rate) |
| 7072 | return -EOPNOTSUPP; |
| 7073 | |
| 7074 | memset(mcast_rate, 0, sizeof(mcast_rate)); |
| 7075 | |
| 7076 | if (!info->attrs[NL80211_ATTR_MCAST_RATE]) |
| 7077 | return -EINVAL; |
| 7078 | |
| 7079 | nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]); |
| 7080 | if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate)) |
| 7081 | return -EINVAL; |
| 7082 | |
| 7083 | err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate); |
| 7084 | |
| 7085 | return err; |
| 7086 | } |
| 7087 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 7088 | static struct sk_buff * |
| 7089 | __cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev, |
| 7090 | int approxlen, u32 portid, u32 seq, |
| 7091 | enum nl80211_commands cmd, |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 7092 | enum nl80211_attrs attr, |
| 7093 | const struct nl80211_vendor_cmd_info *info, |
| 7094 | gfp_t gfp) |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 7095 | { |
| 7096 | struct sk_buff *skb; |
| 7097 | void *hdr; |
| 7098 | struct nlattr *data; |
| 7099 | |
| 7100 | skb = nlmsg_new(approxlen + 100, gfp); |
| 7101 | if (!skb) |
| 7102 | return NULL; |
| 7103 | |
| 7104 | hdr = nl80211hdr_put(skb, portid, seq, 0, cmd); |
| 7105 | if (!hdr) { |
| 7106 | kfree_skb(skb); |
| 7107 | return NULL; |
| 7108 | } |
| 7109 | |
| 7110 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 7111 | goto nla_put_failure; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 7112 | |
| 7113 | if (info) { |
| 7114 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID, |
| 7115 | info->vendor_id)) |
| 7116 | goto nla_put_failure; |
| 7117 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD, |
| 7118 | info->subcmd)) |
| 7119 | goto nla_put_failure; |
| 7120 | } |
| 7121 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 7122 | data = nla_nest_start(skb, attr); |
| 7123 | |
| 7124 | ((void **)skb->cb)[0] = rdev; |
| 7125 | ((void **)skb->cb)[1] = hdr; |
| 7126 | ((void **)skb->cb)[2] = data; |
| 7127 | |
| 7128 | return skb; |
| 7129 | |
| 7130 | nla_put_failure: |
| 7131 | kfree_skb(skb); |
| 7132 | return NULL; |
| 7133 | } |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 7134 | |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 7135 | struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy, |
| 7136 | enum nl80211_commands cmd, |
| 7137 | enum nl80211_attrs attr, |
| 7138 | int vendor_event_idx, |
| 7139 | int approxlen, gfp_t gfp) |
| 7140 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 7141 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 7142 | const struct nl80211_vendor_cmd_info *info; |
| 7143 | |
| 7144 | switch (cmd) { |
| 7145 | case NL80211_CMD_TESTMODE: |
| 7146 | if (WARN_ON(vendor_event_idx != -1)) |
| 7147 | return NULL; |
| 7148 | info = NULL; |
| 7149 | break; |
| 7150 | case NL80211_CMD_VENDOR: |
| 7151 | if (WARN_ON(vendor_event_idx < 0 || |
| 7152 | vendor_event_idx >= wiphy->n_vendor_events)) |
| 7153 | return NULL; |
| 7154 | info = &wiphy->vendor_events[vendor_event_idx]; |
| 7155 | break; |
| 7156 | default: |
| 7157 | WARN_ON(1); |
| 7158 | return NULL; |
| 7159 | } |
| 7160 | |
| 7161 | return __cfg80211_alloc_vendor_skb(rdev, approxlen, 0, 0, |
| 7162 | cmd, attr, info, gfp); |
| 7163 | } |
| 7164 | EXPORT_SYMBOL(__cfg80211_alloc_event_skb); |
| 7165 | |
| 7166 | void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp) |
| 7167 | { |
| 7168 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 7169 | void *hdr = ((void **)skb->cb)[1]; |
| 7170 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 7171 | enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE; |
| 7172 | |
Johannes Berg | bd8c78e | 2014-07-30 14:55:26 +0200 | [diff] [blame] | 7173 | /* clear CB data for netlink core to own from now on */ |
| 7174 | memset(skb->cb, 0, sizeof(skb->cb)); |
| 7175 | |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 7176 | nla_nest_end(skb, data); |
| 7177 | genlmsg_end(skb, hdr); |
| 7178 | |
| 7179 | if (data->nla_type == NL80211_ATTR_VENDOR_DATA) |
| 7180 | mcgrp = NL80211_MCGRP_VENDOR; |
| 7181 | |
| 7182 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0, |
| 7183 | mcgrp, gfp); |
| 7184 | } |
| 7185 | EXPORT_SYMBOL(__cfg80211_send_event_skb); |
| 7186 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7187 | #ifdef CONFIG_NL80211_TESTMODE |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7188 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
| 7189 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7190 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 7191 | struct wireless_dev *wdev = |
| 7192 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7193 | int err; |
| 7194 | |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 7195 | if (!rdev->ops->testmode_cmd) |
| 7196 | return -EOPNOTSUPP; |
| 7197 | |
| 7198 | if (IS_ERR(wdev)) { |
| 7199 | err = PTR_ERR(wdev); |
| 7200 | if (err != -EINVAL) |
| 7201 | return err; |
| 7202 | wdev = NULL; |
| 7203 | } else if (wdev->wiphy != &rdev->wiphy) { |
| 7204 | return -EINVAL; |
| 7205 | } |
| 7206 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7207 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
| 7208 | return -EINVAL; |
| 7209 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 7210 | rdev->cur_cmd_info = info; |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 7211 | err = rdev_testmode_cmd(rdev, wdev, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7212 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
| 7213 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 7214 | rdev->cur_cmd_info = NULL; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7215 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7216 | return err; |
| 7217 | } |
| 7218 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7219 | static int nl80211_testmode_dump(struct sk_buff *skb, |
| 7220 | struct netlink_callback *cb) |
| 7221 | { |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 7222 | struct cfg80211_registered_device *rdev; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7223 | int err; |
| 7224 | long phy_idx; |
| 7225 | void *data = NULL; |
| 7226 | int data_len = 0; |
| 7227 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 7228 | rtnl_lock(); |
| 7229 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7230 | if (cb->args[0]) { |
| 7231 | /* |
| 7232 | * 0 is a valid index, but not valid for args[0], |
| 7233 | * so we need to offset by 1. |
| 7234 | */ |
| 7235 | phy_idx = cb->args[0] - 1; |
| 7236 | } else { |
| 7237 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 7238 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 7239 | nl80211_policy); |
| 7240 | if (err) |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 7241 | goto out_err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 7242 | |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 7243 | rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), |
| 7244 | nl80211_fam.attrbuf); |
| 7245 | if (IS_ERR(rdev)) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 7246 | err = PTR_ERR(rdev); |
| 7247 | goto out_err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 7248 | } |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 7249 | phy_idx = rdev->wiphy_idx; |
| 7250 | rdev = NULL; |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 7251 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7252 | if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]) |
| 7253 | cb->args[1] = |
| 7254 | (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]; |
| 7255 | } |
| 7256 | |
| 7257 | if (cb->args[1]) { |
| 7258 | data = nla_data((void *)cb->args[1]); |
| 7259 | data_len = nla_len((void *)cb->args[1]); |
| 7260 | } |
| 7261 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 7262 | rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
| 7263 | if (!rdev) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 7264 | err = -ENOENT; |
| 7265 | goto out_err; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7266 | } |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7267 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 7268 | if (!rdev->ops->testmode_dump) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7269 | err = -EOPNOTSUPP; |
| 7270 | goto out_err; |
| 7271 | } |
| 7272 | |
| 7273 | while (1) { |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7274 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7275 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 7276 | NL80211_CMD_TESTMODE); |
| 7277 | struct nlattr *tmdata; |
| 7278 | |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 7279 | if (!hdr) |
| 7280 | break; |
| 7281 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7282 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7283 | genlmsg_cancel(skb, hdr); |
| 7284 | break; |
| 7285 | } |
| 7286 | |
| 7287 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 7288 | if (!tmdata) { |
| 7289 | genlmsg_cancel(skb, hdr); |
| 7290 | break; |
| 7291 | } |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7292 | err = rdev_testmode_dump(rdev, skb, cb, data, data_len); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7293 | nla_nest_end(skb, tmdata); |
| 7294 | |
| 7295 | if (err == -ENOBUFS || err == -ENOENT) { |
| 7296 | genlmsg_cancel(skb, hdr); |
| 7297 | break; |
| 7298 | } else if (err) { |
| 7299 | genlmsg_cancel(skb, hdr); |
| 7300 | goto out_err; |
| 7301 | } |
| 7302 | |
| 7303 | genlmsg_end(skb, hdr); |
| 7304 | } |
| 7305 | |
| 7306 | err = skb->len; |
| 7307 | /* see above */ |
| 7308 | cb->args[0] = phy_idx + 1; |
| 7309 | out_err: |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 7310 | rtnl_unlock(); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7311 | return err; |
| 7312 | } |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7313 | #endif |
| 7314 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7315 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
| 7316 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7317 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7318 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7319 | struct cfg80211_connect_params connect; |
| 7320 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7321 | struct cfg80211_cached_keys *connkeys = NULL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7322 | int err; |
| 7323 | |
| 7324 | memset(&connect, 0, sizeof(connect)); |
| 7325 | |
| 7326 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 7327 | return -EINVAL; |
| 7328 | |
| 7329 | if (!info->attrs[NL80211_ATTR_SSID] || |
| 7330 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 7331 | return -EINVAL; |
| 7332 | |
| 7333 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 7334 | connect.auth_type = |
| 7335 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 7336 | if (!nl80211_valid_auth_type(rdev, connect.auth_type, |
| 7337 | NL80211_CMD_CONNECT)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7338 | return -EINVAL; |
| 7339 | } else |
| 7340 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 7341 | |
| 7342 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; |
| 7343 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 7344 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 7345 | NL80211_MAX_NR_CIPHER_SUITES); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7346 | if (err) |
| 7347 | return err; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7348 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7349 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7350 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7351 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7352 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 7353 | wiphy = &rdev->wiphy; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7354 | |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 7355 | connect.bg_scan_period = -1; |
| 7356 | if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] && |
| 7357 | (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) { |
| 7358 | connect.bg_scan_period = |
| 7359 | nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]); |
| 7360 | } |
| 7361 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7362 | if (info->attrs[NL80211_ATTR_MAC]) |
| 7363 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 7364 | else if (info->attrs[NL80211_ATTR_MAC_HINT]) |
| 7365 | connect.bssid_hint = |
| 7366 | nla_data(info->attrs[NL80211_ATTR_MAC_HINT]); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7367 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 7368 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 7369 | |
| 7370 | if (info->attrs[NL80211_ATTR_IE]) { |
| 7371 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 7372 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 7373 | } |
| 7374 | |
Jouni Malinen | cee00a9 | 2013-01-15 17:15:57 +0200 | [diff] [blame] | 7375 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
| 7376 | connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
| 7377 | if (connect.mfp != NL80211_MFP_REQUIRED && |
| 7378 | connect.mfp != NL80211_MFP_NO) |
| 7379 | return -EINVAL; |
| 7380 | } else { |
| 7381 | connect.mfp = NL80211_MFP_NO; |
| 7382 | } |
| 7383 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7384 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 7385 | connect.channel = nl80211_get_valid_chan( |
| 7386 | wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 7387 | if (!connect.channel) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7388 | return -EINVAL; |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 7389 | } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) { |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 7390 | connect.channel_hint = nl80211_get_valid_chan( |
| 7391 | wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]); |
| 7392 | if (!connect.channel_hint) |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 7393 | return -EINVAL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7394 | } |
| 7395 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7396 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
| 7397 | connkeys = nl80211_parse_connkeys(rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 7398 | info->attrs[NL80211_ATTR_KEYS], NULL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7399 | if (IS_ERR(connkeys)) |
| 7400 | return PTR_ERR(connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7401 | } |
| 7402 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 7403 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
| 7404 | connect.flags |= ASSOC_REQ_DISABLE_HT; |
| 7405 | |
| 7406 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 7407 | memcpy(&connect.ht_capa_mask, |
| 7408 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 7409 | sizeof(connect.ht_capa_mask)); |
| 7410 | |
| 7411 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 7412 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) { |
Johannes Berg | b47f610 | 2014-09-10 13:39:54 +0300 | [diff] [blame] | 7413 | kzfree(connkeys); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 7414 | return -EINVAL; |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 7415 | } |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 7416 | memcpy(&connect.ht_capa, |
| 7417 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 7418 | sizeof(connect.ht_capa)); |
| 7419 | } |
| 7420 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 7421 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
| 7422 | connect.flags |= ASSOC_REQ_DISABLE_VHT; |
| 7423 | |
| 7424 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
| 7425 | memcpy(&connect.vht_capa_mask, |
| 7426 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), |
| 7427 | sizeof(connect.vht_capa_mask)); |
| 7428 | |
| 7429 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { |
| 7430 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) { |
Johannes Berg | b47f610 | 2014-09-10 13:39:54 +0300 | [diff] [blame] | 7431 | kzfree(connkeys); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 7432 | return -EINVAL; |
| 7433 | } |
| 7434 | memcpy(&connect.vht_capa, |
| 7435 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), |
| 7436 | sizeof(connect.vht_capa)); |
| 7437 | } |
| 7438 | |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 7439 | if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) { |
| 7440 | if (!(rdev->wiphy.features & |
| 7441 | NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) || |
| 7442 | !(rdev->wiphy.features & NL80211_FEATURE_QUIET)) |
| 7443 | return -EINVAL; |
| 7444 | connect.flags |= ASSOC_REQ_USE_RRM; |
| 7445 | } |
| 7446 | |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7447 | wdev_lock(dev->ieee80211_ptr); |
| 7448 | err = cfg80211_connect(rdev, dev, &connect, connkeys, NULL); |
| 7449 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7450 | if (err) |
Johannes Berg | b47f610 | 2014-09-10 13:39:54 +0300 | [diff] [blame] | 7451 | kzfree(connkeys); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7452 | return err; |
| 7453 | } |
| 7454 | |
| 7455 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) |
| 7456 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7457 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7458 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7459 | u16 reason; |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7460 | int ret; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7461 | |
| 7462 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 7463 | reason = WLAN_REASON_DEAUTH_LEAVING; |
| 7464 | else |
| 7465 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 7466 | |
| 7467 | if (reason == 0) |
| 7468 | return -EINVAL; |
| 7469 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7470 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7471 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7472 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7473 | |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7474 | wdev_lock(dev->ieee80211_ptr); |
| 7475 | ret = cfg80211_disconnect(rdev, dev, reason, true); |
| 7476 | wdev_unlock(dev->ieee80211_ptr); |
| 7477 | return ret; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7478 | } |
| 7479 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7480 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
| 7481 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7482 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7483 | struct net *net; |
| 7484 | int err; |
| 7485 | u32 pid; |
| 7486 | |
| 7487 | if (!info->attrs[NL80211_ATTR_PID]) |
| 7488 | return -EINVAL; |
| 7489 | |
| 7490 | pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); |
| 7491 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7492 | net = get_net_ns_by_pid(pid); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7493 | if (IS_ERR(net)) |
| 7494 | return PTR_ERR(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7495 | |
| 7496 | err = 0; |
| 7497 | |
| 7498 | /* check if anything to do */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7499 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
| 7500 | err = cfg80211_switch_netns(rdev, net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7501 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7502 | put_net(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7503 | return err; |
| 7504 | } |
| 7505 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7506 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 7507 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7508 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7509 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
| 7510 | struct cfg80211_pmksa *pmksa) = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7511 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7512 | struct cfg80211_pmksa pmksa; |
| 7513 | |
| 7514 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); |
| 7515 | |
| 7516 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 7517 | return -EINVAL; |
| 7518 | |
| 7519 | if (!info->attrs[NL80211_ATTR_PMKID]) |
| 7520 | return -EINVAL; |
| 7521 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7522 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
| 7523 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 7524 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7525 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7526 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7527 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7528 | |
| 7529 | switch (info->genlhdr->cmd) { |
| 7530 | case NL80211_CMD_SET_PMKSA: |
| 7531 | rdev_ops = rdev->ops->set_pmksa; |
| 7532 | break; |
| 7533 | case NL80211_CMD_DEL_PMKSA: |
| 7534 | rdev_ops = rdev->ops->del_pmksa; |
| 7535 | break; |
| 7536 | default: |
| 7537 | WARN_ON(1); |
| 7538 | break; |
| 7539 | } |
| 7540 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7541 | if (!rdev_ops) |
| 7542 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7543 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7544 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7545 | } |
| 7546 | |
| 7547 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 7548 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7549 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7550 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7551 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7552 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7553 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7554 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7555 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7556 | if (!rdev->ops->flush_pmksa) |
| 7557 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7558 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7559 | return rdev_flush_pmksa(rdev, dev); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7560 | } |
| 7561 | |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7562 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) |
| 7563 | { |
| 7564 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7565 | struct net_device *dev = info->user_ptr[1]; |
| 7566 | u8 action_code, dialog_token; |
Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 7567 | u32 peer_capability = 0; |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7568 | u16 status_code; |
| 7569 | u8 *peer; |
Arik Nemtsov | 31fa97c | 2014-06-11 17:18:21 +0300 | [diff] [blame] | 7570 | bool initiator; |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7571 | |
| 7572 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 7573 | !rdev->ops->tdls_mgmt) |
| 7574 | return -EOPNOTSUPP; |
| 7575 | |
| 7576 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || |
| 7577 | !info->attrs[NL80211_ATTR_STATUS_CODE] || |
| 7578 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || |
| 7579 | !info->attrs[NL80211_ATTR_IE] || |
| 7580 | !info->attrs[NL80211_ATTR_MAC]) |
| 7581 | return -EINVAL; |
| 7582 | |
| 7583 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 7584 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); |
| 7585 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); |
| 7586 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); |
Arik Nemtsov | 31fa97c | 2014-06-11 17:18:21 +0300 | [diff] [blame] | 7587 | initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]); |
Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 7588 | if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]) |
| 7589 | peer_capability = |
| 7590 | nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7591 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7592 | return rdev_tdls_mgmt(rdev, dev, peer, action_code, |
Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 7593 | dialog_token, status_code, peer_capability, |
Arik Nemtsov | 31fa97c | 2014-06-11 17:18:21 +0300 | [diff] [blame] | 7594 | initiator, |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7595 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 7596 | nla_len(info->attrs[NL80211_ATTR_IE])); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7597 | } |
| 7598 | |
| 7599 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) |
| 7600 | { |
| 7601 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7602 | struct net_device *dev = info->user_ptr[1]; |
| 7603 | enum nl80211_tdls_operation operation; |
| 7604 | u8 *peer; |
| 7605 | |
| 7606 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 7607 | !rdev->ops->tdls_oper) |
| 7608 | return -EOPNOTSUPP; |
| 7609 | |
| 7610 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || |
| 7611 | !info->attrs[NL80211_ATTR_MAC]) |
| 7612 | return -EINVAL; |
| 7613 | |
| 7614 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); |
| 7615 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 7616 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7617 | return rdev_tdls_oper(rdev, dev, peer, operation); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7618 | } |
| 7619 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7620 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
| 7621 | struct genl_info *info) |
| 7622 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7623 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7624 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7625 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7626 | struct sk_buff *msg; |
| 7627 | void *hdr; |
| 7628 | u64 cookie; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7629 | u32 duration; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7630 | int err; |
| 7631 | |
| 7632 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 7633 | !info->attrs[NL80211_ATTR_DURATION]) |
| 7634 | return -EINVAL; |
| 7635 | |
| 7636 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
| 7637 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 7638 | if (!rdev->ops->remain_on_channel || |
| 7639 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7640 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7641 | |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 7642 | /* |
| 7643 | * We should be on that channel for at least a minimum amount of |
| 7644 | * time (10ms) but no longer than the driver supports. |
| 7645 | */ |
| 7646 | if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 7647 | duration > rdev->wiphy.max_remain_on_channel_duration) |
| 7648 | return -EINVAL; |
| 7649 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7650 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 7651 | if (err) |
| 7652 | return err; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7653 | |
| 7654 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7655 | if (!msg) |
| 7656 | return -ENOMEM; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7657 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7658 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7659 | NL80211_CMD_REMAIN_ON_CHANNEL); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 7660 | if (!hdr) { |
| 7661 | err = -ENOBUFS; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7662 | goto free_msg; |
| 7663 | } |
| 7664 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7665 | err = rdev_remain_on_channel(rdev, wdev, chandef.chan, |
| 7666 | duration, &cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7667 | |
| 7668 | if (err) |
| 7669 | goto free_msg; |
| 7670 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7671 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 7672 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7673 | |
| 7674 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7675 | |
| 7676 | return genlmsg_reply(msg, info); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7677 | |
| 7678 | nla_put_failure: |
| 7679 | err = -ENOBUFS; |
| 7680 | free_msg: |
| 7681 | nlmsg_free(msg); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7682 | return err; |
| 7683 | } |
| 7684 | |
| 7685 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, |
| 7686 | struct genl_info *info) |
| 7687 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7688 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7689 | struct wireless_dev *wdev = info->user_ptr[1]; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7690 | u64 cookie; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7691 | |
| 7692 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 7693 | return -EINVAL; |
| 7694 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7695 | if (!rdev->ops->cancel_remain_on_channel) |
| 7696 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7697 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7698 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 7699 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7700 | return rdev_cancel_remain_on_channel(rdev, wdev, cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7701 | } |
| 7702 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7703 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
| 7704 | u8 *rates, u8 rates_len) |
| 7705 | { |
| 7706 | u8 i; |
| 7707 | u32 mask = 0; |
| 7708 | |
| 7709 | for (i = 0; i < rates_len; i++) { |
| 7710 | int rate = (rates[i] & 0x7f) * 5; |
| 7711 | int ridx; |
| 7712 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { |
| 7713 | struct ieee80211_rate *srate = |
| 7714 | &sband->bitrates[ridx]; |
| 7715 | if (rate == srate->bitrate) { |
| 7716 | mask |= 1 << ridx; |
| 7717 | break; |
| 7718 | } |
| 7719 | } |
| 7720 | if (ridx == sband->n_bitrates) |
| 7721 | return 0; /* rate not found */ |
| 7722 | } |
| 7723 | |
| 7724 | return mask; |
| 7725 | } |
| 7726 | |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7727 | static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, |
| 7728 | u8 *rates, u8 rates_len, |
| 7729 | u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) |
| 7730 | { |
| 7731 | u8 i; |
| 7732 | |
| 7733 | memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); |
| 7734 | |
| 7735 | for (i = 0; i < rates_len; i++) { |
| 7736 | int ridx, rbit; |
| 7737 | |
| 7738 | ridx = rates[i] / 8; |
| 7739 | rbit = BIT(rates[i] % 8); |
| 7740 | |
| 7741 | /* check validity */ |
Dan Carpenter | 910570b5 | 2012-02-01 10:42:11 +0300 | [diff] [blame] | 7742 | if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7743 | return false; |
| 7744 | |
| 7745 | /* check availability */ |
| 7746 | if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) |
| 7747 | mcs[ridx] |= rbit; |
| 7748 | else |
| 7749 | return false; |
| 7750 | } |
| 7751 | |
| 7752 | return true; |
| 7753 | } |
| 7754 | |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 7755 | static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map) |
| 7756 | { |
| 7757 | u16 mcs_mask = 0; |
| 7758 | |
| 7759 | switch (vht_mcs_map) { |
| 7760 | case IEEE80211_VHT_MCS_NOT_SUPPORTED: |
| 7761 | break; |
| 7762 | case IEEE80211_VHT_MCS_SUPPORT_0_7: |
| 7763 | mcs_mask = 0x00FF; |
| 7764 | break; |
| 7765 | case IEEE80211_VHT_MCS_SUPPORT_0_8: |
| 7766 | mcs_mask = 0x01FF; |
| 7767 | break; |
| 7768 | case IEEE80211_VHT_MCS_SUPPORT_0_9: |
| 7769 | mcs_mask = 0x03FF; |
| 7770 | break; |
| 7771 | default: |
| 7772 | break; |
| 7773 | } |
| 7774 | |
| 7775 | return mcs_mask; |
| 7776 | } |
| 7777 | |
| 7778 | static void vht_build_mcs_mask(u16 vht_mcs_map, |
| 7779 | u16 vht_mcs_mask[NL80211_VHT_NSS_MAX]) |
| 7780 | { |
| 7781 | u8 nss; |
| 7782 | |
| 7783 | for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) { |
| 7784 | vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03); |
| 7785 | vht_mcs_map >>= 2; |
| 7786 | } |
| 7787 | } |
| 7788 | |
| 7789 | static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband, |
| 7790 | struct nl80211_txrate_vht *txrate, |
| 7791 | u16 mcs[NL80211_VHT_NSS_MAX]) |
| 7792 | { |
| 7793 | u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); |
| 7794 | u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {}; |
| 7795 | u8 i; |
| 7796 | |
| 7797 | if (!sband->vht_cap.vht_supported) |
| 7798 | return false; |
| 7799 | |
| 7800 | memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX); |
| 7801 | |
| 7802 | /* Build vht_mcs_mask from VHT capabilities */ |
| 7803 | vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask); |
| 7804 | |
| 7805 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) { |
| 7806 | if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i]) |
| 7807 | mcs[i] = txrate->mcs[i]; |
| 7808 | else |
| 7809 | return false; |
| 7810 | } |
| 7811 | |
| 7812 | return true; |
| 7813 | } |
| 7814 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 7815 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7816 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
| 7817 | .len = NL80211_MAX_SUPP_RATES }, |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 7818 | [NL80211_TXRATE_HT] = { .type = NLA_BINARY, |
| 7819 | .len = NL80211_MAX_SUPP_HT_RATES }, |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 7820 | [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)}, |
Janusz Dziedzic | 0b9323f | 2014-01-08 08:46:02 +0100 | [diff] [blame] | 7821 | [NL80211_TXRATE_GI] = { .type = NLA_U8 }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7822 | }; |
| 7823 | |
| 7824 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, |
| 7825 | struct genl_info *info) |
| 7826 | { |
| 7827 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7828 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7829 | struct cfg80211_bitrate_mask mask; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7830 | int rem, i; |
| 7831 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7832 | struct nlattr *tx_rates; |
| 7833 | struct ieee80211_supported_band *sband; |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 7834 | u16 vht_tx_mcs_map; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7835 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7836 | if (!rdev->ops->set_bitrate_mask) |
| 7837 | return -EOPNOTSUPP; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7838 | |
| 7839 | memset(&mask, 0, sizeof(mask)); |
| 7840 | /* Default to all rates enabled */ |
| 7841 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) { |
| 7842 | sband = rdev->wiphy.bands[i]; |
Janusz Dziedzic | 7869303 | 2013-12-03 09:50:44 +0100 | [diff] [blame] | 7843 | |
| 7844 | if (!sband) |
| 7845 | continue; |
| 7846 | |
| 7847 | mask.control[i].legacy = (1 << sband->n_bitrates) - 1; |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 7848 | memcpy(mask.control[i].ht_mcs, |
Janusz Dziedzic | 7869303 | 2013-12-03 09:50:44 +0100 | [diff] [blame] | 7849 | sband->ht_cap.mcs.rx_mask, |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 7850 | sizeof(mask.control[i].ht_mcs)); |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 7851 | |
| 7852 | if (!sband->vht_cap.vht_supported) |
| 7853 | continue; |
| 7854 | |
| 7855 | vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); |
| 7856 | 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] | 7857 | } |
| 7858 | |
Janusz Dziedzic | b9243ab | 2013-12-05 10:02:14 +0100 | [diff] [blame] | 7859 | /* if no rates are given set it back to the defaults */ |
| 7860 | if (!info->attrs[NL80211_ATTR_TX_RATES]) |
| 7861 | goto out; |
| 7862 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7863 | /* |
| 7864 | * The nested attribute uses enum nl80211_band as the index. This maps |
| 7865 | * directly to the enum ieee80211_band values used in cfg80211. |
| 7866 | */ |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7867 | 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] | 7868 | 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] | 7869 | enum ieee80211_band band = nla_type(tx_rates); |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 7870 | int err; |
| 7871 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7872 | if (band < 0 || band >= IEEE80211_NUM_BANDS) |
| 7873 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7874 | sband = rdev->wiphy.bands[band]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7875 | if (sband == NULL) |
| 7876 | return -EINVAL; |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 7877 | err = nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), |
| 7878 | nla_len(tx_rates), nl80211_txattr_policy); |
| 7879 | if (err) |
| 7880 | return err; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7881 | if (tb[NL80211_TXRATE_LEGACY]) { |
| 7882 | mask.control[band].legacy = rateset_to_mask( |
| 7883 | sband, |
| 7884 | nla_data(tb[NL80211_TXRATE_LEGACY]), |
| 7885 | nla_len(tb[NL80211_TXRATE_LEGACY])); |
Bala Shanmugam | 218d2e2 | 2012-04-20 19:12:58 +0530 | [diff] [blame] | 7886 | if ((mask.control[band].legacy == 0) && |
| 7887 | nla_len(tb[NL80211_TXRATE_LEGACY])) |
| 7888 | return -EINVAL; |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7889 | } |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 7890 | if (tb[NL80211_TXRATE_HT]) { |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7891 | if (!ht_rateset_to_mask( |
| 7892 | sband, |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 7893 | nla_data(tb[NL80211_TXRATE_HT]), |
| 7894 | nla_len(tb[NL80211_TXRATE_HT]), |
| 7895 | mask.control[band].ht_mcs)) |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7896 | return -EINVAL; |
| 7897 | } |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 7898 | if (tb[NL80211_TXRATE_VHT]) { |
| 7899 | if (!vht_set_mcs_mask( |
| 7900 | sband, |
| 7901 | nla_data(tb[NL80211_TXRATE_VHT]), |
| 7902 | mask.control[band].vht_mcs)) |
| 7903 | return -EINVAL; |
| 7904 | } |
Janusz Dziedzic | 0b9323f | 2014-01-08 08:46:02 +0100 | [diff] [blame] | 7905 | if (tb[NL80211_TXRATE_GI]) { |
| 7906 | mask.control[band].gi = |
| 7907 | nla_get_u8(tb[NL80211_TXRATE_GI]); |
| 7908 | if (mask.control[band].gi > NL80211_TXRATE_FORCE_LGI) |
| 7909 | return -EINVAL; |
| 7910 | } |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7911 | |
| 7912 | if (mask.control[band].legacy == 0) { |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 7913 | /* don't allow empty legacy rates if HT or VHT |
| 7914 | * are not even supported. |
| 7915 | */ |
| 7916 | if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported || |
| 7917 | rdev->wiphy.bands[band]->vht_cap.vht_supported)) |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7918 | return -EINVAL; |
| 7919 | |
| 7920 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 7921 | if (mask.control[band].ht_mcs[i]) |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 7922 | goto out; |
| 7923 | |
| 7924 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) |
| 7925 | if (mask.control[band].vht_mcs[i]) |
| 7926 | goto out; |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7927 | |
| 7928 | /* legacy and mcs rates may not be both empty */ |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 7929 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7930 | } |
| 7931 | } |
| 7932 | |
Janusz Dziedzic | b9243ab | 2013-12-05 10:02:14 +0100 | [diff] [blame] | 7933 | out: |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7934 | return rdev_set_bitrate_mask(rdev, dev, NULL, &mask); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7935 | } |
| 7936 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7937 | 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] | 7938 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7939 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7940 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7941 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7942 | |
| 7943 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) |
| 7944 | return -EINVAL; |
| 7945 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7946 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
| 7947 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7948 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7949 | switch (wdev->iftype) { |
| 7950 | case NL80211_IFTYPE_STATION: |
| 7951 | case NL80211_IFTYPE_ADHOC: |
| 7952 | case NL80211_IFTYPE_P2P_CLIENT: |
| 7953 | case NL80211_IFTYPE_AP: |
| 7954 | case NL80211_IFTYPE_AP_VLAN: |
| 7955 | case NL80211_IFTYPE_MESH_POINT: |
| 7956 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7957 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7958 | break; |
| 7959 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7960 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7961 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7962 | |
| 7963 | /* not much point in registering if we can't reply */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7964 | if (!rdev->ops->mgmt_tx) |
| 7965 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7966 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7967 | return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7968 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
| 7969 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7970 | } |
| 7971 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7972 | 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] | 7973 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7974 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7975 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7976 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7977 | int err; |
Johannes Berg | d64d373 | 2011-11-10 09:44:46 +0100 | [diff] [blame] | 7978 | void *hdr = NULL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7979 | u64 cookie; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7980 | struct sk_buff *msg = NULL; |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7981 | struct cfg80211_mgmt_tx_params params = { |
| 7982 | .dont_wait_for_ack = |
| 7983 | info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK], |
| 7984 | }; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7985 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7986 | if (!info->attrs[NL80211_ATTR_FRAME]) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7987 | return -EINVAL; |
| 7988 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7989 | if (!rdev->ops->mgmt_tx) |
| 7990 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7991 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7992 | switch (wdev->iftype) { |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 7993 | case NL80211_IFTYPE_P2P_DEVICE: |
| 7994 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 7995 | return -EINVAL; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7996 | case NL80211_IFTYPE_STATION: |
| 7997 | case NL80211_IFTYPE_ADHOC: |
| 7998 | case NL80211_IFTYPE_P2P_CLIENT: |
| 7999 | case NL80211_IFTYPE_AP: |
| 8000 | case NL80211_IFTYPE_AP_VLAN: |
| 8001 | case NL80211_IFTYPE_MESH_POINT: |
| 8002 | case NL80211_IFTYPE_P2P_GO: |
| 8003 | break; |
| 8004 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8005 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8006 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8007 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8008 | if (info->attrs[NL80211_ATTR_DURATION]) { |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 8009 | if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8010 | return -EINVAL; |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 8011 | params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 8012 | |
| 8013 | /* |
| 8014 | * We should wait on the channel for at least a minimum amount |
| 8015 | * of time (10ms) but no longer than the driver supports. |
| 8016 | */ |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 8017 | if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 8018 | params.wait > rdev->wiphy.max_remain_on_channel_duration) |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 8019 | return -EINVAL; |
| 8020 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8021 | } |
| 8022 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 8023 | params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8024 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 8025 | if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 8026 | return -EINVAL; |
| 8027 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 8028 | 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] | 8029 | |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 8030 | /* get the channel if any has been specified, otherwise pass NULL to |
| 8031 | * the driver. The latter will use the current one |
| 8032 | */ |
| 8033 | chandef.chan = NULL; |
| 8034 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 8035 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 8036 | if (err) |
| 8037 | return err; |
| 8038 | } |
| 8039 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 8040 | if (!chandef.chan && params.offchan) |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 8041 | return -EINVAL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8042 | |
Andrei Otcheretianski | 34d22ce | 2014-05-09 14:11:44 +0300 | [diff] [blame] | 8043 | params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]); |
| 8044 | params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]); |
| 8045 | |
| 8046 | if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) { |
| 8047 | int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]); |
| 8048 | int i; |
| 8049 | |
| 8050 | if (len % sizeof(u16)) |
| 8051 | return -EINVAL; |
| 8052 | |
| 8053 | params.n_csa_offsets = len / sizeof(u16); |
| 8054 | params.csa_offsets = |
| 8055 | nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]); |
| 8056 | |
| 8057 | /* check that all the offsets fit the frame */ |
| 8058 | for (i = 0; i < params.n_csa_offsets; i++) { |
| 8059 | if (params.csa_offsets[i] >= params.len) |
| 8060 | return -EINVAL; |
| 8061 | } |
| 8062 | } |
| 8063 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 8064 | if (!params.dont_wait_for_ack) { |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 8065 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 8066 | if (!msg) |
| 8067 | return -ENOMEM; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8068 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8069 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 8070 | NL80211_CMD_FRAME); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 8071 | if (!hdr) { |
| 8072 | err = -ENOBUFS; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 8073 | goto free_msg; |
| 8074 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8075 | } |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 8076 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 8077 | params.chan = chandef.chan; |
| 8078 | err = cfg80211_mlme_mgmt_tx(rdev, wdev, ¶ms, &cookie); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8079 | if (err) |
| 8080 | goto free_msg; |
| 8081 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 8082 | if (msg) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8083 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 8084 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8085 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 8086 | genlmsg_end(msg, hdr); |
| 8087 | return genlmsg_reply(msg, info); |
| 8088 | } |
| 8089 | |
| 8090 | return 0; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8091 | |
| 8092 | nla_put_failure: |
| 8093 | err = -ENOBUFS; |
| 8094 | free_msg: |
| 8095 | nlmsg_free(msg); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8096 | return err; |
| 8097 | } |
| 8098 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8099 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
| 8100 | { |
| 8101 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8102 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8103 | u64 cookie; |
| 8104 | |
| 8105 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 8106 | return -EINVAL; |
| 8107 | |
| 8108 | if (!rdev->ops->mgmt_tx_cancel_wait) |
| 8109 | return -EOPNOTSUPP; |
| 8110 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8111 | switch (wdev->iftype) { |
| 8112 | case NL80211_IFTYPE_STATION: |
| 8113 | case NL80211_IFTYPE_ADHOC: |
| 8114 | case NL80211_IFTYPE_P2P_CLIENT: |
| 8115 | case NL80211_IFTYPE_AP: |
| 8116 | case NL80211_IFTYPE_AP_VLAN: |
| 8117 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8118 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8119 | break; |
| 8120 | default: |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8121 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8122 | } |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8123 | |
| 8124 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 8125 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8126 | return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie); |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8127 | } |
| 8128 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8129 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
| 8130 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8131 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8132 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8133 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8134 | u8 ps_state; |
| 8135 | bool state; |
| 8136 | int err; |
| 8137 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8138 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
| 8139 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8140 | |
| 8141 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); |
| 8142 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8143 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
| 8144 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8145 | |
| 8146 | wdev = dev->ieee80211_ptr; |
| 8147 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8148 | if (!rdev->ops->set_power_mgmt) |
| 8149 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8150 | |
| 8151 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; |
| 8152 | |
| 8153 | if (state == wdev->ps) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8154 | return 0; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8155 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8156 | err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8157 | if (!err) |
| 8158 | wdev->ps = state; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8159 | return err; |
| 8160 | } |
| 8161 | |
| 8162 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) |
| 8163 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8164 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8165 | enum nl80211_ps_state ps_state; |
| 8166 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8167 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8168 | struct sk_buff *msg; |
| 8169 | void *hdr; |
| 8170 | int err; |
| 8171 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8172 | wdev = dev->ieee80211_ptr; |
| 8173 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8174 | if (!rdev->ops->set_power_mgmt) |
| 8175 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8176 | |
| 8177 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8178 | if (!msg) |
| 8179 | return -ENOMEM; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8180 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8181 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8182 | NL80211_CMD_GET_POWER_SAVE); |
| 8183 | if (!hdr) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8184 | err = -ENOBUFS; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8185 | goto free_msg; |
| 8186 | } |
| 8187 | |
| 8188 | if (wdev->ps) |
| 8189 | ps_state = NL80211_PS_ENABLED; |
| 8190 | else |
| 8191 | ps_state = NL80211_PS_DISABLED; |
| 8192 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8193 | if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) |
| 8194 | goto nla_put_failure; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8195 | |
| 8196 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8197 | return genlmsg_reply(msg, info); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8198 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8199 | nla_put_failure: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8200 | err = -ENOBUFS; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8201 | free_msg: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8202 | nlmsg_free(msg); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8203 | return err; |
| 8204 | } |
| 8205 | |
Johannes Berg | 94e860f | 2014-01-20 23:58:15 +0100 | [diff] [blame] | 8206 | static const struct nla_policy |
| 8207 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = { |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8208 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, |
| 8209 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, |
| 8210 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 8211 | [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 }, |
| 8212 | [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 }, |
| 8213 | [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8214 | }; |
| 8215 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 8216 | static int nl80211_set_cqm_txe(struct genl_info *info, |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 8217 | u32 rate, u32 pkts, u32 intvl) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 8218 | { |
| 8219 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 8220 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 8221 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 8222 | |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 8223 | if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 8224 | return -EINVAL; |
| 8225 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 8226 | if (!rdev->ops->set_cqm_txe_config) |
| 8227 | return -EOPNOTSUPP; |
| 8228 | |
| 8229 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
| 8230 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 8231 | return -EOPNOTSUPP; |
| 8232 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8233 | return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 8234 | } |
| 8235 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8236 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
| 8237 | s32 threshold, u32 hysteresis) |
| 8238 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8239 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8240 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 8241 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8242 | |
| 8243 | if (threshold > 0) |
| 8244 | return -EINVAL; |
| 8245 | |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 8246 | /* disabling - hysteresis should also be zero then */ |
| 8247 | if (threshold == 0) |
| 8248 | hysteresis = 0; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8249 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8250 | if (!rdev->ops->set_cqm_rssi_config) |
| 8251 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8252 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 8253 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8254 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 8255 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8256 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8257 | return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8258 | } |
| 8259 | |
| 8260 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) |
| 8261 | { |
| 8262 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; |
| 8263 | struct nlattr *cqm; |
| 8264 | int err; |
| 8265 | |
| 8266 | cqm = info->attrs[NL80211_ATTR_CQM]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 8267 | if (!cqm) |
| 8268 | return -EINVAL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8269 | |
| 8270 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, |
| 8271 | nl80211_attr_cqm_policy); |
| 8272 | if (err) |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 8273 | return err; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8274 | |
| 8275 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && |
| 8276 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 8277 | s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
| 8278 | u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8279 | |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 8280 | return nl80211_set_cqm_rssi(info, threshold, hysteresis); |
| 8281 | } |
| 8282 | |
| 8283 | if (attrs[NL80211_ATTR_CQM_TXE_RATE] && |
| 8284 | attrs[NL80211_ATTR_CQM_TXE_PKTS] && |
| 8285 | attrs[NL80211_ATTR_CQM_TXE_INTVL]) { |
| 8286 | u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]); |
| 8287 | u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]); |
| 8288 | u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]); |
| 8289 | |
| 8290 | return nl80211_set_cqm_txe(info, rate, pkts, intvl); |
| 8291 | } |
| 8292 | |
| 8293 | return -EINVAL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8294 | } |
| 8295 | |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 8296 | static int nl80211_join_ocb(struct sk_buff *skb, struct genl_info *info) |
| 8297 | { |
| 8298 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8299 | struct net_device *dev = info->user_ptr[1]; |
| 8300 | struct ocb_setup setup = {}; |
| 8301 | int err; |
| 8302 | |
| 8303 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
| 8304 | if (err) |
| 8305 | return err; |
| 8306 | |
| 8307 | return cfg80211_join_ocb(rdev, dev, &setup); |
| 8308 | } |
| 8309 | |
| 8310 | static int nl80211_leave_ocb(struct sk_buff *skb, struct genl_info *info) |
| 8311 | { |
| 8312 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8313 | struct net_device *dev = info->user_ptr[1]; |
| 8314 | |
| 8315 | return cfg80211_leave_ocb(rdev, dev); |
| 8316 | } |
| 8317 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8318 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
| 8319 | { |
| 8320 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8321 | struct net_device *dev = info->user_ptr[1]; |
| 8322 | struct mesh_config cfg; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 8323 | struct mesh_setup setup; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8324 | int err; |
| 8325 | |
| 8326 | /* start with default */ |
| 8327 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 8328 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8329 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 8330 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8331 | /* and parse parameters if given */ |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 8332 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8333 | if (err) |
| 8334 | return err; |
| 8335 | } |
| 8336 | |
| 8337 | if (!info->attrs[NL80211_ATTR_MESH_ID] || |
| 8338 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) |
| 8339 | return -EINVAL; |
| 8340 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 8341 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
| 8342 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 8343 | |
Chun-Yeow Yeoh | 4bb6234 | 2011-11-24 17:15:20 -0800 | [diff] [blame] | 8344 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 8345 | !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, |
| 8346 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 8347 | return -EINVAL; |
| 8348 | |
Marco Porsch | 9bdbf04 | 2013-01-07 16:04:51 +0100 | [diff] [blame] | 8349 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 8350 | setup.beacon_interval = |
| 8351 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 8352 | if (setup.beacon_interval < 10 || |
| 8353 | setup.beacon_interval > 10000) |
| 8354 | return -EINVAL; |
| 8355 | } |
| 8356 | |
| 8357 | if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) { |
| 8358 | setup.dtim_period = |
| 8359 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 8360 | if (setup.dtim_period < 1 || setup.dtim_period > 100) |
| 8361 | return -EINVAL; |
| 8362 | } |
| 8363 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 8364 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
| 8365 | /* parse additional setup parameters if given */ |
| 8366 | err = nl80211_parse_mesh_setup(info, &setup); |
| 8367 | if (err) |
| 8368 | return err; |
| 8369 | } |
| 8370 | |
Thomas Pedersen | d37bb18 | 2013-03-04 13:06:13 -0800 | [diff] [blame] | 8371 | if (setup.user_mpm) |
| 8372 | cfg.auto_open_plinks = false; |
| 8373 | |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 8374 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 8375 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
| 8376 | if (err) |
| 8377 | return err; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 8378 | } else { |
| 8379 | /* cfg80211_join_mesh() will sort it out */ |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 8380 | setup.chandef.chan = NULL; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 8381 | } |
| 8382 | |
Ashok Nagarajan | ffb3cf3 | 2013-06-03 10:33:36 -0700 | [diff] [blame] | 8383 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 8384 | u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 8385 | int n_rates = |
| 8386 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 8387 | struct ieee80211_supported_band *sband; |
| 8388 | |
| 8389 | if (!setup.chandef.chan) |
| 8390 | return -EINVAL; |
| 8391 | |
| 8392 | sband = rdev->wiphy.bands[setup.chandef.chan->band]; |
| 8393 | |
| 8394 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 8395 | &setup.basic_rates); |
| 8396 | if (err) |
| 8397 | return err; |
| 8398 | } |
| 8399 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 8400 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8401 | } |
| 8402 | |
| 8403 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) |
| 8404 | { |
| 8405 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8406 | struct net_device *dev = info->user_ptr[1]; |
| 8407 | |
| 8408 | return cfg80211_leave_mesh(rdev, dev); |
| 8409 | } |
| 8410 | |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 8411 | #ifdef CONFIG_PM |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8412 | static int nl80211_send_wowlan_patterns(struct sk_buff *msg, |
| 8413 | struct cfg80211_registered_device *rdev) |
| 8414 | { |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8415 | struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config; |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8416 | struct nlattr *nl_pats, *nl_pat; |
| 8417 | int i, pat_len; |
| 8418 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8419 | if (!wowlan->n_patterns) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8420 | return 0; |
| 8421 | |
| 8422 | nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN); |
| 8423 | if (!nl_pats) |
| 8424 | return -ENOBUFS; |
| 8425 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8426 | for (i = 0; i < wowlan->n_patterns; i++) { |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8427 | nl_pat = nla_nest_start(msg, i + 1); |
| 8428 | if (!nl_pat) |
| 8429 | return -ENOBUFS; |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8430 | pat_len = wowlan->patterns[i].pattern_len; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8431 | 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] | 8432 | wowlan->patterns[i].mask) || |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8433 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
| 8434 | wowlan->patterns[i].pattern) || |
| 8435 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8436 | wowlan->patterns[i].pkt_offset)) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8437 | return -ENOBUFS; |
| 8438 | nla_nest_end(msg, nl_pat); |
| 8439 | } |
| 8440 | nla_nest_end(msg, nl_pats); |
| 8441 | |
| 8442 | return 0; |
| 8443 | } |
| 8444 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8445 | static int nl80211_send_wowlan_tcp(struct sk_buff *msg, |
| 8446 | struct cfg80211_wowlan_tcp *tcp) |
| 8447 | { |
| 8448 | struct nlattr *nl_tcp; |
| 8449 | |
| 8450 | if (!tcp) |
| 8451 | return 0; |
| 8452 | |
| 8453 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); |
| 8454 | if (!nl_tcp) |
| 8455 | return -ENOBUFS; |
| 8456 | |
| 8457 | if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) || |
| 8458 | nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) || |
| 8459 | nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) || |
| 8460 | nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) || |
| 8461 | nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) || |
| 8462 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 8463 | tcp->payload_len, tcp->payload) || |
| 8464 | nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, |
| 8465 | tcp->data_interval) || |
| 8466 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, |
| 8467 | tcp->wake_len, tcp->wake_data) || |
| 8468 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK, |
| 8469 | DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask)) |
| 8470 | return -ENOBUFS; |
| 8471 | |
| 8472 | if (tcp->payload_seq.len && |
| 8473 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ, |
| 8474 | sizeof(tcp->payload_seq), &tcp->payload_seq)) |
| 8475 | return -ENOBUFS; |
| 8476 | |
| 8477 | if (tcp->payload_tok.len && |
| 8478 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, |
| 8479 | sizeof(tcp->payload_tok) + tcp->tokens_size, |
| 8480 | &tcp->payload_tok)) |
| 8481 | return -ENOBUFS; |
| 8482 | |
Johannes Berg | e248ad3 | 2013-05-16 10:24:28 +0200 | [diff] [blame] | 8483 | nla_nest_end(msg, nl_tcp); |
| 8484 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8485 | return 0; |
| 8486 | } |
| 8487 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8488 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 8489 | { |
| 8490 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8491 | struct sk_buff *msg; |
| 8492 | void *hdr; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8493 | u32 size = NLMSG_DEFAULT_SIZE; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8494 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8495 | if (!rdev->wiphy.wowlan) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8496 | return -EOPNOTSUPP; |
| 8497 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8498 | if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) { |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8499 | /* adjust size to have room for all the data */ |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8500 | size += rdev->wiphy.wowlan_config->tcp->tokens_size + |
| 8501 | rdev->wiphy.wowlan_config->tcp->payload_len + |
| 8502 | rdev->wiphy.wowlan_config->tcp->wake_len + |
| 8503 | rdev->wiphy.wowlan_config->tcp->wake_len / 8; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8504 | } |
| 8505 | |
| 8506 | msg = nlmsg_new(size, GFP_KERNEL); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8507 | if (!msg) |
| 8508 | return -ENOMEM; |
| 8509 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8510 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8511 | NL80211_CMD_GET_WOWLAN); |
| 8512 | if (!hdr) |
| 8513 | goto nla_put_failure; |
| 8514 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8515 | if (rdev->wiphy.wowlan_config) { |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8516 | struct nlattr *nl_wowlan; |
| 8517 | |
| 8518 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
| 8519 | if (!nl_wowlan) |
| 8520 | goto nla_put_failure; |
| 8521 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8522 | if ((rdev->wiphy.wowlan_config->any && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8523 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8524 | (rdev->wiphy.wowlan_config->disconnect && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8525 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8526 | (rdev->wiphy.wowlan_config->magic_pkt && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8527 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8528 | (rdev->wiphy.wowlan_config->gtk_rekey_failure && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8529 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8530 | (rdev->wiphy.wowlan_config->eap_identity_req && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8531 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8532 | (rdev->wiphy.wowlan_config->four_way_handshake && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8533 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8534 | (rdev->wiphy.wowlan_config->rfkill_release && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8535 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 8536 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8537 | |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8538 | if (nl80211_send_wowlan_patterns(msg, rdev)) |
| 8539 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8540 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8541 | if (nl80211_send_wowlan_tcp(msg, |
| 8542 | rdev->wiphy.wowlan_config->tcp)) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8543 | goto nla_put_failure; |
| 8544 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8545 | nla_nest_end(msg, nl_wowlan); |
| 8546 | } |
| 8547 | |
| 8548 | genlmsg_end(msg, hdr); |
| 8549 | return genlmsg_reply(msg, info); |
| 8550 | |
| 8551 | nla_put_failure: |
| 8552 | nlmsg_free(msg); |
| 8553 | return -ENOBUFS; |
| 8554 | } |
| 8555 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8556 | static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev, |
| 8557 | struct nlattr *attr, |
| 8558 | struct cfg80211_wowlan *trig) |
| 8559 | { |
| 8560 | struct nlattr *tb[NUM_NL80211_WOWLAN_TCP]; |
| 8561 | struct cfg80211_wowlan_tcp *cfg; |
| 8562 | struct nl80211_wowlan_tcp_data_token *tok = NULL; |
| 8563 | struct nl80211_wowlan_tcp_data_seq *seq = NULL; |
| 8564 | u32 size; |
| 8565 | u32 data_size, wake_size, tokens_size = 0, wake_mask_size; |
| 8566 | int err, port; |
| 8567 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8568 | if (!rdev->wiphy.wowlan->tcp) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8569 | return -EINVAL; |
| 8570 | |
| 8571 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP, |
| 8572 | nla_data(attr), nla_len(attr), |
| 8573 | nl80211_wowlan_tcp_policy); |
| 8574 | if (err) |
| 8575 | return err; |
| 8576 | |
| 8577 | if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] || |
| 8578 | !tb[NL80211_WOWLAN_TCP_DST_IPV4] || |
| 8579 | !tb[NL80211_WOWLAN_TCP_DST_MAC] || |
| 8580 | !tb[NL80211_WOWLAN_TCP_DST_PORT] || |
| 8581 | !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] || |
| 8582 | !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] || |
| 8583 | !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] || |
| 8584 | !tb[NL80211_WOWLAN_TCP_WAKE_MASK]) |
| 8585 | return -EINVAL; |
| 8586 | |
| 8587 | data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8588 | if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8589 | return -EINVAL; |
| 8590 | |
| 8591 | if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) > |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8592 | rdev->wiphy.wowlan->tcp->data_interval_max || |
Johannes Berg | 723d568 | 2013-02-26 13:56:40 +0100 | [diff] [blame] | 8593 | nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8594 | return -EINVAL; |
| 8595 | |
| 8596 | wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8597 | if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8598 | return -EINVAL; |
| 8599 | |
| 8600 | wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]); |
| 8601 | if (wake_mask_size != DIV_ROUND_UP(wake_size, 8)) |
| 8602 | return -EINVAL; |
| 8603 | |
| 8604 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) { |
| 8605 | u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 8606 | |
| 8607 | tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 8608 | tokens_size = tokln - sizeof(*tok); |
| 8609 | |
| 8610 | if (!tok->len || tokens_size % tok->len) |
| 8611 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8612 | if (!rdev->wiphy.wowlan->tcp->tok) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8613 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8614 | if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8615 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8616 | if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8617 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8618 | if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8619 | return -EINVAL; |
| 8620 | if (tok->offset + tok->len > data_size) |
| 8621 | return -EINVAL; |
| 8622 | } |
| 8623 | |
| 8624 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) { |
| 8625 | seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8626 | if (!rdev->wiphy.wowlan->tcp->seq) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8627 | return -EINVAL; |
| 8628 | if (seq->len == 0 || seq->len > 4) |
| 8629 | return -EINVAL; |
| 8630 | if (seq->len + seq->offset > data_size) |
| 8631 | return -EINVAL; |
| 8632 | } |
| 8633 | |
| 8634 | size = sizeof(*cfg); |
| 8635 | size += data_size; |
| 8636 | size += wake_size + wake_mask_size; |
| 8637 | size += tokens_size; |
| 8638 | |
| 8639 | cfg = kzalloc(size, GFP_KERNEL); |
| 8640 | if (!cfg) |
| 8641 | return -ENOMEM; |
| 8642 | cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]); |
| 8643 | cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]); |
| 8644 | memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]), |
| 8645 | ETH_ALEN); |
| 8646 | if (tb[NL80211_WOWLAN_TCP_SRC_PORT]) |
| 8647 | port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]); |
| 8648 | else |
| 8649 | port = 0; |
| 8650 | #ifdef CONFIG_INET |
| 8651 | /* allocate a socket and port for it and use it */ |
| 8652 | err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM, |
| 8653 | IPPROTO_TCP, &cfg->sock, 1); |
| 8654 | if (err) { |
| 8655 | kfree(cfg); |
| 8656 | return err; |
| 8657 | } |
| 8658 | if (inet_csk_get_port(cfg->sock->sk, port)) { |
| 8659 | sock_release(cfg->sock); |
| 8660 | kfree(cfg); |
| 8661 | return -EADDRINUSE; |
| 8662 | } |
| 8663 | cfg->src_port = inet_sk(cfg->sock->sk)->inet_num; |
| 8664 | #else |
| 8665 | if (!port) { |
| 8666 | kfree(cfg); |
| 8667 | return -EINVAL; |
| 8668 | } |
| 8669 | cfg->src_port = port; |
| 8670 | #endif |
| 8671 | |
| 8672 | cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]); |
| 8673 | cfg->payload_len = data_size; |
| 8674 | cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size; |
| 8675 | memcpy((void *)cfg->payload, |
| 8676 | nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]), |
| 8677 | data_size); |
| 8678 | if (seq) |
| 8679 | cfg->payload_seq = *seq; |
| 8680 | cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]); |
| 8681 | cfg->wake_len = wake_size; |
| 8682 | cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size; |
| 8683 | memcpy((void *)cfg->wake_data, |
| 8684 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]), |
| 8685 | wake_size); |
| 8686 | cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size + |
| 8687 | data_size + wake_size; |
| 8688 | memcpy((void *)cfg->wake_mask, |
| 8689 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]), |
| 8690 | wake_mask_size); |
| 8691 | if (tok) { |
| 8692 | cfg->tokens_size = tokens_size; |
| 8693 | memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size); |
| 8694 | } |
| 8695 | |
| 8696 | trig->tcp = cfg; |
| 8697 | |
| 8698 | return 0; |
| 8699 | } |
| 8700 | |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame^] | 8701 | static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device *rdev, |
| 8702 | const struct wiphy_wowlan_support *wowlan, |
| 8703 | struct nlattr *attr, |
| 8704 | struct cfg80211_wowlan *trig) |
| 8705 | { |
| 8706 | struct nlattr **tb; |
| 8707 | int err; |
| 8708 | |
| 8709 | tb = kzalloc(NUM_NL80211_ATTR * sizeof(*tb), GFP_KERNEL); |
| 8710 | if (!tb) |
| 8711 | return -ENOMEM; |
| 8712 | |
| 8713 | if (!(wowlan->flags & WIPHY_WOWLAN_NET_DETECT)) { |
| 8714 | err = -EOPNOTSUPP; |
| 8715 | goto out; |
| 8716 | } |
| 8717 | |
| 8718 | err = nla_parse(tb, NL80211_ATTR_MAX, |
| 8719 | nla_data(attr), nla_len(attr), |
| 8720 | nl80211_policy); |
| 8721 | if (err) |
| 8722 | goto out; |
| 8723 | |
| 8724 | trig->nd_config = nl80211_parse_sched_scan(&rdev->wiphy, tb); |
| 8725 | err = PTR_ERR_OR_ZERO(trig->nd_config); |
| 8726 | if (err) |
| 8727 | trig->nd_config = NULL; |
| 8728 | |
| 8729 | out: |
| 8730 | kfree(tb); |
| 8731 | return err; |
| 8732 | } |
| 8733 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8734 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 8735 | { |
| 8736 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8737 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8738 | struct cfg80211_wowlan new_triggers = {}; |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8739 | struct cfg80211_wowlan *ntrig; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8740 | const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8741 | int err, i; |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8742 | bool prev_enabled = rdev->wiphy.wowlan_config; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8743 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8744 | if (!wowlan) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8745 | return -EOPNOTSUPP; |
| 8746 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8747 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) { |
| 8748 | cfg80211_rdev_free_wowlan(rdev); |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8749 | rdev->wiphy.wowlan_config = NULL; |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8750 | goto set_wakeup; |
| 8751 | } |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8752 | |
| 8753 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG, |
| 8754 | nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 8755 | nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 8756 | nl80211_wowlan_policy); |
| 8757 | if (err) |
| 8758 | return err; |
| 8759 | |
| 8760 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { |
| 8761 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) |
| 8762 | return -EINVAL; |
| 8763 | new_triggers.any = true; |
| 8764 | } |
| 8765 | |
| 8766 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { |
| 8767 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) |
| 8768 | return -EINVAL; |
| 8769 | new_triggers.disconnect = true; |
| 8770 | } |
| 8771 | |
| 8772 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { |
| 8773 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) |
| 8774 | return -EINVAL; |
| 8775 | new_triggers.magic_pkt = true; |
| 8776 | } |
| 8777 | |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 8778 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
| 8779 | return -EINVAL; |
| 8780 | |
| 8781 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { |
| 8782 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) |
| 8783 | return -EINVAL; |
| 8784 | new_triggers.gtk_rekey_failure = true; |
| 8785 | } |
| 8786 | |
| 8787 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { |
| 8788 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) |
| 8789 | return -EINVAL; |
| 8790 | new_triggers.eap_identity_req = true; |
| 8791 | } |
| 8792 | |
| 8793 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { |
| 8794 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) |
| 8795 | return -EINVAL; |
| 8796 | new_triggers.four_way_handshake = true; |
| 8797 | } |
| 8798 | |
| 8799 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { |
| 8800 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) |
| 8801 | return -EINVAL; |
| 8802 | new_triggers.rfkill_release = true; |
| 8803 | } |
| 8804 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8805 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
| 8806 | struct nlattr *pat; |
| 8807 | int n_patterns = 0; |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8808 | int rem, pat_len, mask_len, pkt_offset; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8809 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8810 | |
| 8811 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 8812 | rem) |
| 8813 | n_patterns++; |
| 8814 | if (n_patterns > wowlan->n_patterns) |
| 8815 | return -EINVAL; |
| 8816 | |
| 8817 | new_triggers.patterns = kcalloc(n_patterns, |
| 8818 | sizeof(new_triggers.patterns[0]), |
| 8819 | GFP_KERNEL); |
| 8820 | if (!new_triggers.patterns) |
| 8821 | return -ENOMEM; |
| 8822 | |
| 8823 | new_triggers.n_patterns = n_patterns; |
| 8824 | i = 0; |
| 8825 | |
| 8826 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 8827 | rem) { |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 8828 | u8 *mask_pat; |
| 8829 | |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8830 | nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat), |
| 8831 | nla_len(pat), NULL); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8832 | err = -EINVAL; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8833 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
| 8834 | !pat_tb[NL80211_PKTPAT_PATTERN]) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8835 | goto error; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8836 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8837 | mask_len = DIV_ROUND_UP(pat_len, 8); |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8838 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8839 | goto error; |
| 8840 | if (pat_len > wowlan->pattern_max_len || |
| 8841 | pat_len < wowlan->pattern_min_len) |
| 8842 | goto error; |
| 8843 | |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8844 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8845 | pkt_offset = 0; |
| 8846 | else |
| 8847 | pkt_offset = nla_get_u32( |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8848 | pat_tb[NL80211_PKTPAT_OFFSET]); |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8849 | if (pkt_offset > wowlan->max_pkt_offset) |
| 8850 | goto error; |
| 8851 | new_triggers.patterns[i].pkt_offset = pkt_offset; |
| 8852 | |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 8853 | mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 8854 | if (!mask_pat) { |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8855 | err = -ENOMEM; |
| 8856 | goto error; |
| 8857 | } |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 8858 | new_triggers.patterns[i].mask = mask_pat; |
| 8859 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]), |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8860 | mask_len); |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 8861 | mask_pat += mask_len; |
| 8862 | new_triggers.patterns[i].pattern = mask_pat; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8863 | new_triggers.patterns[i].pattern_len = pat_len; |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 8864 | memcpy(mask_pat, |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8865 | nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8866 | pat_len); |
| 8867 | i++; |
| 8868 | } |
| 8869 | } |
| 8870 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8871 | if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) { |
| 8872 | err = nl80211_parse_wowlan_tcp( |
| 8873 | rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION], |
| 8874 | &new_triggers); |
| 8875 | if (err) |
| 8876 | goto error; |
| 8877 | } |
| 8878 | |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame^] | 8879 | if (tb[NL80211_WOWLAN_TRIG_NET_DETECT]) { |
| 8880 | err = nl80211_parse_wowlan_nd( |
| 8881 | rdev, wowlan, tb[NL80211_WOWLAN_TRIG_NET_DETECT], |
| 8882 | &new_triggers); |
| 8883 | if (err) |
| 8884 | goto error; |
| 8885 | } |
| 8886 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8887 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL); |
| 8888 | if (!ntrig) { |
| 8889 | err = -ENOMEM; |
| 8890 | goto error; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8891 | } |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8892 | cfg80211_rdev_free_wowlan(rdev); |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8893 | rdev->wiphy.wowlan_config = ntrig; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8894 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8895 | set_wakeup: |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8896 | if (rdev->ops->set_wakeup && |
| 8897 | prev_enabled != !!rdev->wiphy.wowlan_config) |
| 8898 | rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config); |
Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame] | 8899 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8900 | return 0; |
| 8901 | error: |
| 8902 | for (i = 0; i < new_triggers.n_patterns; i++) |
| 8903 | kfree(new_triggers.patterns[i].mask); |
| 8904 | kfree(new_triggers.patterns); |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8905 | if (new_triggers.tcp && new_triggers.tcp->sock) |
| 8906 | sock_release(new_triggers.tcp->sock); |
| 8907 | kfree(new_triggers.tcp); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8908 | return err; |
| 8909 | } |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 8910 | #endif |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8911 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 8912 | static int nl80211_send_coalesce_rules(struct sk_buff *msg, |
| 8913 | struct cfg80211_registered_device *rdev) |
| 8914 | { |
| 8915 | struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules; |
| 8916 | int i, j, pat_len; |
| 8917 | struct cfg80211_coalesce_rules *rule; |
| 8918 | |
| 8919 | if (!rdev->coalesce->n_rules) |
| 8920 | return 0; |
| 8921 | |
| 8922 | nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE); |
| 8923 | if (!nl_rules) |
| 8924 | return -ENOBUFS; |
| 8925 | |
| 8926 | for (i = 0; i < rdev->coalesce->n_rules; i++) { |
| 8927 | nl_rule = nla_nest_start(msg, i + 1); |
| 8928 | if (!nl_rule) |
| 8929 | return -ENOBUFS; |
| 8930 | |
| 8931 | rule = &rdev->coalesce->rules[i]; |
| 8932 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY, |
| 8933 | rule->delay)) |
| 8934 | return -ENOBUFS; |
| 8935 | |
| 8936 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION, |
| 8937 | rule->condition)) |
| 8938 | return -ENOBUFS; |
| 8939 | |
| 8940 | nl_pats = nla_nest_start(msg, |
| 8941 | NL80211_ATTR_COALESCE_RULE_PKT_PATTERN); |
| 8942 | if (!nl_pats) |
| 8943 | return -ENOBUFS; |
| 8944 | |
| 8945 | for (j = 0; j < rule->n_patterns; j++) { |
| 8946 | nl_pat = nla_nest_start(msg, j + 1); |
| 8947 | if (!nl_pat) |
| 8948 | return -ENOBUFS; |
| 8949 | pat_len = rule->patterns[j].pattern_len; |
| 8950 | if (nla_put(msg, NL80211_PKTPAT_MASK, |
| 8951 | DIV_ROUND_UP(pat_len, 8), |
| 8952 | rule->patterns[j].mask) || |
| 8953 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
| 8954 | rule->patterns[j].pattern) || |
| 8955 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, |
| 8956 | rule->patterns[j].pkt_offset)) |
| 8957 | return -ENOBUFS; |
| 8958 | nla_nest_end(msg, nl_pat); |
| 8959 | } |
| 8960 | nla_nest_end(msg, nl_pats); |
| 8961 | nla_nest_end(msg, nl_rule); |
| 8962 | } |
| 8963 | nla_nest_end(msg, nl_rules); |
| 8964 | |
| 8965 | return 0; |
| 8966 | } |
| 8967 | |
| 8968 | static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info) |
| 8969 | { |
| 8970 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8971 | struct sk_buff *msg; |
| 8972 | void *hdr; |
| 8973 | |
| 8974 | if (!rdev->wiphy.coalesce) |
| 8975 | return -EOPNOTSUPP; |
| 8976 | |
| 8977 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 8978 | if (!msg) |
| 8979 | return -ENOMEM; |
| 8980 | |
| 8981 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 8982 | NL80211_CMD_GET_COALESCE); |
| 8983 | if (!hdr) |
| 8984 | goto nla_put_failure; |
| 8985 | |
| 8986 | if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev)) |
| 8987 | goto nla_put_failure; |
| 8988 | |
| 8989 | genlmsg_end(msg, hdr); |
| 8990 | return genlmsg_reply(msg, info); |
| 8991 | |
| 8992 | nla_put_failure: |
| 8993 | nlmsg_free(msg); |
| 8994 | return -ENOBUFS; |
| 8995 | } |
| 8996 | |
| 8997 | void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev) |
| 8998 | { |
| 8999 | struct cfg80211_coalesce *coalesce = rdev->coalesce; |
| 9000 | int i, j; |
| 9001 | struct cfg80211_coalesce_rules *rule; |
| 9002 | |
| 9003 | if (!coalesce) |
| 9004 | return; |
| 9005 | |
| 9006 | for (i = 0; i < coalesce->n_rules; i++) { |
| 9007 | rule = &coalesce->rules[i]; |
| 9008 | for (j = 0; j < rule->n_patterns; j++) |
| 9009 | kfree(rule->patterns[j].mask); |
| 9010 | kfree(rule->patterns); |
| 9011 | } |
| 9012 | kfree(coalesce->rules); |
| 9013 | kfree(coalesce); |
| 9014 | rdev->coalesce = NULL; |
| 9015 | } |
| 9016 | |
| 9017 | static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev, |
| 9018 | struct nlattr *rule, |
| 9019 | struct cfg80211_coalesce_rules *new_rule) |
| 9020 | { |
| 9021 | int err, i; |
| 9022 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; |
| 9023 | struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat; |
| 9024 | int rem, pat_len, mask_len, pkt_offset, n_patterns = 0; |
| 9025 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
| 9026 | |
| 9027 | err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule), |
| 9028 | nla_len(rule), nl80211_coalesce_policy); |
| 9029 | if (err) |
| 9030 | return err; |
| 9031 | |
| 9032 | if (tb[NL80211_ATTR_COALESCE_RULE_DELAY]) |
| 9033 | new_rule->delay = |
| 9034 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]); |
| 9035 | if (new_rule->delay > coalesce->max_delay) |
| 9036 | return -EINVAL; |
| 9037 | |
| 9038 | if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION]) |
| 9039 | new_rule->condition = |
| 9040 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]); |
| 9041 | if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH && |
| 9042 | new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH) |
| 9043 | return -EINVAL; |
| 9044 | |
| 9045 | if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN]) |
| 9046 | return -EINVAL; |
| 9047 | |
| 9048 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], |
| 9049 | rem) |
| 9050 | n_patterns++; |
| 9051 | if (n_patterns > coalesce->n_patterns) |
| 9052 | return -EINVAL; |
| 9053 | |
| 9054 | new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]), |
| 9055 | GFP_KERNEL); |
| 9056 | if (!new_rule->patterns) |
| 9057 | return -ENOMEM; |
| 9058 | |
| 9059 | new_rule->n_patterns = n_patterns; |
| 9060 | i = 0; |
| 9061 | |
| 9062 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], |
| 9063 | rem) { |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 9064 | u8 *mask_pat; |
| 9065 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 9066 | nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat), |
| 9067 | nla_len(pat), NULL); |
| 9068 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
| 9069 | !pat_tb[NL80211_PKTPAT_PATTERN]) |
| 9070 | return -EINVAL; |
| 9071 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
| 9072 | mask_len = DIV_ROUND_UP(pat_len, 8); |
| 9073 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
| 9074 | return -EINVAL; |
| 9075 | if (pat_len > coalesce->pattern_max_len || |
| 9076 | pat_len < coalesce->pattern_min_len) |
| 9077 | return -EINVAL; |
| 9078 | |
| 9079 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
| 9080 | pkt_offset = 0; |
| 9081 | else |
| 9082 | pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]); |
| 9083 | if (pkt_offset > coalesce->max_pkt_offset) |
| 9084 | return -EINVAL; |
| 9085 | new_rule->patterns[i].pkt_offset = pkt_offset; |
| 9086 | |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 9087 | mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 9088 | if (!mask_pat) |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 9089 | return -ENOMEM; |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 9090 | |
| 9091 | new_rule->patterns[i].mask = mask_pat; |
| 9092 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]), |
| 9093 | mask_len); |
| 9094 | |
| 9095 | mask_pat += mask_len; |
| 9096 | new_rule->patterns[i].pattern = mask_pat; |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 9097 | new_rule->patterns[i].pattern_len = pat_len; |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 9098 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
| 9099 | pat_len); |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 9100 | i++; |
| 9101 | } |
| 9102 | |
| 9103 | return 0; |
| 9104 | } |
| 9105 | |
| 9106 | static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info) |
| 9107 | { |
| 9108 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9109 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; |
| 9110 | struct cfg80211_coalesce new_coalesce = {}; |
| 9111 | struct cfg80211_coalesce *n_coalesce; |
| 9112 | int err, rem_rule, n_rules = 0, i, j; |
| 9113 | struct nlattr *rule; |
| 9114 | struct cfg80211_coalesce_rules *tmp_rule; |
| 9115 | |
| 9116 | if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce) |
| 9117 | return -EOPNOTSUPP; |
| 9118 | |
| 9119 | if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) { |
| 9120 | cfg80211_rdev_free_coalesce(rdev); |
| 9121 | rdev->ops->set_coalesce(&rdev->wiphy, NULL); |
| 9122 | return 0; |
| 9123 | } |
| 9124 | |
| 9125 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], |
| 9126 | rem_rule) |
| 9127 | n_rules++; |
| 9128 | if (n_rules > coalesce->n_rules) |
| 9129 | return -EINVAL; |
| 9130 | |
| 9131 | new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]), |
| 9132 | GFP_KERNEL); |
| 9133 | if (!new_coalesce.rules) |
| 9134 | return -ENOMEM; |
| 9135 | |
| 9136 | new_coalesce.n_rules = n_rules; |
| 9137 | i = 0; |
| 9138 | |
| 9139 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], |
| 9140 | rem_rule) { |
| 9141 | err = nl80211_parse_coalesce_rule(rdev, rule, |
| 9142 | &new_coalesce.rules[i]); |
| 9143 | if (err) |
| 9144 | goto error; |
| 9145 | |
| 9146 | i++; |
| 9147 | } |
| 9148 | |
| 9149 | err = rdev->ops->set_coalesce(&rdev->wiphy, &new_coalesce); |
| 9150 | if (err) |
| 9151 | goto error; |
| 9152 | |
| 9153 | n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL); |
| 9154 | if (!n_coalesce) { |
| 9155 | err = -ENOMEM; |
| 9156 | goto error; |
| 9157 | } |
| 9158 | cfg80211_rdev_free_coalesce(rdev); |
| 9159 | rdev->coalesce = n_coalesce; |
| 9160 | |
| 9161 | return 0; |
| 9162 | error: |
| 9163 | for (i = 0; i < new_coalesce.n_rules; i++) { |
| 9164 | tmp_rule = &new_coalesce.rules[i]; |
| 9165 | for (j = 0; j < tmp_rule->n_patterns; j++) |
| 9166 | kfree(tmp_rule->patterns[j].mask); |
| 9167 | kfree(tmp_rule->patterns); |
| 9168 | } |
| 9169 | kfree(new_coalesce.rules); |
| 9170 | |
| 9171 | return err; |
| 9172 | } |
| 9173 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 9174 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
| 9175 | { |
| 9176 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9177 | struct net_device *dev = info->user_ptr[1]; |
| 9178 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9179 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; |
| 9180 | struct cfg80211_gtk_rekey_data rekey_data; |
| 9181 | int err; |
| 9182 | |
| 9183 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) |
| 9184 | return -EINVAL; |
| 9185 | |
| 9186 | err = nla_parse(tb, MAX_NL80211_REKEY_DATA, |
| 9187 | nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 9188 | nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 9189 | nl80211_rekey_policy); |
| 9190 | if (err) |
| 9191 | return err; |
| 9192 | |
| 9193 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) |
| 9194 | return -ERANGE; |
| 9195 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) |
| 9196 | return -ERANGE; |
| 9197 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) |
| 9198 | return -ERANGE; |
| 9199 | |
Johannes Berg | 78f686c | 2014-09-10 22:28:06 +0300 | [diff] [blame] | 9200 | rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]); |
| 9201 | rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]); |
| 9202 | rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 9203 | |
| 9204 | wdev_lock(wdev); |
| 9205 | if (!wdev->current_bss) { |
| 9206 | err = -ENOTCONN; |
| 9207 | goto out; |
| 9208 | } |
| 9209 | |
| 9210 | if (!rdev->ops->set_rekey_data) { |
| 9211 | err = -EOPNOTSUPP; |
| 9212 | goto out; |
| 9213 | } |
| 9214 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 9215 | err = rdev_set_rekey_data(rdev, dev, &rekey_data); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 9216 | out: |
| 9217 | wdev_unlock(wdev); |
| 9218 | return err; |
| 9219 | } |
| 9220 | |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9221 | static int nl80211_register_unexpected_frame(struct sk_buff *skb, |
| 9222 | struct genl_info *info) |
| 9223 | { |
| 9224 | struct net_device *dev = info->user_ptr[1]; |
| 9225 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9226 | |
| 9227 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 9228 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 9229 | return -EINVAL; |
| 9230 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9231 | if (wdev->ap_unexpected_nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9232 | return -EBUSY; |
| 9233 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9234 | wdev->ap_unexpected_nlportid = info->snd_portid; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9235 | return 0; |
| 9236 | } |
| 9237 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9238 | static int nl80211_probe_client(struct sk_buff *skb, |
| 9239 | struct genl_info *info) |
| 9240 | { |
| 9241 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9242 | struct net_device *dev = info->user_ptr[1]; |
| 9243 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9244 | struct sk_buff *msg; |
| 9245 | void *hdr; |
| 9246 | const u8 *addr; |
| 9247 | u64 cookie; |
| 9248 | int err; |
| 9249 | |
| 9250 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 9251 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 9252 | return -EOPNOTSUPP; |
| 9253 | |
| 9254 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 9255 | return -EINVAL; |
| 9256 | |
| 9257 | if (!rdev->ops->probe_client) |
| 9258 | return -EOPNOTSUPP; |
| 9259 | |
| 9260 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 9261 | if (!msg) |
| 9262 | return -ENOMEM; |
| 9263 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9264 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9265 | NL80211_CMD_PROBE_CLIENT); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 9266 | if (!hdr) { |
| 9267 | err = -ENOBUFS; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9268 | goto free_msg; |
| 9269 | } |
| 9270 | |
| 9271 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 9272 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 9273 | err = rdev_probe_client(rdev, dev, addr, &cookie); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9274 | if (err) |
| 9275 | goto free_msg; |
| 9276 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9277 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 9278 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9279 | |
| 9280 | genlmsg_end(msg, hdr); |
| 9281 | |
| 9282 | return genlmsg_reply(msg, info); |
| 9283 | |
| 9284 | nla_put_failure: |
| 9285 | err = -ENOBUFS; |
| 9286 | free_msg: |
| 9287 | nlmsg_free(msg); |
| 9288 | return err; |
| 9289 | } |
| 9290 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9291 | static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) |
| 9292 | { |
| 9293 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9294 | struct cfg80211_beacon_registration *reg, *nreg; |
| 9295 | int rv; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9296 | |
| 9297 | if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) |
| 9298 | return -EOPNOTSUPP; |
| 9299 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9300 | nreg = kzalloc(sizeof(*nreg), GFP_KERNEL); |
| 9301 | if (!nreg) |
| 9302 | return -ENOMEM; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9303 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9304 | /* First, check if already registered. */ |
| 9305 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 9306 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 9307 | if (reg->nlportid == info->snd_portid) { |
| 9308 | rv = -EALREADY; |
| 9309 | goto out_err; |
| 9310 | } |
| 9311 | } |
| 9312 | /* Add it to the list */ |
| 9313 | nreg->nlportid = info->snd_portid; |
| 9314 | list_add(&nreg->list, &rdev->beacon_registrations); |
| 9315 | |
| 9316 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9317 | |
| 9318 | return 0; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9319 | out_err: |
| 9320 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 9321 | kfree(nreg); |
| 9322 | return rv; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9323 | } |
| 9324 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9325 | static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 9326 | { |
| 9327 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9328 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 9329 | int err; |
| 9330 | |
| 9331 | if (!rdev->ops->start_p2p_device) |
| 9332 | return -EOPNOTSUPP; |
| 9333 | |
| 9334 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 9335 | return -EOPNOTSUPP; |
| 9336 | |
| 9337 | if (wdev->p2p_started) |
| 9338 | return 0; |
| 9339 | |
Luciano Coelho | b6a5501 | 2014-02-27 11:07:21 +0200 | [diff] [blame] | 9340 | if (rfkill_blocked(rdev->rfkill)) |
| 9341 | return -ERFKILL; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9342 | |
Johannes Berg | eeb126e | 2012-10-23 15:16:50 +0200 | [diff] [blame] | 9343 | err = rdev_start_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9344 | if (err) |
| 9345 | return err; |
| 9346 | |
| 9347 | wdev->p2p_started = true; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9348 | rdev->opencount++; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9349 | |
| 9350 | return 0; |
| 9351 | } |
| 9352 | |
| 9353 | static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 9354 | { |
| 9355 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9356 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 9357 | |
| 9358 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 9359 | return -EOPNOTSUPP; |
| 9360 | |
| 9361 | if (!rdev->ops->stop_p2p_device) |
| 9362 | return -EOPNOTSUPP; |
| 9363 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 9364 | cfg80211_stop_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9365 | |
| 9366 | return 0; |
| 9367 | } |
| 9368 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 9369 | static int nl80211_get_protocol_features(struct sk_buff *skb, |
| 9370 | struct genl_info *info) |
| 9371 | { |
| 9372 | void *hdr; |
| 9373 | struct sk_buff *msg; |
| 9374 | |
| 9375 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 9376 | if (!msg) |
| 9377 | return -ENOMEM; |
| 9378 | |
| 9379 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 9380 | NL80211_CMD_GET_PROTOCOL_FEATURES); |
| 9381 | if (!hdr) |
| 9382 | goto nla_put_failure; |
| 9383 | |
| 9384 | if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES, |
| 9385 | NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)) |
| 9386 | goto nla_put_failure; |
| 9387 | |
| 9388 | genlmsg_end(msg, hdr); |
| 9389 | return genlmsg_reply(msg, info); |
| 9390 | |
| 9391 | nla_put_failure: |
| 9392 | kfree_skb(msg); |
| 9393 | return -ENOBUFS; |
| 9394 | } |
| 9395 | |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 9396 | static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info) |
| 9397 | { |
| 9398 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9399 | struct cfg80211_update_ft_ies_params ft_params; |
| 9400 | struct net_device *dev = info->user_ptr[1]; |
| 9401 | |
| 9402 | if (!rdev->ops->update_ft_ies) |
| 9403 | return -EOPNOTSUPP; |
| 9404 | |
| 9405 | if (!info->attrs[NL80211_ATTR_MDID] || |
| 9406 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 9407 | return -EINVAL; |
| 9408 | |
| 9409 | memset(&ft_params, 0, sizeof(ft_params)); |
| 9410 | ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]); |
| 9411 | ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 9412 | ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 9413 | |
| 9414 | return rdev_update_ft_ies(rdev, dev, &ft_params); |
| 9415 | } |
| 9416 | |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 9417 | static int nl80211_crit_protocol_start(struct sk_buff *skb, |
| 9418 | struct genl_info *info) |
| 9419 | { |
| 9420 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9421 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 9422 | enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC; |
| 9423 | u16 duration; |
| 9424 | int ret; |
| 9425 | |
| 9426 | if (!rdev->ops->crit_proto_start) |
| 9427 | return -EOPNOTSUPP; |
| 9428 | |
| 9429 | if (WARN_ON(!rdev->ops->crit_proto_stop)) |
| 9430 | return -EINVAL; |
| 9431 | |
| 9432 | if (rdev->crit_proto_nlportid) |
| 9433 | return -EBUSY; |
| 9434 | |
| 9435 | /* determine protocol if provided */ |
| 9436 | if (info->attrs[NL80211_ATTR_CRIT_PROT_ID]) |
| 9437 | proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]); |
| 9438 | |
| 9439 | if (proto >= NUM_NL80211_CRIT_PROTO) |
| 9440 | return -EINVAL; |
| 9441 | |
| 9442 | /* timeout must be provided */ |
| 9443 | if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]) |
| 9444 | return -EINVAL; |
| 9445 | |
| 9446 | duration = |
| 9447 | nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]); |
| 9448 | |
| 9449 | if (duration > NL80211_CRIT_PROTO_MAX_DURATION) |
| 9450 | return -ERANGE; |
| 9451 | |
| 9452 | ret = rdev_crit_proto_start(rdev, wdev, proto, duration); |
| 9453 | if (!ret) |
| 9454 | rdev->crit_proto_nlportid = info->snd_portid; |
| 9455 | |
| 9456 | return ret; |
| 9457 | } |
| 9458 | |
| 9459 | static int nl80211_crit_protocol_stop(struct sk_buff *skb, |
| 9460 | struct genl_info *info) |
| 9461 | { |
| 9462 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9463 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 9464 | |
| 9465 | if (!rdev->ops->crit_proto_stop) |
| 9466 | return -EOPNOTSUPP; |
| 9467 | |
| 9468 | if (rdev->crit_proto_nlportid) { |
| 9469 | rdev->crit_proto_nlportid = 0; |
| 9470 | rdev_crit_proto_stop(rdev, wdev); |
| 9471 | } |
| 9472 | return 0; |
| 9473 | } |
| 9474 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 9475 | static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info) |
| 9476 | { |
| 9477 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9478 | struct wireless_dev *wdev = |
| 9479 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); |
| 9480 | int i, err; |
| 9481 | u32 vid, subcmd; |
| 9482 | |
| 9483 | if (!rdev->wiphy.vendor_commands) |
| 9484 | return -EOPNOTSUPP; |
| 9485 | |
| 9486 | if (IS_ERR(wdev)) { |
| 9487 | err = PTR_ERR(wdev); |
| 9488 | if (err != -EINVAL) |
| 9489 | return err; |
| 9490 | wdev = NULL; |
| 9491 | } else if (wdev->wiphy != &rdev->wiphy) { |
| 9492 | return -EINVAL; |
| 9493 | } |
| 9494 | |
| 9495 | if (!info->attrs[NL80211_ATTR_VENDOR_ID] || |
| 9496 | !info->attrs[NL80211_ATTR_VENDOR_SUBCMD]) |
| 9497 | return -EINVAL; |
| 9498 | |
| 9499 | vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]); |
| 9500 | subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]); |
| 9501 | for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { |
| 9502 | const struct wiphy_vendor_command *vcmd; |
| 9503 | void *data = NULL; |
| 9504 | int len = 0; |
| 9505 | |
| 9506 | vcmd = &rdev->wiphy.vendor_commands[i]; |
| 9507 | |
| 9508 | if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd) |
| 9509 | continue; |
| 9510 | |
| 9511 | if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV | |
| 9512 | WIPHY_VENDOR_CMD_NEED_NETDEV)) { |
| 9513 | if (!wdev) |
| 9514 | return -EINVAL; |
| 9515 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV && |
| 9516 | !wdev->netdev) |
| 9517 | return -EINVAL; |
| 9518 | |
| 9519 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) { |
| 9520 | if (wdev->netdev && |
| 9521 | !netif_running(wdev->netdev)) |
| 9522 | return -ENETDOWN; |
| 9523 | if (!wdev->netdev && !wdev->p2p_started) |
| 9524 | return -ENETDOWN; |
| 9525 | } |
| 9526 | } else { |
| 9527 | wdev = NULL; |
| 9528 | } |
| 9529 | |
| 9530 | if (info->attrs[NL80211_ATTR_VENDOR_DATA]) { |
| 9531 | data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]); |
| 9532 | len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]); |
| 9533 | } |
| 9534 | |
| 9535 | rdev->cur_cmd_info = info; |
| 9536 | err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev, |
| 9537 | data, len); |
| 9538 | rdev->cur_cmd_info = NULL; |
| 9539 | return err; |
| 9540 | } |
| 9541 | |
| 9542 | return -EOPNOTSUPP; |
| 9543 | } |
| 9544 | |
| 9545 | struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy, |
| 9546 | enum nl80211_commands cmd, |
| 9547 | enum nl80211_attrs attr, |
| 9548 | int approxlen) |
| 9549 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 9550 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 9551 | |
| 9552 | if (WARN_ON(!rdev->cur_cmd_info)) |
| 9553 | return NULL; |
| 9554 | |
| 9555 | return __cfg80211_alloc_vendor_skb(rdev, approxlen, |
| 9556 | rdev->cur_cmd_info->snd_portid, |
| 9557 | rdev->cur_cmd_info->snd_seq, |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 9558 | cmd, attr, NULL, GFP_KERNEL); |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 9559 | } |
| 9560 | EXPORT_SYMBOL(__cfg80211_alloc_reply_skb); |
| 9561 | |
| 9562 | int cfg80211_vendor_cmd_reply(struct sk_buff *skb) |
| 9563 | { |
| 9564 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 9565 | void *hdr = ((void **)skb->cb)[1]; |
| 9566 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 9567 | |
Johannes Berg | bd8c78e | 2014-07-30 14:55:26 +0200 | [diff] [blame] | 9568 | /* clear CB data for netlink core to own from now on */ |
| 9569 | memset(skb->cb, 0, sizeof(skb->cb)); |
| 9570 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 9571 | if (WARN_ON(!rdev->cur_cmd_info)) { |
| 9572 | kfree_skb(skb); |
| 9573 | return -EINVAL; |
| 9574 | } |
| 9575 | |
| 9576 | nla_nest_end(skb, data); |
| 9577 | genlmsg_end(skb, hdr); |
| 9578 | return genlmsg_reply(skb, rdev->cur_cmd_info); |
| 9579 | } |
| 9580 | EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply); |
| 9581 | |
| 9582 | |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 9583 | static int nl80211_set_qos_map(struct sk_buff *skb, |
| 9584 | struct genl_info *info) |
| 9585 | { |
| 9586 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9587 | struct cfg80211_qos_map *qos_map = NULL; |
| 9588 | struct net_device *dev = info->user_ptr[1]; |
| 9589 | u8 *pos, len, num_des, des_len, des; |
| 9590 | int ret; |
| 9591 | |
| 9592 | if (!rdev->ops->set_qos_map) |
| 9593 | return -EOPNOTSUPP; |
| 9594 | |
| 9595 | if (info->attrs[NL80211_ATTR_QOS_MAP]) { |
| 9596 | pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]); |
| 9597 | len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]); |
| 9598 | |
| 9599 | if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN || |
| 9600 | len > IEEE80211_QOS_MAP_LEN_MAX) |
| 9601 | return -EINVAL; |
| 9602 | |
| 9603 | qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL); |
| 9604 | if (!qos_map) |
| 9605 | return -ENOMEM; |
| 9606 | |
| 9607 | num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1; |
| 9608 | if (num_des) { |
| 9609 | des_len = num_des * |
| 9610 | sizeof(struct cfg80211_dscp_exception); |
| 9611 | memcpy(qos_map->dscp_exception, pos, des_len); |
| 9612 | qos_map->num_des = num_des; |
| 9613 | for (des = 0; des < num_des; des++) { |
| 9614 | if (qos_map->dscp_exception[des].up > 7) { |
| 9615 | kfree(qos_map); |
| 9616 | return -EINVAL; |
| 9617 | } |
| 9618 | } |
| 9619 | pos += des_len; |
| 9620 | } |
| 9621 | memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN); |
| 9622 | } |
| 9623 | |
| 9624 | wdev_lock(dev->ieee80211_ptr); |
| 9625 | ret = nl80211_key_allowed(dev->ieee80211_ptr); |
| 9626 | if (!ret) |
| 9627 | ret = rdev_set_qos_map(rdev, dev, qos_map); |
| 9628 | wdev_unlock(dev->ieee80211_ptr); |
| 9629 | |
| 9630 | kfree(qos_map); |
| 9631 | return ret; |
| 9632 | } |
| 9633 | |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 9634 | static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info) |
| 9635 | { |
| 9636 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9637 | struct net_device *dev = info->user_ptr[1]; |
| 9638 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9639 | const u8 *peer; |
| 9640 | u8 tsid, up; |
| 9641 | u16 admitted_time = 0; |
| 9642 | int err; |
| 9643 | |
Johannes Berg | 723e73a | 2014-10-22 09:25:06 +0200 | [diff] [blame] | 9644 | if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)) |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 9645 | return -EOPNOTSUPP; |
| 9646 | |
| 9647 | if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] || |
| 9648 | !info->attrs[NL80211_ATTR_USER_PRIO]) |
| 9649 | return -EINVAL; |
| 9650 | |
| 9651 | tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]); |
| 9652 | if (tsid >= IEEE80211_NUM_TIDS) |
| 9653 | return -EINVAL; |
| 9654 | |
| 9655 | up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]); |
| 9656 | if (up >= IEEE80211_NUM_UPS) |
| 9657 | return -EINVAL; |
| 9658 | |
| 9659 | /* WMM uses TIDs 0-7 even for TSPEC */ |
Johannes Berg | 723e73a | 2014-10-22 09:25:06 +0200 | [diff] [blame] | 9660 | if (tsid >= IEEE80211_FIRST_TSPEC_TSID) { |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 9661 | /* TODO: handle 802.11 TSPEC/admission control |
Johannes Berg | 723e73a | 2014-10-22 09:25:06 +0200 | [diff] [blame] | 9662 | * need more attributes for that (e.g. BA session requirement); |
| 9663 | * change the WMM adminssion test above to allow both then |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 9664 | */ |
| 9665 | return -EINVAL; |
| 9666 | } |
| 9667 | |
| 9668 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 9669 | |
| 9670 | if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) { |
| 9671 | admitted_time = |
| 9672 | nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]); |
| 9673 | if (!admitted_time) |
| 9674 | return -EINVAL; |
| 9675 | } |
| 9676 | |
| 9677 | wdev_lock(wdev); |
| 9678 | switch (wdev->iftype) { |
| 9679 | case NL80211_IFTYPE_STATION: |
| 9680 | case NL80211_IFTYPE_P2P_CLIENT: |
| 9681 | if (wdev->current_bss) |
| 9682 | break; |
| 9683 | err = -ENOTCONN; |
| 9684 | goto out; |
| 9685 | default: |
| 9686 | err = -EOPNOTSUPP; |
| 9687 | goto out; |
| 9688 | } |
| 9689 | |
| 9690 | err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time); |
| 9691 | |
| 9692 | out: |
| 9693 | wdev_unlock(wdev); |
| 9694 | return err; |
| 9695 | } |
| 9696 | |
| 9697 | static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info) |
| 9698 | { |
| 9699 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9700 | struct net_device *dev = info->user_ptr[1]; |
| 9701 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9702 | const u8 *peer; |
| 9703 | u8 tsid; |
| 9704 | int err; |
| 9705 | |
| 9706 | if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC]) |
| 9707 | return -EINVAL; |
| 9708 | |
| 9709 | tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]); |
| 9710 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 9711 | |
| 9712 | wdev_lock(wdev); |
| 9713 | err = rdev_del_tx_ts(rdev, dev, tsid, peer); |
| 9714 | wdev_unlock(wdev); |
| 9715 | |
| 9716 | return err; |
| 9717 | } |
| 9718 | |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 9719 | static int nl80211_tdls_channel_switch(struct sk_buff *skb, |
| 9720 | struct genl_info *info) |
| 9721 | { |
| 9722 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9723 | struct net_device *dev = info->user_ptr[1]; |
| 9724 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9725 | struct cfg80211_chan_def chandef = {}; |
| 9726 | const u8 *addr; |
| 9727 | u8 oper_class; |
| 9728 | int err; |
| 9729 | |
| 9730 | if (!rdev->ops->tdls_channel_switch || |
| 9731 | !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH)) |
| 9732 | return -EOPNOTSUPP; |
| 9733 | |
| 9734 | switch (dev->ieee80211_ptr->iftype) { |
| 9735 | case NL80211_IFTYPE_STATION: |
| 9736 | case NL80211_IFTYPE_P2P_CLIENT: |
| 9737 | break; |
| 9738 | default: |
| 9739 | return -EOPNOTSUPP; |
| 9740 | } |
| 9741 | |
| 9742 | if (!info->attrs[NL80211_ATTR_MAC] || |
| 9743 | !info->attrs[NL80211_ATTR_OPER_CLASS]) |
| 9744 | return -EINVAL; |
| 9745 | |
| 9746 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 9747 | if (err) |
| 9748 | return err; |
| 9749 | |
| 9750 | /* |
| 9751 | * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012 |
| 9752 | * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the |
| 9753 | * specification is not defined for them. |
| 9754 | */ |
| 9755 | if (chandef.chan->band == IEEE80211_BAND_2GHZ && |
| 9756 | chandef.width != NL80211_CHAN_WIDTH_20_NOHT && |
| 9757 | chandef.width != NL80211_CHAN_WIDTH_20) |
| 9758 | return -EINVAL; |
| 9759 | |
| 9760 | /* we will be active on the TDLS link */ |
| 9761 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef, wdev->iftype)) |
| 9762 | return -EINVAL; |
| 9763 | |
| 9764 | /* don't allow switching to DFS channels */ |
| 9765 | if (cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, wdev->iftype)) |
| 9766 | return -EINVAL; |
| 9767 | |
| 9768 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 9769 | oper_class = nla_get_u8(info->attrs[NL80211_ATTR_OPER_CLASS]); |
| 9770 | |
| 9771 | wdev_lock(wdev); |
| 9772 | err = rdev_tdls_channel_switch(rdev, dev, addr, oper_class, &chandef); |
| 9773 | wdev_unlock(wdev); |
| 9774 | |
| 9775 | return err; |
| 9776 | } |
| 9777 | |
| 9778 | static int nl80211_tdls_cancel_channel_switch(struct sk_buff *skb, |
| 9779 | struct genl_info *info) |
| 9780 | { |
| 9781 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9782 | struct net_device *dev = info->user_ptr[1]; |
| 9783 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9784 | const u8 *addr; |
| 9785 | |
| 9786 | if (!rdev->ops->tdls_channel_switch || |
| 9787 | !rdev->ops->tdls_cancel_channel_switch || |
| 9788 | !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH)) |
| 9789 | return -EOPNOTSUPP; |
| 9790 | |
| 9791 | switch (dev->ieee80211_ptr->iftype) { |
| 9792 | case NL80211_IFTYPE_STATION: |
| 9793 | case NL80211_IFTYPE_P2P_CLIENT: |
| 9794 | break; |
| 9795 | default: |
| 9796 | return -EOPNOTSUPP; |
| 9797 | } |
| 9798 | |
| 9799 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 9800 | return -EINVAL; |
| 9801 | |
| 9802 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 9803 | |
| 9804 | wdev_lock(wdev); |
| 9805 | rdev_tdls_cancel_channel_switch(rdev, dev, addr); |
| 9806 | wdev_unlock(wdev); |
| 9807 | |
| 9808 | return 0; |
| 9809 | } |
| 9810 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9811 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
| 9812 | #define NL80211_FLAG_NEED_NETDEV 0x02 |
| 9813 | #define NL80211_FLAG_NEED_RTNL 0x04 |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9814 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
| 9815 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ |
| 9816 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 9817 | #define NL80211_FLAG_NEED_WDEV 0x10 |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9818 | /* 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] | 9819 | #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\ |
| 9820 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 9821 | #define NL80211_FLAG_CLEAR_SKB 0x20 |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9822 | |
Johannes Berg | f84f771 | 2013-11-14 17:14:45 +0100 | [diff] [blame] | 9823 | 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] | 9824 | struct genl_info *info) |
| 9825 | { |
| 9826 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 9827 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9828 | struct net_device *dev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9829 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
| 9830 | |
| 9831 | if (rtnl) |
| 9832 | rtnl_lock(); |
| 9833 | |
| 9834 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 9835 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9836 | if (IS_ERR(rdev)) { |
| 9837 | if (rtnl) |
| 9838 | rtnl_unlock(); |
| 9839 | return PTR_ERR(rdev); |
| 9840 | } |
| 9841 | info->user_ptr[0] = rdev; |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 9842 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV || |
| 9843 | ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 9844 | ASSERT_RTNL(); |
| 9845 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 9846 | wdev = __cfg80211_wdev_from_attrs(genl_info_net(info), |
| 9847 | info->attrs); |
| 9848 | if (IS_ERR(wdev)) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9849 | if (rtnl) |
| 9850 | rtnl_unlock(); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 9851 | return PTR_ERR(wdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9852 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 9853 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 9854 | dev = wdev->netdev; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 9855 | rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 9856 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 9857 | if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
| 9858 | if (!dev) { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 9859 | if (rtnl) |
| 9860 | rtnl_unlock(); |
| 9861 | return -EINVAL; |
| 9862 | } |
| 9863 | |
| 9864 | info->user_ptr[1] = dev; |
| 9865 | } else { |
| 9866 | info->user_ptr[1] = wdev; |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9867 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 9868 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 9869 | if (dev) { |
| 9870 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && |
| 9871 | !netif_running(dev)) { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 9872 | if (rtnl) |
| 9873 | rtnl_unlock(); |
| 9874 | return -ENETDOWN; |
| 9875 | } |
| 9876 | |
| 9877 | dev_hold(dev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9878 | } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) { |
| 9879 | if (!wdev->p2p_started) { |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9880 | if (rtnl) |
| 9881 | rtnl_unlock(); |
| 9882 | return -ENETDOWN; |
| 9883 | } |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 9884 | } |
| 9885 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9886 | info->user_ptr[0] = rdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9887 | } |
| 9888 | |
| 9889 | return 0; |
| 9890 | } |
| 9891 | |
Johannes Berg | f84f771 | 2013-11-14 17:14:45 +0100 | [diff] [blame] | 9892 | 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] | 9893 | struct genl_info *info) |
| 9894 | { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 9895 | if (info->user_ptr[1]) { |
| 9896 | if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
| 9897 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 9898 | |
| 9899 | if (wdev->netdev) |
| 9900 | dev_put(wdev->netdev); |
| 9901 | } else { |
| 9902 | dev_put(info->user_ptr[1]); |
| 9903 | } |
| 9904 | } |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 9905 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9906 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
| 9907 | rtnl_unlock(); |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 9908 | |
| 9909 | /* If needed, clear the netlink message payload from the SKB |
| 9910 | * as it might contain key data that shouldn't stick around on |
| 9911 | * the heap after the SKB is freed. The netlink message header |
| 9912 | * is still needed for further processing, so leave it intact. |
| 9913 | */ |
| 9914 | if (ops->internal_flags & NL80211_FLAG_CLEAR_SKB) { |
| 9915 | struct nlmsghdr *nlh = nlmsg_hdr(skb); |
| 9916 | |
| 9917 | memset(nlmsg_data(nlh), 0, nlmsg_len(nlh)); |
| 9918 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9919 | } |
| 9920 | |
Johannes Berg | 4534de8 | 2013-11-14 17:14:46 +0100 | [diff] [blame] | 9921 | static const struct genl_ops nl80211_ops[] = { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9922 | { |
| 9923 | .cmd = NL80211_CMD_GET_WIPHY, |
| 9924 | .doit = nl80211_get_wiphy, |
| 9925 | .dumpit = nl80211_dump_wiphy, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 9926 | .done = nl80211_dump_wiphy_done, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9927 | .policy = nl80211_policy, |
| 9928 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 9929 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9930 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9931 | }, |
| 9932 | { |
| 9933 | .cmd = NL80211_CMD_SET_WIPHY, |
| 9934 | .doit = nl80211_set_wiphy, |
| 9935 | .policy = nl80211_policy, |
| 9936 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9937 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9938 | }, |
| 9939 | { |
| 9940 | .cmd = NL80211_CMD_GET_INTERFACE, |
| 9941 | .doit = nl80211_get_interface, |
| 9942 | .dumpit = nl80211_dump_interface, |
| 9943 | .policy = nl80211_policy, |
| 9944 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 9945 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 9946 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9947 | }, |
| 9948 | { |
| 9949 | .cmd = NL80211_CMD_SET_INTERFACE, |
| 9950 | .doit = nl80211_set_interface, |
| 9951 | .policy = nl80211_policy, |
| 9952 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9953 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9954 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9955 | }, |
| 9956 | { |
| 9957 | .cmd = NL80211_CMD_NEW_INTERFACE, |
| 9958 | .doit = nl80211_new_interface, |
| 9959 | .policy = nl80211_policy, |
| 9960 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9961 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9962 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9963 | }, |
| 9964 | { |
| 9965 | .cmd = NL80211_CMD_DEL_INTERFACE, |
| 9966 | .doit = nl80211_del_interface, |
| 9967 | .policy = nl80211_policy, |
| 9968 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 9969 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9970 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9971 | }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 9972 | { |
| 9973 | .cmd = NL80211_CMD_GET_KEY, |
| 9974 | .doit = nl80211_get_key, |
| 9975 | .policy = nl80211_policy, |
| 9976 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9977 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9978 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 9979 | }, |
| 9980 | { |
| 9981 | .cmd = NL80211_CMD_SET_KEY, |
| 9982 | .doit = nl80211_set_key, |
| 9983 | .policy = nl80211_policy, |
| 9984 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9985 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 9986 | NL80211_FLAG_NEED_RTNL | |
| 9987 | NL80211_FLAG_CLEAR_SKB, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 9988 | }, |
| 9989 | { |
| 9990 | .cmd = NL80211_CMD_NEW_KEY, |
| 9991 | .doit = nl80211_new_key, |
| 9992 | .policy = nl80211_policy, |
| 9993 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9994 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 9995 | NL80211_FLAG_NEED_RTNL | |
| 9996 | NL80211_FLAG_CLEAR_SKB, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 9997 | }, |
| 9998 | { |
| 9999 | .cmd = NL80211_CMD_DEL_KEY, |
| 10000 | .doit = nl80211_del_key, |
| 10001 | .policy = nl80211_policy, |
| 10002 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10003 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10004 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 10005 | }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 10006 | { |
| 10007 | .cmd = NL80211_CMD_SET_BEACON, |
| 10008 | .policy = nl80211_policy, |
| 10009 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 10010 | .doit = nl80211_set_beacon, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 10011 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10012 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 10013 | }, |
| 10014 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 10015 | .cmd = NL80211_CMD_START_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 10016 | .policy = nl80211_policy, |
| 10017 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 10018 | .doit = nl80211_start_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 10019 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10020 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 10021 | }, |
| 10022 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 10023 | .cmd = NL80211_CMD_STOP_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 10024 | .policy = nl80211_policy, |
| 10025 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 10026 | .doit = nl80211_stop_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 10027 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10028 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 10029 | }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 10030 | { |
| 10031 | .cmd = NL80211_CMD_GET_STATION, |
| 10032 | .doit = nl80211_get_station, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 10033 | .dumpit = nl80211_dump_station, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 10034 | .policy = nl80211_policy, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10035 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 10036 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 10037 | }, |
| 10038 | { |
| 10039 | .cmd = NL80211_CMD_SET_STATION, |
| 10040 | .doit = nl80211_set_station, |
| 10041 | .policy = nl80211_policy, |
| 10042 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 10043 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10044 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 10045 | }, |
| 10046 | { |
| 10047 | .cmd = NL80211_CMD_NEW_STATION, |
| 10048 | .doit = nl80211_new_station, |
| 10049 | .policy = nl80211_policy, |
| 10050 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10051 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10052 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 10053 | }, |
| 10054 | { |
| 10055 | .cmd = NL80211_CMD_DEL_STATION, |
| 10056 | .doit = nl80211_del_station, |
| 10057 | .policy = nl80211_policy, |
| 10058 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 10059 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10060 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 10061 | }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 10062 | { |
| 10063 | .cmd = NL80211_CMD_GET_MPATH, |
| 10064 | .doit = nl80211_get_mpath, |
| 10065 | .dumpit = nl80211_dump_mpath, |
| 10066 | .policy = nl80211_policy, |
| 10067 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10068 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10069 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 10070 | }, |
| 10071 | { |
Henning Rogge | 66be7d2 | 2014-09-12 08:58:49 +0200 | [diff] [blame] | 10072 | .cmd = NL80211_CMD_GET_MPP, |
| 10073 | .doit = nl80211_get_mpp, |
| 10074 | .dumpit = nl80211_dump_mpp, |
| 10075 | .policy = nl80211_policy, |
| 10076 | .flags = GENL_ADMIN_PERM, |
| 10077 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10078 | NL80211_FLAG_NEED_RTNL, |
| 10079 | }, |
| 10080 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 10081 | .cmd = NL80211_CMD_SET_MPATH, |
| 10082 | .doit = nl80211_set_mpath, |
| 10083 | .policy = nl80211_policy, |
| 10084 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10085 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10086 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 10087 | }, |
| 10088 | { |
| 10089 | .cmd = NL80211_CMD_NEW_MPATH, |
| 10090 | .doit = nl80211_new_mpath, |
| 10091 | .policy = nl80211_policy, |
| 10092 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10093 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10094 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 10095 | }, |
| 10096 | { |
| 10097 | .cmd = NL80211_CMD_DEL_MPATH, |
| 10098 | .doit = nl80211_del_mpath, |
| 10099 | .policy = nl80211_policy, |
| 10100 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 10101 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10102 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 10103 | }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 10104 | { |
| 10105 | .cmd = NL80211_CMD_SET_BSS, |
| 10106 | .doit = nl80211_set_bss, |
| 10107 | .policy = nl80211_policy, |
| 10108 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 10109 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10110 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 10111 | }, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 10112 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 10113 | .cmd = NL80211_CMD_GET_REG, |
| 10114 | .doit = nl80211_get_reg, |
| 10115 | .policy = nl80211_policy, |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 10116 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 10117 | /* can be retrieved by unprivileged users */ |
| 10118 | }, |
| 10119 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 10120 | .cmd = NL80211_CMD_SET_REG, |
| 10121 | .doit = nl80211_set_reg, |
| 10122 | .policy = nl80211_policy, |
| 10123 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 10124 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 10125 | }, |
| 10126 | { |
| 10127 | .cmd = NL80211_CMD_REQ_SET_REG, |
| 10128 | .doit = nl80211_req_set_reg, |
| 10129 | .policy = nl80211_policy, |
| 10130 | .flags = GENL_ADMIN_PERM, |
| 10131 | }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 10132 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 10133 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
| 10134 | .doit = nl80211_get_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 10135 | .policy = nl80211_policy, |
| 10136 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 10137 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10138 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 10139 | }, |
| 10140 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 10141 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
| 10142 | .doit = nl80211_update_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 10143 | .policy = nl80211_policy, |
| 10144 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 10145 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10146 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 10147 | }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 10148 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10149 | .cmd = NL80211_CMD_TRIGGER_SCAN, |
| 10150 | .doit = nl80211_trigger_scan, |
| 10151 | .policy = nl80211_policy, |
| 10152 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 10153 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10154 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10155 | }, |
| 10156 | { |
| 10157 | .cmd = NL80211_CMD_GET_SCAN, |
| 10158 | .policy = nl80211_policy, |
| 10159 | .dumpit = nl80211_dump_scan, |
| 10160 | }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 10161 | { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 10162 | .cmd = NL80211_CMD_START_SCHED_SCAN, |
| 10163 | .doit = nl80211_start_sched_scan, |
| 10164 | .policy = nl80211_policy, |
| 10165 | .flags = GENL_ADMIN_PERM, |
| 10166 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10167 | NL80211_FLAG_NEED_RTNL, |
| 10168 | }, |
| 10169 | { |
| 10170 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, |
| 10171 | .doit = nl80211_stop_sched_scan, |
| 10172 | .policy = nl80211_policy, |
| 10173 | .flags = GENL_ADMIN_PERM, |
| 10174 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10175 | NL80211_FLAG_NEED_RTNL, |
| 10176 | }, |
| 10177 | { |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 10178 | .cmd = NL80211_CMD_AUTHENTICATE, |
| 10179 | .doit = nl80211_authenticate, |
| 10180 | .policy = nl80211_policy, |
| 10181 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10182 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 10183 | NL80211_FLAG_NEED_RTNL | |
| 10184 | NL80211_FLAG_CLEAR_SKB, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 10185 | }, |
| 10186 | { |
| 10187 | .cmd = NL80211_CMD_ASSOCIATE, |
| 10188 | .doit = nl80211_associate, |
| 10189 | .policy = nl80211_policy, |
| 10190 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10191 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10192 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 10193 | }, |
| 10194 | { |
| 10195 | .cmd = NL80211_CMD_DEAUTHENTICATE, |
| 10196 | .doit = nl80211_deauthenticate, |
| 10197 | .policy = nl80211_policy, |
| 10198 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10199 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10200 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 10201 | }, |
| 10202 | { |
| 10203 | .cmd = NL80211_CMD_DISASSOCIATE, |
| 10204 | .doit = nl80211_disassociate, |
| 10205 | .policy = nl80211_policy, |
| 10206 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10207 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10208 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 10209 | }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10210 | { |
| 10211 | .cmd = NL80211_CMD_JOIN_IBSS, |
| 10212 | .doit = nl80211_join_ibss, |
| 10213 | .policy = nl80211_policy, |
| 10214 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10215 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10216 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10217 | }, |
| 10218 | { |
| 10219 | .cmd = NL80211_CMD_LEAVE_IBSS, |
| 10220 | .doit = nl80211_leave_ibss, |
| 10221 | .policy = nl80211_policy, |
| 10222 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10223 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10224 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10225 | }, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 10226 | #ifdef CONFIG_NL80211_TESTMODE |
| 10227 | { |
| 10228 | .cmd = NL80211_CMD_TESTMODE, |
| 10229 | .doit = nl80211_testmode_do, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 10230 | .dumpit = nl80211_testmode_dump, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 10231 | .policy = nl80211_policy, |
| 10232 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10233 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 10234 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 10235 | }, |
| 10236 | #endif |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10237 | { |
| 10238 | .cmd = NL80211_CMD_CONNECT, |
| 10239 | .doit = nl80211_connect, |
| 10240 | .policy = nl80211_policy, |
| 10241 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10242 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10243 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10244 | }, |
| 10245 | { |
| 10246 | .cmd = NL80211_CMD_DISCONNECT, |
| 10247 | .doit = nl80211_disconnect, |
| 10248 | .policy = nl80211_policy, |
| 10249 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10250 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10251 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10252 | }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 10253 | { |
| 10254 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, |
| 10255 | .doit = nl80211_wiphy_netns, |
| 10256 | .policy = nl80211_policy, |
| 10257 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10258 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 10259 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 10260 | }, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 10261 | { |
| 10262 | .cmd = NL80211_CMD_GET_SURVEY, |
| 10263 | .policy = nl80211_policy, |
| 10264 | .dumpit = nl80211_dump_survey, |
| 10265 | }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 10266 | { |
| 10267 | .cmd = NL80211_CMD_SET_PMKSA, |
| 10268 | .doit = nl80211_setdel_pmksa, |
| 10269 | .policy = nl80211_policy, |
| 10270 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 10271 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10272 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 10273 | }, |
| 10274 | { |
| 10275 | .cmd = NL80211_CMD_DEL_PMKSA, |
| 10276 | .doit = nl80211_setdel_pmksa, |
| 10277 | .policy = nl80211_policy, |
| 10278 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 10279 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10280 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 10281 | }, |
| 10282 | { |
| 10283 | .cmd = NL80211_CMD_FLUSH_PMKSA, |
| 10284 | .doit = nl80211_flush_pmksa, |
| 10285 | .policy = nl80211_policy, |
| 10286 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 10287 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10288 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 10289 | }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10290 | { |
| 10291 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, |
| 10292 | .doit = nl80211_remain_on_channel, |
| 10293 | .policy = nl80211_policy, |
| 10294 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10295 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10296 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10297 | }, |
| 10298 | { |
| 10299 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
| 10300 | .doit = nl80211_cancel_remain_on_channel, |
| 10301 | .policy = nl80211_policy, |
| 10302 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10303 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10304 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10305 | }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 10306 | { |
| 10307 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, |
| 10308 | .doit = nl80211_set_tx_bitrate_mask, |
| 10309 | .policy = nl80211_policy, |
| 10310 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10311 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 10312 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 10313 | }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10314 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 10315 | .cmd = NL80211_CMD_REGISTER_FRAME, |
| 10316 | .doit = nl80211_register_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10317 | .policy = nl80211_policy, |
| 10318 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10319 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10320 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10321 | }, |
| 10322 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 10323 | .cmd = NL80211_CMD_FRAME, |
| 10324 | .doit = nl80211_tx_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10325 | .policy = nl80211_policy, |
| 10326 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10327 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10328 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10329 | }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 10330 | { |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 10331 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, |
| 10332 | .doit = nl80211_tx_mgmt_cancel_wait, |
| 10333 | .policy = nl80211_policy, |
| 10334 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10335 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 10336 | NL80211_FLAG_NEED_RTNL, |
| 10337 | }, |
| 10338 | { |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 10339 | .cmd = NL80211_CMD_SET_POWER_SAVE, |
| 10340 | .doit = nl80211_set_power_save, |
| 10341 | .policy = nl80211_policy, |
| 10342 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10343 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 10344 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 10345 | }, |
| 10346 | { |
| 10347 | .cmd = NL80211_CMD_GET_POWER_SAVE, |
| 10348 | .doit = nl80211_get_power_save, |
| 10349 | .policy = nl80211_policy, |
| 10350 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10351 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 10352 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 10353 | }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10354 | { |
| 10355 | .cmd = NL80211_CMD_SET_CQM, |
| 10356 | .doit = nl80211_set_cqm, |
| 10357 | .policy = nl80211_policy, |
| 10358 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10359 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 10360 | NL80211_FLAG_NEED_RTNL, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10361 | }, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 10362 | { |
| 10363 | .cmd = NL80211_CMD_SET_CHANNEL, |
| 10364 | .doit = nl80211_set_channel, |
| 10365 | .policy = nl80211_policy, |
| 10366 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10367 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 10368 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 10369 | }, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 10370 | { |
| 10371 | .cmd = NL80211_CMD_SET_WDS_PEER, |
| 10372 | .doit = nl80211_set_wds_peer, |
| 10373 | .policy = nl80211_policy, |
| 10374 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 10375 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 10376 | NL80211_FLAG_NEED_RTNL, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 10377 | }, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 10378 | { |
| 10379 | .cmd = NL80211_CMD_JOIN_MESH, |
| 10380 | .doit = nl80211_join_mesh, |
| 10381 | .policy = nl80211_policy, |
| 10382 | .flags = GENL_ADMIN_PERM, |
| 10383 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10384 | NL80211_FLAG_NEED_RTNL, |
| 10385 | }, |
| 10386 | { |
| 10387 | .cmd = NL80211_CMD_LEAVE_MESH, |
| 10388 | .doit = nl80211_leave_mesh, |
| 10389 | .policy = nl80211_policy, |
| 10390 | .flags = GENL_ADMIN_PERM, |
| 10391 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10392 | NL80211_FLAG_NEED_RTNL, |
| 10393 | }, |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 10394 | { |
| 10395 | .cmd = NL80211_CMD_JOIN_OCB, |
| 10396 | .doit = nl80211_join_ocb, |
| 10397 | .policy = nl80211_policy, |
| 10398 | .flags = GENL_ADMIN_PERM, |
| 10399 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10400 | NL80211_FLAG_NEED_RTNL, |
| 10401 | }, |
| 10402 | { |
| 10403 | .cmd = NL80211_CMD_LEAVE_OCB, |
| 10404 | .doit = nl80211_leave_ocb, |
| 10405 | .policy = nl80211_policy, |
| 10406 | .flags = GENL_ADMIN_PERM, |
| 10407 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10408 | NL80211_FLAG_NEED_RTNL, |
| 10409 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 10410 | #ifdef CONFIG_PM |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10411 | { |
| 10412 | .cmd = NL80211_CMD_GET_WOWLAN, |
| 10413 | .doit = nl80211_get_wowlan, |
| 10414 | .policy = nl80211_policy, |
| 10415 | /* can be retrieved by unprivileged users */ |
| 10416 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 10417 | NL80211_FLAG_NEED_RTNL, |
| 10418 | }, |
| 10419 | { |
| 10420 | .cmd = NL80211_CMD_SET_WOWLAN, |
| 10421 | .doit = nl80211_set_wowlan, |
| 10422 | .policy = nl80211_policy, |
| 10423 | .flags = GENL_ADMIN_PERM, |
| 10424 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 10425 | NL80211_FLAG_NEED_RTNL, |
| 10426 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 10427 | #endif |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10428 | { |
| 10429 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, |
| 10430 | .doit = nl80211_set_rekey_data, |
| 10431 | .policy = nl80211_policy, |
| 10432 | .flags = GENL_ADMIN_PERM, |
| 10433 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 10434 | NL80211_FLAG_NEED_RTNL | |
| 10435 | NL80211_FLAG_CLEAR_SKB, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10436 | }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 10437 | { |
| 10438 | .cmd = NL80211_CMD_TDLS_MGMT, |
| 10439 | .doit = nl80211_tdls_mgmt, |
| 10440 | .policy = nl80211_policy, |
| 10441 | .flags = GENL_ADMIN_PERM, |
| 10442 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10443 | NL80211_FLAG_NEED_RTNL, |
| 10444 | }, |
| 10445 | { |
| 10446 | .cmd = NL80211_CMD_TDLS_OPER, |
| 10447 | .doit = nl80211_tdls_oper, |
| 10448 | .policy = nl80211_policy, |
| 10449 | .flags = GENL_ADMIN_PERM, |
| 10450 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10451 | NL80211_FLAG_NEED_RTNL, |
| 10452 | }, |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10453 | { |
| 10454 | .cmd = NL80211_CMD_UNEXPECTED_FRAME, |
| 10455 | .doit = nl80211_register_unexpected_frame, |
| 10456 | .policy = nl80211_policy, |
| 10457 | .flags = GENL_ADMIN_PERM, |
| 10458 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 10459 | NL80211_FLAG_NEED_RTNL, |
| 10460 | }, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 10461 | { |
| 10462 | .cmd = NL80211_CMD_PROBE_CLIENT, |
| 10463 | .doit = nl80211_probe_client, |
| 10464 | .policy = nl80211_policy, |
| 10465 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 10466 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 10467 | NL80211_FLAG_NEED_RTNL, |
| 10468 | }, |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10469 | { |
| 10470 | .cmd = NL80211_CMD_REGISTER_BEACONS, |
| 10471 | .doit = nl80211_register_beacons, |
| 10472 | .policy = nl80211_policy, |
| 10473 | .flags = GENL_ADMIN_PERM, |
| 10474 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 10475 | NL80211_FLAG_NEED_RTNL, |
| 10476 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 10477 | { |
| 10478 | .cmd = NL80211_CMD_SET_NOACK_MAP, |
| 10479 | .doit = nl80211_set_noack_map, |
| 10480 | .policy = nl80211_policy, |
| 10481 | .flags = GENL_ADMIN_PERM, |
| 10482 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 10483 | NL80211_FLAG_NEED_RTNL, |
| 10484 | }, |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 10485 | { |
| 10486 | .cmd = NL80211_CMD_START_P2P_DEVICE, |
| 10487 | .doit = nl80211_start_p2p_device, |
| 10488 | .policy = nl80211_policy, |
| 10489 | .flags = GENL_ADMIN_PERM, |
| 10490 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 10491 | NL80211_FLAG_NEED_RTNL, |
| 10492 | }, |
| 10493 | { |
| 10494 | .cmd = NL80211_CMD_STOP_P2P_DEVICE, |
| 10495 | .doit = nl80211_stop_p2p_device, |
| 10496 | .policy = nl80211_policy, |
| 10497 | .flags = GENL_ADMIN_PERM, |
| 10498 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 10499 | NL80211_FLAG_NEED_RTNL, |
| 10500 | }, |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 10501 | { |
| 10502 | .cmd = NL80211_CMD_SET_MCAST_RATE, |
| 10503 | .doit = nl80211_set_mcast_rate, |
| 10504 | .policy = nl80211_policy, |
| 10505 | .flags = GENL_ADMIN_PERM, |
| 10506 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 10507 | NL80211_FLAG_NEED_RTNL, |
| 10508 | }, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 10509 | { |
| 10510 | .cmd = NL80211_CMD_SET_MAC_ACL, |
| 10511 | .doit = nl80211_set_mac_acl, |
| 10512 | .policy = nl80211_policy, |
| 10513 | .flags = GENL_ADMIN_PERM, |
| 10514 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 10515 | NL80211_FLAG_NEED_RTNL, |
| 10516 | }, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 10517 | { |
| 10518 | .cmd = NL80211_CMD_RADAR_DETECT, |
| 10519 | .doit = nl80211_start_radar_detection, |
| 10520 | .policy = nl80211_policy, |
| 10521 | .flags = GENL_ADMIN_PERM, |
| 10522 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10523 | NL80211_FLAG_NEED_RTNL, |
| 10524 | }, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 10525 | { |
| 10526 | .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES, |
| 10527 | .doit = nl80211_get_protocol_features, |
| 10528 | .policy = nl80211_policy, |
| 10529 | }, |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 10530 | { |
| 10531 | .cmd = NL80211_CMD_UPDATE_FT_IES, |
| 10532 | .doit = nl80211_update_ft_ies, |
| 10533 | .policy = nl80211_policy, |
| 10534 | .flags = GENL_ADMIN_PERM, |
| 10535 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10536 | NL80211_FLAG_NEED_RTNL, |
| 10537 | }, |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 10538 | { |
| 10539 | .cmd = NL80211_CMD_CRIT_PROTOCOL_START, |
| 10540 | .doit = nl80211_crit_protocol_start, |
| 10541 | .policy = nl80211_policy, |
| 10542 | .flags = GENL_ADMIN_PERM, |
| 10543 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 10544 | NL80211_FLAG_NEED_RTNL, |
| 10545 | }, |
| 10546 | { |
| 10547 | .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP, |
| 10548 | .doit = nl80211_crit_protocol_stop, |
| 10549 | .policy = nl80211_policy, |
| 10550 | .flags = GENL_ADMIN_PERM, |
| 10551 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 10552 | NL80211_FLAG_NEED_RTNL, |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 10553 | }, |
| 10554 | { |
| 10555 | .cmd = NL80211_CMD_GET_COALESCE, |
| 10556 | .doit = nl80211_get_coalesce, |
| 10557 | .policy = nl80211_policy, |
| 10558 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 10559 | NL80211_FLAG_NEED_RTNL, |
| 10560 | }, |
| 10561 | { |
| 10562 | .cmd = NL80211_CMD_SET_COALESCE, |
| 10563 | .doit = nl80211_set_coalesce, |
| 10564 | .policy = nl80211_policy, |
| 10565 | .flags = GENL_ADMIN_PERM, |
| 10566 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 10567 | NL80211_FLAG_NEED_RTNL, |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 10568 | }, |
| 10569 | { |
| 10570 | .cmd = NL80211_CMD_CHANNEL_SWITCH, |
| 10571 | .doit = nl80211_channel_switch, |
| 10572 | .policy = nl80211_policy, |
| 10573 | .flags = GENL_ADMIN_PERM, |
| 10574 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10575 | NL80211_FLAG_NEED_RTNL, |
| 10576 | }, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 10577 | { |
| 10578 | .cmd = NL80211_CMD_VENDOR, |
| 10579 | .doit = nl80211_vendor_cmd, |
| 10580 | .policy = nl80211_policy, |
| 10581 | .flags = GENL_ADMIN_PERM, |
| 10582 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 10583 | NL80211_FLAG_NEED_RTNL, |
| 10584 | }, |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 10585 | { |
| 10586 | .cmd = NL80211_CMD_SET_QOS_MAP, |
| 10587 | .doit = nl80211_set_qos_map, |
| 10588 | .policy = nl80211_policy, |
| 10589 | .flags = GENL_ADMIN_PERM, |
| 10590 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10591 | NL80211_FLAG_NEED_RTNL, |
| 10592 | }, |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 10593 | { |
| 10594 | .cmd = NL80211_CMD_ADD_TX_TS, |
| 10595 | .doit = nl80211_add_tx_ts, |
| 10596 | .policy = nl80211_policy, |
| 10597 | .flags = GENL_ADMIN_PERM, |
| 10598 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10599 | NL80211_FLAG_NEED_RTNL, |
| 10600 | }, |
| 10601 | { |
| 10602 | .cmd = NL80211_CMD_DEL_TX_TS, |
| 10603 | .doit = nl80211_del_tx_ts, |
| 10604 | .policy = nl80211_policy, |
| 10605 | .flags = GENL_ADMIN_PERM, |
| 10606 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10607 | NL80211_FLAG_NEED_RTNL, |
| 10608 | }, |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 10609 | { |
| 10610 | .cmd = NL80211_CMD_TDLS_CHANNEL_SWITCH, |
| 10611 | .doit = nl80211_tdls_channel_switch, |
| 10612 | .policy = nl80211_policy, |
| 10613 | .flags = GENL_ADMIN_PERM, |
| 10614 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10615 | NL80211_FLAG_NEED_RTNL, |
| 10616 | }, |
| 10617 | { |
| 10618 | .cmd = NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH, |
| 10619 | .doit = nl80211_tdls_cancel_channel_switch, |
| 10620 | .policy = nl80211_policy, |
| 10621 | .flags = GENL_ADMIN_PERM, |
| 10622 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10623 | NL80211_FLAG_NEED_RTNL, |
| 10624 | }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10625 | }; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10626 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10627 | /* notification functions */ |
| 10628 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 10629 | void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev, |
| 10630 | enum nl80211_commands cmd) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10631 | { |
| 10632 | struct sk_buff *msg; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 10633 | struct nl80211_dump_wiphy_state state = {}; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10634 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 10635 | WARN_ON(cmd != NL80211_CMD_NEW_WIPHY && |
| 10636 | cmd != NL80211_CMD_DEL_WIPHY); |
| 10637 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 10638 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10639 | if (!msg) |
| 10640 | return; |
| 10641 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 10642 | if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10643 | nlmsg_free(msg); |
| 10644 | return; |
| 10645 | } |
| 10646 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10647 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10648 | NL80211_MCGRP_CONFIG, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10649 | } |
| 10650 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 10651 | static int nl80211_add_scan_req(struct sk_buff *msg, |
| 10652 | struct cfg80211_registered_device *rdev) |
| 10653 | { |
| 10654 | struct cfg80211_scan_request *req = rdev->scan_req; |
| 10655 | struct nlattr *nest; |
| 10656 | int i; |
| 10657 | |
| 10658 | if (WARN_ON(!req)) |
| 10659 | return 0; |
| 10660 | |
| 10661 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); |
| 10662 | if (!nest) |
| 10663 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10664 | for (i = 0; i < req->n_ssids; i++) { |
| 10665 | if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) |
| 10666 | goto nla_put_failure; |
| 10667 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 10668 | nla_nest_end(msg, nest); |
| 10669 | |
| 10670 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 10671 | if (!nest) |
| 10672 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10673 | for (i = 0; i < req->n_channels; i++) { |
| 10674 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) |
| 10675 | goto nla_put_failure; |
| 10676 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 10677 | nla_nest_end(msg, nest); |
| 10678 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10679 | if (req->ie && |
| 10680 | nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie)) |
| 10681 | goto nla_put_failure; |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 10682 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 10683 | if (req->flags && |
| 10684 | nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags)) |
| 10685 | goto nla_put_failure; |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 10686 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 10687 | return 0; |
| 10688 | nla_put_failure: |
| 10689 | return -ENOBUFS; |
| 10690 | } |
| 10691 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 10692 | static int nl80211_send_scan_msg(struct sk_buff *msg, |
| 10693 | struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 10694 | struct wireless_dev *wdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10695 | u32 portid, u32 seq, int flags, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 10696 | u32 cmd) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10697 | { |
| 10698 | void *hdr; |
| 10699 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10700 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10701 | if (!hdr) |
| 10702 | return -1; |
| 10703 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10704 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 10705 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 10706 | wdev->netdev->ifindex)) || |
| 10707 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10708 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10709 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 10710 | /* ignore errors and send incomplete event anyway */ |
| 10711 | nl80211_add_scan_req(msg, rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10712 | |
| 10713 | return genlmsg_end(msg, hdr); |
| 10714 | |
| 10715 | nla_put_failure: |
| 10716 | genlmsg_cancel(msg, hdr); |
| 10717 | return -EMSGSIZE; |
| 10718 | } |
| 10719 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 10720 | static int |
| 10721 | nl80211_send_sched_scan_msg(struct sk_buff *msg, |
| 10722 | struct cfg80211_registered_device *rdev, |
| 10723 | struct net_device *netdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10724 | u32 portid, u32 seq, int flags, u32 cmd) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 10725 | { |
| 10726 | void *hdr; |
| 10727 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10728 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 10729 | if (!hdr) |
| 10730 | return -1; |
| 10731 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10732 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10733 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 10734 | goto nla_put_failure; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 10735 | |
| 10736 | return genlmsg_end(msg, hdr); |
| 10737 | |
| 10738 | nla_put_failure: |
| 10739 | genlmsg_cancel(msg, hdr); |
| 10740 | return -EMSGSIZE; |
| 10741 | } |
| 10742 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 10743 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 10744 | struct wireless_dev *wdev) |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 10745 | { |
| 10746 | struct sk_buff *msg; |
| 10747 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10748 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 10749 | if (!msg) |
| 10750 | return; |
| 10751 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 10752 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 10753 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
| 10754 | nlmsg_free(msg); |
| 10755 | return; |
| 10756 | } |
| 10757 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10758 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10759 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 10760 | } |
| 10761 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 10762 | struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev, |
| 10763 | struct wireless_dev *wdev, bool aborted) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10764 | { |
| 10765 | struct sk_buff *msg; |
| 10766 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 10767 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10768 | if (!msg) |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 10769 | return NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10770 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 10771 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 10772 | aborted ? NL80211_CMD_SCAN_ABORTED : |
| 10773 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10774 | nlmsg_free(msg); |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 10775 | return NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10776 | } |
| 10777 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 10778 | return msg; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10779 | } |
| 10780 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 10781 | void nl80211_send_scan_result(struct cfg80211_registered_device *rdev, |
| 10782 | struct sk_buff *msg) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10783 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10784 | if (!msg) |
| 10785 | return; |
| 10786 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10787 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10788 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10789 | } |
| 10790 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 10791 | void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev, |
| 10792 | struct net_device *netdev) |
| 10793 | { |
| 10794 | struct sk_buff *msg; |
| 10795 | |
| 10796 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 10797 | if (!msg) |
| 10798 | return; |
| 10799 | |
| 10800 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 10801 | NL80211_CMD_SCHED_SCAN_RESULTS) < 0) { |
| 10802 | nlmsg_free(msg); |
| 10803 | return; |
| 10804 | } |
| 10805 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10806 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10807 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 10808 | } |
| 10809 | |
| 10810 | void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev, |
| 10811 | struct net_device *netdev, u32 cmd) |
| 10812 | { |
| 10813 | struct sk_buff *msg; |
| 10814 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10815 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 10816 | if (!msg) |
| 10817 | return; |
| 10818 | |
| 10819 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) { |
| 10820 | nlmsg_free(msg); |
| 10821 | return; |
| 10822 | } |
| 10823 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10824 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10825 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 10826 | } |
| 10827 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 10828 | /* |
| 10829 | * This can happen on global regulatory changes or device specific settings |
| 10830 | * based on custom world regulatory domains. |
| 10831 | */ |
| 10832 | void nl80211_send_reg_change_event(struct regulatory_request *request) |
| 10833 | { |
| 10834 | struct sk_buff *msg; |
| 10835 | void *hdr; |
| 10836 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 10837 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 10838 | if (!msg) |
| 10839 | return; |
| 10840 | |
| 10841 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE); |
| 10842 | if (!hdr) { |
| 10843 | nlmsg_free(msg); |
| 10844 | return; |
| 10845 | } |
| 10846 | |
| 10847 | /* Userspace can always count this one always being set */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10848 | if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator)) |
| 10849 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 10850 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10851 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') { |
| 10852 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 10853 | NL80211_REGDOM_TYPE_WORLD)) |
| 10854 | goto nla_put_failure; |
| 10855 | } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') { |
| 10856 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 10857 | NL80211_REGDOM_TYPE_CUSTOM_WORLD)) |
| 10858 | goto nla_put_failure; |
| 10859 | } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || |
| 10860 | request->intersect) { |
| 10861 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 10862 | NL80211_REGDOM_TYPE_INTERSECTION)) |
| 10863 | goto nla_put_failure; |
| 10864 | } else { |
| 10865 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 10866 | NL80211_REGDOM_TYPE_COUNTRY) || |
| 10867 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, |
| 10868 | request->alpha2)) |
| 10869 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 10870 | } |
| 10871 | |
Johannes Berg | f417376 | 2012-12-03 18:23:37 +0100 | [diff] [blame] | 10872 | if (request->wiphy_idx != WIPHY_IDX_INVALID && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10873 | nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) |
| 10874 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 10875 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10876 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 10877 | |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 10878 | rcu_read_lock(); |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10879 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10880 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 10881 | rcu_read_unlock(); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 10882 | |
| 10883 | return; |
| 10884 | |
| 10885 | nla_put_failure: |
| 10886 | genlmsg_cancel(msg, hdr); |
| 10887 | nlmsg_free(msg); |
| 10888 | } |
| 10889 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10890 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
| 10891 | struct net_device *netdev, |
| 10892 | const u8 *buf, size_t len, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 10893 | enum nl80211_commands cmd, gfp_t gfp, |
| 10894 | int uapsd_queues) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10895 | { |
| 10896 | struct sk_buff *msg; |
| 10897 | void *hdr; |
| 10898 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10899 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10900 | if (!msg) |
| 10901 | return; |
| 10902 | |
| 10903 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 10904 | if (!hdr) { |
| 10905 | nlmsg_free(msg); |
| 10906 | return; |
| 10907 | } |
| 10908 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10909 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10910 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10911 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) |
| 10912 | goto nla_put_failure; |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10913 | |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 10914 | if (uapsd_queues >= 0) { |
| 10915 | struct nlattr *nla_wmm = |
| 10916 | nla_nest_start(msg, NL80211_ATTR_STA_WME); |
| 10917 | if (!nla_wmm) |
| 10918 | goto nla_put_failure; |
| 10919 | |
| 10920 | if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES, |
| 10921 | uapsd_queues)) |
| 10922 | goto nla_put_failure; |
| 10923 | |
| 10924 | nla_nest_end(msg, nla_wmm); |
| 10925 | } |
| 10926 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10927 | genlmsg_end(msg, hdr); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10928 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10929 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10930 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10931 | return; |
| 10932 | |
| 10933 | nla_put_failure: |
| 10934 | genlmsg_cancel(msg, hdr); |
| 10935 | nlmsg_free(msg); |
| 10936 | } |
| 10937 | |
| 10938 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10939 | struct net_device *netdev, const u8 *buf, |
| 10940 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10941 | { |
| 10942 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 10943 | NL80211_CMD_AUTHENTICATE, gfp, -1); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10944 | } |
| 10945 | |
| 10946 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, |
| 10947 | struct net_device *netdev, const u8 *buf, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 10948 | size_t len, gfp_t gfp, int uapsd_queues) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10949 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10950 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 10951 | NL80211_CMD_ASSOCIATE, gfp, uapsd_queues); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10952 | } |
| 10953 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 10954 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10955 | struct net_device *netdev, const u8 *buf, |
| 10956 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10957 | { |
| 10958 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 10959 | NL80211_CMD_DEAUTHENTICATE, gfp, -1); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10960 | } |
| 10961 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 10962 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
| 10963 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10964 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10965 | { |
| 10966 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 10967 | NL80211_CMD_DISASSOCIATE, gfp, -1); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10968 | } |
| 10969 | |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 10970 | void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf, |
| 10971 | size_t len) |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 10972 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10973 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10974 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 10975 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 10976 | const struct ieee80211_mgmt *mgmt = (void *)buf; |
| 10977 | u32 cmd; |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 10978 | |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 10979 | if (WARN_ON(len < 2)) |
| 10980 | return; |
| 10981 | |
| 10982 | if (ieee80211_is_deauth(mgmt->frame_control)) |
| 10983 | cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE; |
| 10984 | else |
| 10985 | cmd = NL80211_CMD_UNPROT_DISASSOCIATE; |
| 10986 | |
| 10987 | trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len); |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 10988 | nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1); |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 10989 | } |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 10990 | EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt); |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 10991 | |
Luis R. Rodriguez | 1b06bb4 | 2009-05-02 00:34:48 -0400 | [diff] [blame] | 10992 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
| 10993 | struct net_device *netdev, int cmd, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10994 | const u8 *addr, gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10995 | { |
| 10996 | struct sk_buff *msg; |
| 10997 | void *hdr; |
| 10998 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10999 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 11000 | if (!msg) |
| 11001 | return; |
| 11002 | |
| 11003 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 11004 | if (!hdr) { |
| 11005 | nlmsg_free(msg); |
| 11006 | return; |
| 11007 | } |
| 11008 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11009 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11010 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 11011 | nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || |
| 11012 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 11013 | goto nla_put_failure; |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 11014 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11015 | genlmsg_end(msg, hdr); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 11016 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11017 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11018 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 11019 | return; |
| 11020 | |
| 11021 | nla_put_failure: |
| 11022 | genlmsg_cancel(msg, hdr); |
| 11023 | nlmsg_free(msg); |
| 11024 | } |
| 11025 | |
| 11026 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 11027 | struct net_device *netdev, const u8 *addr, |
| 11028 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 11029 | { |
| 11030 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 11031 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 11032 | } |
| 11033 | |
| 11034 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 11035 | struct net_device *netdev, const u8 *addr, |
| 11036 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 11037 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 11038 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
| 11039 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 11040 | } |
| 11041 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11042 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
| 11043 | struct net_device *netdev, const u8 *bssid, |
| 11044 | const u8 *req_ie, size_t req_ie_len, |
| 11045 | const u8 *resp_ie, size_t resp_ie_len, |
| 11046 | u16 status, gfp_t gfp) |
| 11047 | { |
| 11048 | struct sk_buff *msg; |
| 11049 | void *hdr; |
| 11050 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11051 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11052 | if (!msg) |
| 11053 | return; |
| 11054 | |
| 11055 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); |
| 11056 | if (!hdr) { |
| 11057 | nlmsg_free(msg); |
| 11058 | return; |
| 11059 | } |
| 11060 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11061 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11062 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 11063 | (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) || |
| 11064 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) || |
| 11065 | (req_ie && |
| 11066 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 11067 | (resp_ie && |
| 11068 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 11069 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11070 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11071 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11072 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11073 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11074 | NL80211_MCGRP_MLME, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11075 | return; |
| 11076 | |
| 11077 | nla_put_failure: |
| 11078 | genlmsg_cancel(msg, hdr); |
| 11079 | nlmsg_free(msg); |
| 11080 | |
| 11081 | } |
| 11082 | |
| 11083 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, |
| 11084 | struct net_device *netdev, const u8 *bssid, |
| 11085 | const u8 *req_ie, size_t req_ie_len, |
| 11086 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) |
| 11087 | { |
| 11088 | struct sk_buff *msg; |
| 11089 | void *hdr; |
| 11090 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11091 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11092 | if (!msg) |
| 11093 | return; |
| 11094 | |
| 11095 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); |
| 11096 | if (!hdr) { |
| 11097 | nlmsg_free(msg); |
| 11098 | return; |
| 11099 | } |
| 11100 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11101 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11102 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 11103 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) || |
| 11104 | (req_ie && |
| 11105 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 11106 | (resp_ie && |
| 11107 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 11108 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11109 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11110 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11111 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11112 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11113 | NL80211_MCGRP_MLME, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11114 | return; |
| 11115 | |
| 11116 | nla_put_failure: |
| 11117 | genlmsg_cancel(msg, hdr); |
| 11118 | nlmsg_free(msg); |
| 11119 | |
| 11120 | } |
| 11121 | |
| 11122 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, |
| 11123 | struct net_device *netdev, u16 reason, |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 11124 | const u8 *ie, size_t ie_len, bool from_ap) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11125 | { |
| 11126 | struct sk_buff *msg; |
| 11127 | void *hdr; |
| 11128 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11129 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11130 | if (!msg) |
| 11131 | return; |
| 11132 | |
| 11133 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); |
| 11134 | if (!hdr) { |
| 11135 | nlmsg_free(msg); |
| 11136 | return; |
| 11137 | } |
| 11138 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11139 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11140 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 11141 | (from_ap && reason && |
| 11142 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) || |
| 11143 | (from_ap && |
| 11144 | nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) || |
| 11145 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) |
| 11146 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11147 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11148 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11149 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11150 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11151 | NL80211_MCGRP_MLME, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11152 | return; |
| 11153 | |
| 11154 | nla_put_failure: |
| 11155 | genlmsg_cancel(msg, hdr); |
| 11156 | nlmsg_free(msg); |
| 11157 | |
| 11158 | } |
| 11159 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 11160 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
| 11161 | struct net_device *netdev, const u8 *bssid, |
| 11162 | gfp_t gfp) |
| 11163 | { |
| 11164 | struct sk_buff *msg; |
| 11165 | void *hdr; |
| 11166 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 11167 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 11168 | if (!msg) |
| 11169 | return; |
| 11170 | |
| 11171 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); |
| 11172 | if (!hdr) { |
| 11173 | nlmsg_free(msg); |
| 11174 | return; |
| 11175 | } |
| 11176 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11177 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11178 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 11179 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 11180 | goto nla_put_failure; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 11181 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11182 | genlmsg_end(msg, hdr); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 11183 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11184 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11185 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 11186 | return; |
| 11187 | |
| 11188 | nla_put_failure: |
| 11189 | genlmsg_cancel(msg, hdr); |
| 11190 | nlmsg_free(msg); |
| 11191 | } |
| 11192 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11193 | void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr, |
| 11194 | const u8* ie, u8 ie_len, gfp_t gfp) |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 11195 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11196 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11197 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 11198 | struct sk_buff *msg; |
| 11199 | void *hdr; |
| 11200 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11201 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT)) |
| 11202 | return; |
| 11203 | |
| 11204 | trace_cfg80211_notify_new_peer_candidate(dev, addr); |
| 11205 | |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 11206 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 11207 | if (!msg) |
| 11208 | return; |
| 11209 | |
| 11210 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); |
| 11211 | if (!hdr) { |
| 11212 | nlmsg_free(msg); |
| 11213 | return; |
| 11214 | } |
| 11215 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11216 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11217 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 11218 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11219 | (ie_len && ie && |
| 11220 | nla_put(msg, NL80211_ATTR_IE, ie_len , ie))) |
| 11221 | goto nla_put_failure; |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 11222 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11223 | genlmsg_end(msg, hdr); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 11224 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11225 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11226 | NL80211_MCGRP_MLME, gfp); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 11227 | return; |
| 11228 | |
| 11229 | nla_put_failure: |
| 11230 | genlmsg_cancel(msg, hdr); |
| 11231 | nlmsg_free(msg); |
| 11232 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11233 | EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 11234 | |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 11235 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
| 11236 | struct net_device *netdev, const u8 *addr, |
| 11237 | enum nl80211_key_type key_type, int key_id, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 11238 | const u8 *tsc, gfp_t gfp) |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 11239 | { |
| 11240 | struct sk_buff *msg; |
| 11241 | void *hdr; |
| 11242 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 11243 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 11244 | if (!msg) |
| 11245 | return; |
| 11246 | |
| 11247 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); |
| 11248 | if (!hdr) { |
| 11249 | nlmsg_free(msg); |
| 11250 | return; |
| 11251 | } |
| 11252 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11253 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11254 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 11255 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
| 11256 | nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) || |
| 11257 | (key_id != -1 && |
| 11258 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) || |
| 11259 | (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc))) |
| 11260 | goto nla_put_failure; |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 11261 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11262 | genlmsg_end(msg, hdr); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 11263 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11264 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11265 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 11266 | return; |
| 11267 | |
| 11268 | nla_put_failure: |
| 11269 | genlmsg_cancel(msg, hdr); |
| 11270 | nlmsg_free(msg); |
| 11271 | } |
| 11272 | |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 11273 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
| 11274 | struct ieee80211_channel *channel_before, |
| 11275 | struct ieee80211_channel *channel_after) |
| 11276 | { |
| 11277 | struct sk_buff *msg; |
| 11278 | void *hdr; |
| 11279 | struct nlattr *nl_freq; |
| 11280 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 11281 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 11282 | if (!msg) |
| 11283 | return; |
| 11284 | |
| 11285 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); |
| 11286 | if (!hdr) { |
| 11287 | nlmsg_free(msg); |
| 11288 | return; |
| 11289 | } |
| 11290 | |
| 11291 | /* |
| 11292 | * Since we are applying the beacon hint to a wiphy we know its |
| 11293 | * wiphy_idx is valid |
| 11294 | */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11295 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 11296 | goto nla_put_failure; |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 11297 | |
| 11298 | /* Before */ |
| 11299 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); |
| 11300 | if (!nl_freq) |
| 11301 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 11302 | if (nl80211_msg_put_channel(msg, channel_before, false)) |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 11303 | goto nla_put_failure; |
| 11304 | nla_nest_end(msg, nl_freq); |
| 11305 | |
| 11306 | /* After */ |
| 11307 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); |
| 11308 | if (!nl_freq) |
| 11309 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 11310 | if (nl80211_msg_put_channel(msg, channel_after, false)) |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 11311 | goto nla_put_failure; |
| 11312 | nla_nest_end(msg, nl_freq); |
| 11313 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11314 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 11315 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 11316 | rcu_read_lock(); |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11317 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11318 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 11319 | rcu_read_unlock(); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 11320 | |
| 11321 | return; |
| 11322 | |
| 11323 | nla_put_failure: |
| 11324 | genlmsg_cancel(msg, hdr); |
| 11325 | nlmsg_free(msg); |
| 11326 | } |
| 11327 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11328 | static void nl80211_send_remain_on_chan_event( |
| 11329 | int cmd, struct cfg80211_registered_device *rdev, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11330 | struct wireless_dev *wdev, u64 cookie, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11331 | struct ieee80211_channel *chan, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11332 | unsigned int duration, gfp_t gfp) |
| 11333 | { |
| 11334 | struct sk_buff *msg; |
| 11335 | void *hdr; |
| 11336 | |
| 11337 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 11338 | if (!msg) |
| 11339 | return; |
| 11340 | |
| 11341 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 11342 | if (!hdr) { |
| 11343 | nlmsg_free(msg); |
| 11344 | return; |
| 11345 | } |
| 11346 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11347 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11348 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 11349 | wdev->netdev->ifindex)) || |
Johannes Berg | 00f5335 | 2012-07-17 11:53:12 +0200 | [diff] [blame] | 11350 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11351 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) || |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 11352 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 11353 | NL80211_CHAN_NO_HT) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11354 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 11355 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11356 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11357 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL && |
| 11358 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) |
| 11359 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11360 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11361 | genlmsg_end(msg, hdr); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11362 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11363 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11364 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11365 | return; |
| 11366 | |
| 11367 | nla_put_failure: |
| 11368 | genlmsg_cancel(msg, hdr); |
| 11369 | nlmsg_free(msg); |
| 11370 | } |
| 11371 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11372 | void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie, |
| 11373 | struct ieee80211_channel *chan, |
| 11374 | unsigned int duration, gfp_t gfp) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11375 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11376 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11377 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11378 | |
| 11379 | trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11380 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11381 | rdev, wdev, cookie, chan, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 11382 | duration, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11383 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11384 | EXPORT_SYMBOL(cfg80211_ready_on_channel); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11385 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11386 | void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie, |
| 11387 | struct ieee80211_channel *chan, |
| 11388 | gfp_t gfp) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11389 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11390 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11391 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11392 | |
| 11393 | trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11394 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 11395 | rdev, wdev, cookie, chan, 0, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11396 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11397 | EXPORT_SYMBOL(cfg80211_remain_on_channel_expired); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11398 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11399 | void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr, |
| 11400 | struct station_info *sinfo, gfp_t gfp) |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 11401 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11402 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11403 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 11404 | struct sk_buff *msg; |
| 11405 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11406 | trace_cfg80211_new_sta(dev, mac_addr, sinfo); |
| 11407 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11408 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 11409 | if (!msg) |
| 11410 | return; |
| 11411 | |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 11412 | if (nl80211_send_station(msg, 0, 0, 0, |
| 11413 | rdev, dev, mac_addr, sinfo) < 0) { |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 11414 | nlmsg_free(msg); |
| 11415 | return; |
| 11416 | } |
| 11417 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11418 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11419 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 11420 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11421 | EXPORT_SYMBOL(cfg80211_new_sta); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 11422 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11423 | 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] | 11424 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11425 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11426 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 11427 | struct sk_buff *msg; |
| 11428 | void *hdr; |
| 11429 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11430 | trace_cfg80211_del_sta(dev, mac_addr); |
| 11431 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11432 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 11433 | if (!msg) |
| 11434 | return; |
| 11435 | |
| 11436 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION); |
| 11437 | if (!hdr) { |
| 11438 | nlmsg_free(msg); |
| 11439 | return; |
| 11440 | } |
| 11441 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11442 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 11443 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 11444 | goto nla_put_failure; |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 11445 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11446 | genlmsg_end(msg, hdr); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 11447 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11448 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11449 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 11450 | return; |
| 11451 | |
| 11452 | nla_put_failure: |
| 11453 | genlmsg_cancel(msg, hdr); |
| 11454 | nlmsg_free(msg); |
| 11455 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11456 | EXPORT_SYMBOL(cfg80211_del_sta); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 11457 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11458 | void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr, |
| 11459 | enum nl80211_connect_failed_reason reason, |
| 11460 | gfp_t gfp) |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 11461 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11462 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11463 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 11464 | struct sk_buff *msg; |
| 11465 | void *hdr; |
| 11466 | |
| 11467 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 11468 | if (!msg) |
| 11469 | return; |
| 11470 | |
| 11471 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED); |
| 11472 | if (!hdr) { |
| 11473 | nlmsg_free(msg); |
| 11474 | return; |
| 11475 | } |
| 11476 | |
| 11477 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 11478 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 11479 | nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason)) |
| 11480 | goto nla_put_failure; |
| 11481 | |
| 11482 | genlmsg_end(msg, hdr); |
| 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); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [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_conn_failed); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 11493 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 11494 | static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, |
| 11495 | const u8 *addr, gfp_t gfp) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 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 | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 11499 | struct sk_buff *msg; |
| 11500 | void *hdr; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11501 | u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 11502 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11503 | if (!nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 11504 | return false; |
| 11505 | |
| 11506 | msg = nlmsg_new(100, gfp); |
| 11507 | if (!msg) |
| 11508 | return true; |
| 11509 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 11510 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 11511 | if (!hdr) { |
| 11512 | nlmsg_free(msg); |
| 11513 | return true; |
| 11514 | } |
| 11515 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11516 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11517 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 11518 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 11519 | goto nla_put_failure; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 11520 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 11521 | genlmsg_end(msg, hdr); |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11522 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 11523 | return true; |
| 11524 | |
| 11525 | nla_put_failure: |
| 11526 | genlmsg_cancel(msg, hdr); |
| 11527 | nlmsg_free(msg); |
| 11528 | return true; |
| 11529 | } |
| 11530 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11531 | bool cfg80211_rx_spurious_frame(struct net_device *dev, |
| 11532 | const u8 *addr, gfp_t gfp) |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 11533 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11534 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11535 | bool ret; |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 11536 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11537 | trace_cfg80211_rx_spurious_frame(dev, addr); |
| 11538 | |
| 11539 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 11540 | wdev->iftype != NL80211_IFTYPE_P2P_GO)) { |
| 11541 | trace_cfg80211_return_bool(false); |
| 11542 | return false; |
| 11543 | } |
| 11544 | ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, |
| 11545 | addr, gfp); |
| 11546 | trace_cfg80211_return_bool(ret); |
| 11547 | return ret; |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 11548 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11549 | EXPORT_SYMBOL(cfg80211_rx_spurious_frame); |
| 11550 | |
| 11551 | bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev, |
| 11552 | const u8 *addr, gfp_t gfp) |
| 11553 | { |
| 11554 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11555 | bool ret; |
| 11556 | |
| 11557 | trace_cfg80211_rx_unexpected_4addr_frame(dev, addr); |
| 11558 | |
| 11559 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 11560 | wdev->iftype != NL80211_IFTYPE_P2P_GO && |
| 11561 | wdev->iftype != NL80211_IFTYPE_AP_VLAN)) { |
| 11562 | trace_cfg80211_return_bool(false); |
| 11563 | return false; |
| 11564 | } |
| 11565 | ret = __nl80211_unexpected_frame(dev, |
| 11566 | NL80211_CMD_UNEXPECTED_4ADDR_FRAME, |
| 11567 | addr, gfp); |
| 11568 | trace_cfg80211_return_bool(ret); |
| 11569 | return ret; |
| 11570 | } |
| 11571 | EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame); |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 11572 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 11573 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11574 | struct wireless_dev *wdev, u32 nlportid, |
Johannes Berg | 804483e | 2012-03-05 22:18:41 +0100 | [diff] [blame] | 11575 | int freq, int sig_dbm, |
Vladimir Kondratiev | 19504cf | 2013-08-15 14:51:28 +0300 | [diff] [blame] | 11576 | const u8 *buf, size_t len, u32 flags, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11577 | { |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11578 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11579 | struct sk_buff *msg; |
| 11580 | void *hdr; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11581 | |
| 11582 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 11583 | if (!msg) |
| 11584 | return -ENOMEM; |
| 11585 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 11586 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11587 | if (!hdr) { |
| 11588 | nlmsg_free(msg); |
| 11589 | return -ENOMEM; |
| 11590 | } |
| 11591 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11592 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11593 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 11594 | netdev->ifindex)) || |
Ilan Peer | a838490 | 2013-05-08 16:35:55 +0300 | [diff] [blame] | 11595 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11596 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
| 11597 | (sig_dbm && |
| 11598 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
Vladimir Kondratiev | 19504cf | 2013-08-15 14:51:28 +0300 | [diff] [blame] | 11599 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
| 11600 | (flags && |
| 11601 | nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11602 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11603 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11604 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11605 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11606 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11607 | |
| 11608 | nla_put_failure: |
| 11609 | genlmsg_cancel(msg, hdr); |
| 11610 | nlmsg_free(msg); |
| 11611 | return -ENOBUFS; |
| 11612 | } |
| 11613 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11614 | void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie, |
| 11615 | const u8 *buf, size_t len, bool ack, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11616 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11617 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11618 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11619 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11620 | struct sk_buff *msg; |
| 11621 | void *hdr; |
| 11622 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11623 | trace_cfg80211_mgmt_tx_status(wdev, cookie, ack); |
| 11624 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11625 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 11626 | if (!msg) |
| 11627 | return; |
| 11628 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 11629 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11630 | if (!hdr) { |
| 11631 | nlmsg_free(msg); |
| 11632 | return; |
| 11633 | } |
| 11634 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11635 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11636 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 11637 | netdev->ifindex)) || |
Ilan Peer | a838490 | 2013-05-08 16:35:55 +0300 | [diff] [blame] | 11638 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11639 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
| 11640 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || |
| 11641 | (ack && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 11642 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11643 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11644 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11645 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11646 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11647 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11648 | return; |
| 11649 | |
| 11650 | nla_put_failure: |
| 11651 | genlmsg_cancel(msg, hdr); |
| 11652 | nlmsg_free(msg); |
| 11653 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11654 | EXPORT_SYMBOL(cfg80211_mgmt_tx_status); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11655 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11656 | void cfg80211_cqm_rssi_notify(struct net_device *dev, |
| 11657 | enum nl80211_cqm_rssi_threshold_event rssi_event, |
| 11658 | gfp_t gfp) |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11659 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11660 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11661 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11662 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11663 | struct sk_buff *msg; |
| 11664 | struct nlattr *pinfoattr; |
| 11665 | void *hdr; |
| 11666 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11667 | trace_cfg80211_cqm_rssi_notify(dev, rssi_event); |
| 11668 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11669 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11670 | if (!msg) |
| 11671 | return; |
| 11672 | |
| 11673 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 11674 | if (!hdr) { |
| 11675 | nlmsg_free(msg); |
| 11676 | return; |
| 11677 | } |
| 11678 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11679 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11680 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11681 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11682 | |
| 11683 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 11684 | if (!pinfoattr) |
| 11685 | goto nla_put_failure; |
| 11686 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11687 | if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, |
| 11688 | rssi_event)) |
| 11689 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11690 | |
| 11691 | nla_nest_end(msg, pinfoattr); |
| 11692 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11693 | genlmsg_end(msg, hdr); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11694 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11695 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11696 | NL80211_MCGRP_MLME, gfp); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11697 | return; |
| 11698 | |
| 11699 | nla_put_failure: |
| 11700 | genlmsg_cancel(msg, hdr); |
| 11701 | nlmsg_free(msg); |
| 11702 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11703 | EXPORT_SYMBOL(cfg80211_cqm_rssi_notify); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11704 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11705 | static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
| 11706 | struct net_device *netdev, const u8 *bssid, |
| 11707 | const u8 *replay_ctr, gfp_t gfp) |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 11708 | { |
| 11709 | struct sk_buff *msg; |
| 11710 | struct nlattr *rekey_attr; |
| 11711 | void *hdr; |
| 11712 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11713 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 11714 | if (!msg) |
| 11715 | return; |
| 11716 | |
| 11717 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); |
| 11718 | if (!hdr) { |
| 11719 | nlmsg_free(msg); |
| 11720 | return; |
| 11721 | } |
| 11722 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11723 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11724 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 11725 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 11726 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 11727 | |
| 11728 | rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); |
| 11729 | if (!rekey_attr) |
| 11730 | goto nla_put_failure; |
| 11731 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11732 | if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
| 11733 | NL80211_REPLAY_CTR_LEN, replay_ctr)) |
| 11734 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 11735 | |
| 11736 | nla_nest_end(msg, rekey_attr); |
| 11737 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11738 | genlmsg_end(msg, hdr); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 11739 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11740 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11741 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 11742 | return; |
| 11743 | |
| 11744 | nla_put_failure: |
| 11745 | genlmsg_cancel(msg, hdr); |
| 11746 | nlmsg_free(msg); |
| 11747 | } |
| 11748 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11749 | void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid, |
| 11750 | const u8 *replay_ctr, gfp_t gfp) |
| 11751 | { |
| 11752 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11753 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11754 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11755 | |
| 11756 | trace_cfg80211_gtk_rekey_notify(dev, bssid); |
| 11757 | nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp); |
| 11758 | } |
| 11759 | EXPORT_SYMBOL(cfg80211_gtk_rekey_notify); |
| 11760 | |
| 11761 | static void |
| 11762 | nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, |
| 11763 | struct net_device *netdev, int index, |
| 11764 | const u8 *bssid, bool preauth, gfp_t gfp) |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 11765 | { |
| 11766 | struct sk_buff *msg; |
| 11767 | struct nlattr *attr; |
| 11768 | void *hdr; |
| 11769 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11770 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 11771 | if (!msg) |
| 11772 | return; |
| 11773 | |
| 11774 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); |
| 11775 | if (!hdr) { |
| 11776 | nlmsg_free(msg); |
| 11777 | return; |
| 11778 | } |
| 11779 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11780 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11781 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 11782 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 11783 | |
| 11784 | attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE); |
| 11785 | if (!attr) |
| 11786 | goto nla_put_failure; |
| 11787 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11788 | if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) || |
| 11789 | nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) || |
| 11790 | (preauth && |
| 11791 | nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH))) |
| 11792 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 11793 | |
| 11794 | nla_nest_end(msg, attr); |
| 11795 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11796 | genlmsg_end(msg, hdr); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 11797 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11798 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11799 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 11800 | return; |
| 11801 | |
| 11802 | nla_put_failure: |
| 11803 | genlmsg_cancel(msg, hdr); |
| 11804 | nlmsg_free(msg); |
| 11805 | } |
| 11806 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11807 | void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index, |
| 11808 | const u8 *bssid, bool preauth, gfp_t gfp) |
| 11809 | { |
| 11810 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11811 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11812 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11813 | |
| 11814 | trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth); |
| 11815 | nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp); |
| 11816 | } |
| 11817 | EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify); |
| 11818 | |
| 11819 | static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev, |
| 11820 | struct net_device *netdev, |
| 11821 | struct cfg80211_chan_def *chandef, |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 11822 | gfp_t gfp, |
| 11823 | enum nl80211_commands notif, |
| 11824 | u8 count) |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 11825 | { |
| 11826 | struct sk_buff *msg; |
| 11827 | void *hdr; |
| 11828 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11829 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 11830 | if (!msg) |
| 11831 | return; |
| 11832 | |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 11833 | hdr = nl80211hdr_put(msg, 0, 0, 0, notif); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 11834 | if (!hdr) { |
| 11835 | nlmsg_free(msg); |
| 11836 | return; |
| 11837 | } |
| 11838 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 11839 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 11840 | goto nla_put_failure; |
| 11841 | |
| 11842 | if (nl80211_send_chandef(msg, chandef)) |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 11843 | goto nla_put_failure; |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 11844 | |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 11845 | if ((notif == NL80211_CMD_CH_SWITCH_STARTED_NOTIFY) && |
| 11846 | (nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, count))) |
| 11847 | goto nla_put_failure; |
| 11848 | |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 11849 | genlmsg_end(msg, hdr); |
| 11850 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11851 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11852 | NL80211_MCGRP_MLME, gfp); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 11853 | return; |
| 11854 | |
| 11855 | nla_put_failure: |
| 11856 | genlmsg_cancel(msg, hdr); |
| 11857 | nlmsg_free(msg); |
| 11858 | } |
| 11859 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11860 | void cfg80211_ch_switch_notify(struct net_device *dev, |
| 11861 | struct cfg80211_chan_def *chandef) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 11862 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11863 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11864 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11865 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11866 | |
Simon Wunderlich | e487eae | 2013-11-21 18:19:51 +0100 | [diff] [blame] | 11867 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11868 | |
Simon Wunderlich | e487eae | 2013-11-21 18:19:51 +0100 | [diff] [blame] | 11869 | trace_cfg80211_ch_switch_notify(dev, chandef); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11870 | |
Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 11871 | wdev->chandef = *chandef; |
Janusz Dziedzic | 96f55f1 | 2014-01-24 14:29:21 +0100 | [diff] [blame] | 11872 | wdev->preset_chandef = *chandef; |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 11873 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL, |
| 11874 | NL80211_CMD_CH_SWITCH_NOTIFY, 0); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11875 | } |
| 11876 | EXPORT_SYMBOL(cfg80211_ch_switch_notify); |
| 11877 | |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 11878 | void cfg80211_ch_switch_started_notify(struct net_device *dev, |
| 11879 | struct cfg80211_chan_def *chandef, |
| 11880 | u8 count) |
| 11881 | { |
| 11882 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11883 | struct wiphy *wiphy = wdev->wiphy; |
| 11884 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
| 11885 | |
| 11886 | trace_cfg80211_ch_switch_started_notify(dev, chandef); |
| 11887 | |
| 11888 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL, |
| 11889 | NL80211_CMD_CH_SWITCH_STARTED_NOTIFY, count); |
| 11890 | } |
| 11891 | EXPORT_SYMBOL(cfg80211_ch_switch_started_notify); |
| 11892 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11893 | void cfg80211_cqm_txe_notify(struct net_device *dev, |
| 11894 | const u8 *peer, u32 num_packets, |
| 11895 | u32 rate, u32 intvl, gfp_t gfp) |
| 11896 | { |
| 11897 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11898 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11899 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 11900 | struct sk_buff *msg; |
| 11901 | struct nlattr *pinfoattr; |
| 11902 | void *hdr; |
| 11903 | |
| 11904 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 11905 | if (!msg) |
| 11906 | return; |
| 11907 | |
| 11908 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 11909 | if (!hdr) { |
| 11910 | nlmsg_free(msg); |
| 11911 | return; |
| 11912 | } |
| 11913 | |
| 11914 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11915 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 11916 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
| 11917 | goto nla_put_failure; |
| 11918 | |
| 11919 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 11920 | if (!pinfoattr) |
| 11921 | goto nla_put_failure; |
| 11922 | |
| 11923 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets)) |
| 11924 | goto nla_put_failure; |
| 11925 | |
| 11926 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate)) |
| 11927 | goto nla_put_failure; |
| 11928 | |
| 11929 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl)) |
| 11930 | goto nla_put_failure; |
| 11931 | |
| 11932 | nla_nest_end(msg, pinfoattr); |
| 11933 | |
| 11934 | genlmsg_end(msg, hdr); |
| 11935 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11936 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11937 | NL80211_MCGRP_MLME, gfp); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 11938 | return; |
| 11939 | |
| 11940 | nla_put_failure: |
| 11941 | genlmsg_cancel(msg, hdr); |
| 11942 | nlmsg_free(msg); |
| 11943 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11944 | EXPORT_SYMBOL(cfg80211_cqm_txe_notify); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 11945 | |
| 11946 | void |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 11947 | nl80211_radar_notify(struct cfg80211_registered_device *rdev, |
Janusz Dziedzic | d2859df | 2013-11-06 13:55:51 +0100 | [diff] [blame] | 11948 | const struct cfg80211_chan_def *chandef, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 11949 | enum nl80211_radar_event event, |
| 11950 | struct net_device *netdev, gfp_t gfp) |
| 11951 | { |
| 11952 | struct sk_buff *msg; |
| 11953 | void *hdr; |
| 11954 | |
| 11955 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 11956 | if (!msg) |
| 11957 | return; |
| 11958 | |
| 11959 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT); |
| 11960 | if (!hdr) { |
| 11961 | nlmsg_free(msg); |
| 11962 | return; |
| 11963 | } |
| 11964 | |
| 11965 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 11966 | goto nla_put_failure; |
| 11967 | |
| 11968 | /* NOP and radar events don't need a netdev parameter */ |
| 11969 | if (netdev) { |
| 11970 | struct wireless_dev *wdev = netdev->ieee80211_ptr; |
| 11971 | |
| 11972 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 11973 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 11974 | goto nla_put_failure; |
| 11975 | } |
| 11976 | |
| 11977 | if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event)) |
| 11978 | goto nla_put_failure; |
| 11979 | |
| 11980 | if (nl80211_send_chandef(msg, chandef)) |
| 11981 | goto nla_put_failure; |
| 11982 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 11983 | genlmsg_end(msg, hdr); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 11984 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11985 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11986 | NL80211_MCGRP_MLME, gfp); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 11987 | return; |
| 11988 | |
| 11989 | nla_put_failure: |
| 11990 | genlmsg_cancel(msg, hdr); |
| 11991 | nlmsg_free(msg); |
| 11992 | } |
| 11993 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11994 | void cfg80211_cqm_pktloss_notify(struct net_device *dev, |
| 11995 | const u8 *peer, u32 num_packets, gfp_t gfp) |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 11996 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11997 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11998 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11999 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 12000 | struct sk_buff *msg; |
| 12001 | struct nlattr *pinfoattr; |
| 12002 | void *hdr; |
| 12003 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12004 | trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets); |
| 12005 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 12006 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 12007 | if (!msg) |
| 12008 | return; |
| 12009 | |
| 12010 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 12011 | if (!hdr) { |
| 12012 | nlmsg_free(msg); |
| 12013 | return; |
| 12014 | } |
| 12015 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12016 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12017 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12018 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
| 12019 | goto nla_put_failure; |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 12020 | |
| 12021 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 12022 | if (!pinfoattr) |
| 12023 | goto nla_put_failure; |
| 12024 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12025 | if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets)) |
| 12026 | goto nla_put_failure; |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 12027 | |
| 12028 | nla_nest_end(msg, pinfoattr); |
| 12029 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 12030 | genlmsg_end(msg, hdr); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 12031 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12032 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12033 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 12034 | return; |
| 12035 | |
| 12036 | nla_put_failure: |
| 12037 | genlmsg_cancel(msg, hdr); |
| 12038 | nlmsg_free(msg); |
| 12039 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12040 | EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 12041 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 12042 | void cfg80211_probe_status(struct net_device *dev, const u8 *addr, |
| 12043 | u64 cookie, bool acked, gfp_t gfp) |
| 12044 | { |
| 12045 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12046 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 12047 | struct sk_buff *msg; |
| 12048 | void *hdr; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 12049 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 12050 | trace_cfg80211_probe_status(dev, addr, cookie, acked); |
| 12051 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 12052 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 12053 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 12054 | if (!msg) |
| 12055 | return; |
| 12056 | |
| 12057 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); |
| 12058 | if (!hdr) { |
| 12059 | nlmsg_free(msg); |
| 12060 | return; |
| 12061 | } |
| 12062 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12063 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 12064 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 12065 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 12066 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || |
| 12067 | (acked && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 12068 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 12069 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 12070 | genlmsg_end(msg, hdr); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 12071 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12072 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12073 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 12074 | return; |
| 12075 | |
| 12076 | nla_put_failure: |
| 12077 | genlmsg_cancel(msg, hdr); |
| 12078 | nlmsg_free(msg); |
| 12079 | } |
| 12080 | EXPORT_SYMBOL(cfg80211_probe_status); |
| 12081 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 12082 | void cfg80211_report_obss_beacon(struct wiphy *wiphy, |
| 12083 | const u8 *frame, size_t len, |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 12084 | int freq, int sig_dbm) |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 12085 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12086 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 12087 | struct sk_buff *msg; |
| 12088 | void *hdr; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 12089 | struct cfg80211_beacon_registration *reg; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 12090 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 12091 | trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm); |
| 12092 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 12093 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 12094 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 12095 | msg = nlmsg_new(len + 100, GFP_ATOMIC); |
| 12096 | if (!msg) { |
| 12097 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 12098 | return; |
| 12099 | } |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 12100 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 12101 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
| 12102 | if (!hdr) |
| 12103 | goto nla_put_failure; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 12104 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 12105 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 12106 | (freq && |
| 12107 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || |
| 12108 | (sig_dbm && |
| 12109 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
| 12110 | nla_put(msg, NL80211_ATTR_FRAME, len, frame)) |
| 12111 | goto nla_put_failure; |
| 12112 | |
| 12113 | genlmsg_end(msg, hdr); |
| 12114 | |
| 12115 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 12116 | } |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 12117 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 12118 | return; |
| 12119 | |
| 12120 | nla_put_failure: |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 12121 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 12122 | if (hdr) |
| 12123 | genlmsg_cancel(msg, hdr); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 12124 | nlmsg_free(msg); |
| 12125 | } |
| 12126 | EXPORT_SYMBOL(cfg80211_report_obss_beacon); |
| 12127 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 12128 | #ifdef CONFIG_PM |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame^] | 12129 | static int cfg80211_net_detect_results(struct sk_buff *msg, |
| 12130 | struct cfg80211_wowlan_wakeup *wakeup) |
| 12131 | { |
| 12132 | struct cfg80211_wowlan_nd_info *nd = wakeup->net_detect; |
| 12133 | struct nlattr *nl_results, *nl_match, *nl_freqs; |
| 12134 | int i, j; |
| 12135 | |
| 12136 | nl_results = nla_nest_start( |
| 12137 | msg, NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS); |
| 12138 | if (!nl_results) |
| 12139 | return -EMSGSIZE; |
| 12140 | |
| 12141 | for (i = 0; i < nd->n_matches; i++) { |
| 12142 | struct cfg80211_wowlan_nd_match *match = nd->matches[i]; |
| 12143 | |
| 12144 | nl_match = nla_nest_start(msg, i); |
| 12145 | if (!nl_match) |
| 12146 | break; |
| 12147 | |
| 12148 | /* The SSID attribute is optional in nl80211, but for |
| 12149 | * simplicity reasons it's always present in the |
| 12150 | * cfg80211 structure. If a driver can't pass the |
| 12151 | * SSID, that needs to be changed. A zero length SSID |
| 12152 | * is still a valid SSID (wildcard), so it cannot be |
| 12153 | * used for this purpose. |
| 12154 | */ |
| 12155 | if (nla_put(msg, NL80211_ATTR_SSID, match->ssid.ssid_len, |
| 12156 | match->ssid.ssid)) { |
| 12157 | nla_nest_cancel(msg, nl_match); |
| 12158 | goto out; |
| 12159 | } |
| 12160 | |
| 12161 | if (match->n_channels) { |
| 12162 | nl_freqs = nla_nest_start( |
| 12163 | msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 12164 | if (!nl_freqs) { |
| 12165 | nla_nest_cancel(msg, nl_match); |
| 12166 | goto out; |
| 12167 | } |
| 12168 | |
| 12169 | for (j = 0; j < match->n_channels; j++) { |
| 12170 | if (nla_put_u32(msg, |
| 12171 | NL80211_ATTR_WIPHY_FREQ, |
| 12172 | match->channels[j])) { |
| 12173 | nla_nest_cancel(msg, nl_freqs); |
| 12174 | nla_nest_cancel(msg, nl_match); |
| 12175 | goto out; |
| 12176 | } |
| 12177 | } |
| 12178 | |
| 12179 | nla_nest_end(msg, nl_freqs); |
| 12180 | } |
| 12181 | |
| 12182 | nla_nest_end(msg, nl_match); |
| 12183 | } |
| 12184 | |
| 12185 | out: |
| 12186 | nla_nest_end(msg, nl_results); |
| 12187 | return 0; |
| 12188 | } |
| 12189 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 12190 | void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev, |
| 12191 | struct cfg80211_wowlan_wakeup *wakeup, |
| 12192 | gfp_t gfp) |
| 12193 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12194 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 12195 | struct sk_buff *msg; |
| 12196 | void *hdr; |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 12197 | int size = 200; |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 12198 | |
| 12199 | trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup); |
| 12200 | |
| 12201 | if (wakeup) |
| 12202 | size += wakeup->packet_present_len; |
| 12203 | |
| 12204 | msg = nlmsg_new(size, gfp); |
| 12205 | if (!msg) |
| 12206 | return; |
| 12207 | |
| 12208 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN); |
| 12209 | if (!hdr) |
| 12210 | goto free_msg; |
| 12211 | |
| 12212 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 12213 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 12214 | goto free_msg; |
| 12215 | |
| 12216 | if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 12217 | wdev->netdev->ifindex)) |
| 12218 | goto free_msg; |
| 12219 | |
| 12220 | if (wakeup) { |
| 12221 | struct nlattr *reasons; |
| 12222 | |
| 12223 | reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
Johannes Berg | 7fa322c | 2013-10-25 11:16:58 +0200 | [diff] [blame] | 12224 | if (!reasons) |
| 12225 | goto free_msg; |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 12226 | |
| 12227 | if (wakeup->disconnect && |
| 12228 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) |
| 12229 | goto free_msg; |
| 12230 | if (wakeup->magic_pkt && |
| 12231 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) |
| 12232 | goto free_msg; |
| 12233 | if (wakeup->gtk_rekey_failure && |
| 12234 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) |
| 12235 | goto free_msg; |
| 12236 | if (wakeup->eap_identity_req && |
| 12237 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) |
| 12238 | goto free_msg; |
| 12239 | if (wakeup->four_way_handshake && |
| 12240 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) |
| 12241 | goto free_msg; |
| 12242 | if (wakeup->rfkill_release && |
| 12243 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)) |
| 12244 | goto free_msg; |
| 12245 | |
| 12246 | if (wakeup->pattern_idx >= 0 && |
| 12247 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 12248 | wakeup->pattern_idx)) |
| 12249 | goto free_msg; |
| 12250 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 12251 | if (wakeup->tcp_match && |
| 12252 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH)) |
| 12253 | goto free_msg; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 12254 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 12255 | if (wakeup->tcp_connlost && |
| 12256 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST)) |
| 12257 | goto free_msg; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 12258 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 12259 | if (wakeup->tcp_nomoretokens && |
| 12260 | nla_put_flag(msg, |
| 12261 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS)) |
| 12262 | goto free_msg; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 12263 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 12264 | if (wakeup->packet) { |
| 12265 | u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211; |
| 12266 | u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN; |
| 12267 | |
| 12268 | if (!wakeup->packet_80211) { |
| 12269 | pkt_attr = |
| 12270 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023; |
| 12271 | len_attr = |
| 12272 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN; |
| 12273 | } |
| 12274 | |
| 12275 | if (wakeup->packet_len && |
| 12276 | nla_put_u32(msg, len_attr, wakeup->packet_len)) |
| 12277 | goto free_msg; |
| 12278 | |
| 12279 | if (nla_put(msg, pkt_attr, wakeup->packet_present_len, |
| 12280 | wakeup->packet)) |
| 12281 | goto free_msg; |
| 12282 | } |
| 12283 | |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame^] | 12284 | if (wakeup->net_detect && |
| 12285 | cfg80211_net_detect_results(msg, wakeup)) |
| 12286 | goto free_msg; |
| 12287 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 12288 | nla_nest_end(msg, reasons); |
| 12289 | } |
| 12290 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 12291 | genlmsg_end(msg, hdr); |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 12292 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12293 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12294 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 12295 | return; |
| 12296 | |
| 12297 | free_msg: |
| 12298 | nlmsg_free(msg); |
| 12299 | } |
| 12300 | EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup); |
| 12301 | #endif |
| 12302 | |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 12303 | void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer, |
| 12304 | enum nl80211_tdls_operation oper, |
| 12305 | u16 reason_code, gfp_t gfp) |
| 12306 | { |
| 12307 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12308 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 12309 | struct sk_buff *msg; |
| 12310 | void *hdr; |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 12311 | |
| 12312 | trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper, |
| 12313 | reason_code); |
| 12314 | |
| 12315 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 12316 | if (!msg) |
| 12317 | return; |
| 12318 | |
| 12319 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER); |
| 12320 | if (!hdr) { |
| 12321 | nlmsg_free(msg); |
| 12322 | return; |
| 12323 | } |
| 12324 | |
| 12325 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 12326 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 12327 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) || |
| 12328 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) || |
| 12329 | (reason_code > 0 && |
| 12330 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) |
| 12331 | goto nla_put_failure; |
| 12332 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 12333 | genlmsg_end(msg, hdr); |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 12334 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12335 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12336 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 12337 | return; |
| 12338 | |
| 12339 | nla_put_failure: |
| 12340 | genlmsg_cancel(msg, hdr); |
| 12341 | nlmsg_free(msg); |
| 12342 | } |
| 12343 | EXPORT_SYMBOL(cfg80211_tdls_oper_request); |
| 12344 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12345 | static int nl80211_netlink_notify(struct notifier_block * nb, |
| 12346 | unsigned long state, |
| 12347 | void *_notify) |
| 12348 | { |
| 12349 | struct netlink_notify *notify = _notify; |
| 12350 | struct cfg80211_registered_device *rdev; |
| 12351 | struct wireless_dev *wdev; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 12352 | struct cfg80211_beacon_registration *reg, *tmp; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12353 | |
| 12354 | if (state != NETLINK_URELEASE) |
| 12355 | return NOTIFY_DONE; |
| 12356 | |
| 12357 | rcu_read_lock(); |
| 12358 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 12359 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 12360 | bool schedule_destroy_work = false; |
| 12361 | |
| 12362 | list_for_each_entry_rcu(wdev, &rdev->wdev_list, list) { |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 12363 | cfg80211_mlme_unregister_socket(wdev, notify->portid); |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 12364 | |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 12365 | if (wdev->owner_nlportid == notify->portid) |
| 12366 | schedule_destroy_work = true; |
| 12367 | } |
| 12368 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 12369 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 12370 | list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations, |
| 12371 | list) { |
| 12372 | if (reg->nlportid == notify->portid) { |
| 12373 | list_del(®->list); |
| 12374 | kfree(reg); |
| 12375 | break; |
| 12376 | } |
| 12377 | } |
| 12378 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 12379 | |
| 12380 | if (schedule_destroy_work) { |
| 12381 | struct cfg80211_iface_destroy *destroy; |
| 12382 | |
| 12383 | destroy = kzalloc(sizeof(*destroy), GFP_ATOMIC); |
| 12384 | if (destroy) { |
| 12385 | destroy->nlportid = notify->portid; |
| 12386 | spin_lock(&rdev->destroy_list_lock); |
| 12387 | list_add(&destroy->list, &rdev->destroy_list); |
| 12388 | spin_unlock(&rdev->destroy_list_lock); |
| 12389 | schedule_work(&rdev->destroy_work); |
| 12390 | } |
| 12391 | } |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 12392 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12393 | |
| 12394 | rcu_read_unlock(); |
| 12395 | |
Zhao, Gang | 6784c7d | 2014-04-21 12:53:04 +0800 | [diff] [blame] | 12396 | return NOTIFY_OK; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12397 | } |
| 12398 | |
| 12399 | static struct notifier_block nl80211_netlink_notifier = { |
| 12400 | .notifier_call = nl80211_netlink_notify, |
| 12401 | }; |
| 12402 | |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 12403 | void cfg80211_ft_event(struct net_device *netdev, |
| 12404 | struct cfg80211_ft_event_params *ft_event) |
| 12405 | { |
| 12406 | struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12407 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 12408 | struct sk_buff *msg; |
| 12409 | void *hdr; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 12410 | |
| 12411 | trace_cfg80211_ft_event(wiphy, netdev, ft_event); |
| 12412 | |
| 12413 | if (!ft_event->target_ap) |
| 12414 | return; |
| 12415 | |
| 12416 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 12417 | if (!msg) |
| 12418 | return; |
| 12419 | |
| 12420 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT); |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 12421 | if (!hdr) |
| 12422 | goto out; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 12423 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 12424 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 12425 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 12426 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap)) |
| 12427 | goto out; |
| 12428 | |
| 12429 | if (ft_event->ies && |
| 12430 | nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies)) |
| 12431 | goto out; |
| 12432 | if (ft_event->ric_ies && |
| 12433 | nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len, |
| 12434 | ft_event->ric_ies)) |
| 12435 | goto out; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 12436 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 12437 | genlmsg_end(msg, hdr); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 12438 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12439 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12440 | NL80211_MCGRP_MLME, GFP_KERNEL); |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 12441 | return; |
| 12442 | out: |
| 12443 | nlmsg_free(msg); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 12444 | } |
| 12445 | EXPORT_SYMBOL(cfg80211_ft_event); |
| 12446 | |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 12447 | void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp) |
| 12448 | { |
| 12449 | struct cfg80211_registered_device *rdev; |
| 12450 | struct sk_buff *msg; |
| 12451 | void *hdr; |
| 12452 | u32 nlportid; |
| 12453 | |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12454 | rdev = wiphy_to_rdev(wdev->wiphy); |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 12455 | if (!rdev->crit_proto_nlportid) |
| 12456 | return; |
| 12457 | |
| 12458 | nlportid = rdev->crit_proto_nlportid; |
| 12459 | rdev->crit_proto_nlportid = 0; |
| 12460 | |
| 12461 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 12462 | if (!msg) |
| 12463 | return; |
| 12464 | |
| 12465 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP); |
| 12466 | if (!hdr) |
| 12467 | goto nla_put_failure; |
| 12468 | |
| 12469 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 12470 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 12471 | goto nla_put_failure; |
| 12472 | |
| 12473 | genlmsg_end(msg, hdr); |
| 12474 | |
| 12475 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
| 12476 | return; |
| 12477 | |
| 12478 | nla_put_failure: |
| 12479 | if (hdr) |
| 12480 | genlmsg_cancel(msg, hdr); |
| 12481 | nlmsg_free(msg); |
| 12482 | |
| 12483 | } |
| 12484 | EXPORT_SYMBOL(cfg80211_crit_proto_stopped); |
| 12485 | |
Johannes Berg | 348baf0 | 2014-01-24 14:06:29 +0100 | [diff] [blame] | 12486 | void nl80211_send_ap_stopped(struct wireless_dev *wdev) |
| 12487 | { |
| 12488 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12489 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 348baf0 | 2014-01-24 14:06:29 +0100 | [diff] [blame] | 12490 | struct sk_buff *msg; |
| 12491 | void *hdr; |
| 12492 | |
| 12493 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 12494 | if (!msg) |
| 12495 | return; |
| 12496 | |
| 12497 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP); |
| 12498 | if (!hdr) |
| 12499 | goto out; |
| 12500 | |
| 12501 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 12502 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) || |
| 12503 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 12504 | goto out; |
| 12505 | |
| 12506 | genlmsg_end(msg, hdr); |
| 12507 | |
| 12508 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0, |
| 12509 | NL80211_MCGRP_MLME, GFP_KERNEL); |
| 12510 | return; |
| 12511 | out: |
| 12512 | nlmsg_free(msg); |
| 12513 | } |
| 12514 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 12515 | /* initialisation/exit functions */ |
| 12516 | |
| 12517 | int nl80211_init(void) |
| 12518 | { |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 12519 | int err; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 12520 | |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12521 | err = genl_register_family_with_ops_groups(&nl80211_fam, nl80211_ops, |
| 12522 | nl80211_mcgrps); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 12523 | if (err) |
| 12524 | return err; |
| 12525 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12526 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
| 12527 | if (err) |
| 12528 | goto err_out; |
| 12529 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 12530 | return 0; |
| 12531 | err_out: |
| 12532 | genl_unregister_family(&nl80211_fam); |
| 12533 | return err; |
| 12534 | } |
| 12535 | |
| 12536 | void nl80211_exit(void) |
| 12537 | { |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12538 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 12539 | genl_unregister_family(&nl80211_fam); |
| 12540 | } |