Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1 | /* |
| 2 | * This is the new netlink-based wireless configuration interface. |
| 3 | * |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4 | * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <linux/if.h> |
| 8 | #include <linux/module.h> |
| 9 | #include <linux/err.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 10 | #include <linux/slab.h> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11 | #include <linux/list.h> |
| 12 | #include <linux/if_ether.h> |
| 13 | #include <linux/ieee80211.h> |
| 14 | #include <linux/nl80211.h> |
| 15 | #include <linux/rtnetlink.h> |
| 16 | #include <linux/netlink.h> |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 17 | #include <linux/etherdevice.h> |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 18 | #include <net/net_namespace.h> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 19 | #include <net/genetlink.h> |
| 20 | #include <net/cfg80211.h> |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 21 | #include <net/sock.h> |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 22 | #include <net/inet_connection_sock.h> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 23 | #include "core.h" |
| 24 | #include "nl80211.h" |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 25 | #include "reg.h" |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 26 | #include "rdev-ops.h" |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 27 | |
Jouni Malinen | 5fb628e | 2011-08-10 23:54:35 +0300 | [diff] [blame] | 28 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 29 | struct genl_info *info, |
| 30 | struct cfg80211_crypto_settings *settings, |
| 31 | int cipher_limit); |
| 32 | |
Johannes Berg | f84f771 | 2013-11-14 17:14:45 +0100 | [diff] [blame] | 33 | static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 34 | struct genl_info *info); |
Johannes Berg | f84f771 | 2013-11-14 17:14:45 +0100 | [diff] [blame] | 35 | static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 36 | struct genl_info *info); |
| 37 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 38 | /* the netlink family */ |
| 39 | static struct genl_family nl80211_fam = { |
Marcel Holtmann | fb4e156 | 2013-04-28 16:22:06 -0700 | [diff] [blame] | 40 | .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */ |
| 41 | .name = NL80211_GENL_NAME, /* have users key off the name instead */ |
| 42 | .hdrsize = 0, /* no private header */ |
| 43 | .version = 1, /* no particular meaning now */ |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 44 | .maxattr = NL80211_ATTR_MAX, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 45 | .netnsok = true, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 46 | .pre_doit = nl80211_pre_doit, |
| 47 | .post_doit = nl80211_post_doit, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 48 | }; |
| 49 | |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 50 | /* multicast groups */ |
| 51 | enum nl80211_multicast_groups { |
| 52 | NL80211_MCGRP_CONFIG, |
| 53 | NL80211_MCGRP_SCAN, |
| 54 | NL80211_MCGRP_REGULATORY, |
| 55 | NL80211_MCGRP_MLME, |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 56 | NL80211_MCGRP_VENDOR, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 57 | NL80211_MCGRP_TESTMODE /* keep last - ifdef! */ |
| 58 | }; |
| 59 | |
| 60 | static const struct genl_multicast_group nl80211_mcgrps[] = { |
| 61 | [NL80211_MCGRP_CONFIG] = { .name = "config", }, |
| 62 | [NL80211_MCGRP_SCAN] = { .name = "scan", }, |
| 63 | [NL80211_MCGRP_REGULATORY] = { .name = "regulatory", }, |
| 64 | [NL80211_MCGRP_MLME] = { .name = "mlme", }, |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 65 | [NL80211_MCGRP_VENDOR] = { .name = "vendor", }, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 66 | #ifdef CONFIG_NL80211_TESTMODE |
| 67 | [NL80211_MCGRP_TESTMODE] = { .name = "testmode", } |
| 68 | #endif |
| 69 | }; |
| 70 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 71 | /* returns ERR_PTR values */ |
| 72 | static struct wireless_dev * |
| 73 | __cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 74 | { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 75 | struct cfg80211_registered_device *rdev; |
| 76 | struct wireless_dev *result = NULL; |
| 77 | bool have_ifidx = attrs[NL80211_ATTR_IFINDEX]; |
| 78 | bool have_wdev_id = attrs[NL80211_ATTR_WDEV]; |
| 79 | u64 wdev_id; |
| 80 | int wiphy_idx = -1; |
| 81 | int ifidx = -1; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 82 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 83 | ASSERT_RTNL(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 84 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 85 | if (!have_ifidx && !have_wdev_id) |
| 86 | return ERR_PTR(-EINVAL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 87 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 88 | if (have_ifidx) |
| 89 | ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); |
| 90 | if (have_wdev_id) { |
| 91 | wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); |
| 92 | wiphy_idx = wdev_id >> 32; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 93 | } |
| 94 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 95 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 96 | struct wireless_dev *wdev; |
| 97 | |
| 98 | if (wiphy_net(&rdev->wiphy) != netns) |
| 99 | continue; |
| 100 | |
| 101 | if (have_wdev_id && rdev->wiphy_idx != wiphy_idx) |
| 102 | continue; |
| 103 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 104 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
| 105 | if (have_ifidx && wdev->netdev && |
| 106 | wdev->netdev->ifindex == ifidx) { |
| 107 | result = wdev; |
| 108 | break; |
| 109 | } |
| 110 | if (have_wdev_id && wdev->identifier == (u32)wdev_id) { |
| 111 | result = wdev; |
| 112 | break; |
| 113 | } |
| 114 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 115 | |
| 116 | if (result) |
| 117 | break; |
| 118 | } |
| 119 | |
| 120 | if (result) |
| 121 | return result; |
| 122 | return ERR_PTR(-ENODEV); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 123 | } |
| 124 | |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 125 | static struct cfg80211_registered_device * |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 126 | __cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs) |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 127 | { |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 128 | struct cfg80211_registered_device *rdev = NULL, *tmp; |
| 129 | struct net_device *netdev; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 130 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 131 | ASSERT_RTNL(); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 132 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 133 | if (!attrs[NL80211_ATTR_WIPHY] && |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 134 | !attrs[NL80211_ATTR_IFINDEX] && |
| 135 | !attrs[NL80211_ATTR_WDEV]) |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 136 | return ERR_PTR(-EINVAL); |
| 137 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 138 | if (attrs[NL80211_ATTR_WIPHY]) |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 139 | rdev = cfg80211_rdev_by_wiphy_idx( |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 140 | nla_get_u32(attrs[NL80211_ATTR_WIPHY])); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 141 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 142 | if (attrs[NL80211_ATTR_WDEV]) { |
| 143 | u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); |
| 144 | struct wireless_dev *wdev; |
| 145 | bool found = false; |
| 146 | |
| 147 | tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32); |
| 148 | if (tmp) { |
| 149 | /* make sure wdev exists */ |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 150 | list_for_each_entry(wdev, &tmp->wdev_list, list) { |
| 151 | if (wdev->identifier != (u32)wdev_id) |
| 152 | continue; |
| 153 | found = true; |
| 154 | break; |
| 155 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 156 | |
| 157 | if (!found) |
| 158 | tmp = NULL; |
| 159 | |
| 160 | if (rdev && tmp != rdev) |
| 161 | return ERR_PTR(-EINVAL); |
| 162 | rdev = tmp; |
| 163 | } |
| 164 | } |
| 165 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 166 | if (attrs[NL80211_ATTR_IFINDEX]) { |
| 167 | int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 168 | netdev = __dev_get_by_index(netns, ifindex); |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 169 | if (netdev) { |
| 170 | if (netdev->ieee80211_ptr) |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 171 | tmp = wiphy_to_rdev( |
| 172 | netdev->ieee80211_ptr->wiphy); |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 173 | else |
| 174 | tmp = NULL; |
| 175 | |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 176 | /* not wireless device -- return error */ |
| 177 | if (!tmp) |
| 178 | return ERR_PTR(-EINVAL); |
| 179 | |
| 180 | /* mismatch -- return error */ |
| 181 | if (rdev && tmp != rdev) |
| 182 | return ERR_PTR(-EINVAL); |
| 183 | |
| 184 | rdev = tmp; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 185 | } |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 186 | } |
| 187 | |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 188 | if (!rdev) |
| 189 | return ERR_PTR(-ENODEV); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 190 | |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 191 | if (netns != wiphy_net(&rdev->wiphy)) |
| 192 | return ERR_PTR(-ENODEV); |
| 193 | |
| 194 | return rdev; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | /* |
| 198 | * This function returns a pointer to the driver |
| 199 | * that the genl_info item that is passed refers to. |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 200 | * |
| 201 | * The result of this can be a PTR_ERR and hence must |
| 202 | * be checked with IS_ERR() for errors. |
| 203 | */ |
| 204 | static struct cfg80211_registered_device * |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 205 | cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info) |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 206 | { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 207 | return __cfg80211_rdev_from_attrs(netns, info->attrs); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 208 | } |
| 209 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 210 | /* policy for the attributes */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 211 | static const struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] = { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 212 | [NL80211_ATTR_WIPHY] = { .type = NLA_U32 }, |
| 213 | [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING, |
David S. Miller | 079e24e | 2009-05-26 21:15:00 -0700 | [diff] [blame] | 214 | .len = 20-1 }, |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 215 | [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED }, |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 216 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 217 | [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 }, |
Sujith | 094d05d | 2008-12-12 11:57:43 +0530 | [diff] [blame] | 218 | [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 219 | [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 }, |
| 220 | [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 }, |
| 221 | [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 }, |
| 222 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 223 | [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 }, |
| 224 | [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 }, |
| 225 | [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 }, |
| 226 | [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 }, |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 227 | [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 228 | |
| 229 | [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 }, |
| 230 | [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 }, |
| 231 | [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 232 | |
Eliad Peller | e007b85 | 2011-11-24 18:13:56 +0200 | [diff] [blame] | 233 | [NL80211_ATTR_MAC] = { .len = ETH_ALEN }, |
| 234 | [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 235 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 236 | [NL80211_ATTR_KEY] = { .type = NLA_NESTED, }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 237 | [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY, |
| 238 | .len = WLAN_MAX_KEY_LEN }, |
| 239 | [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 }, |
| 240 | [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 }, |
| 241 | [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG }, |
Jouni Malinen | 8196226 | 2011-11-02 23:36:31 +0200 | [diff] [blame] | 242 | [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 243 | [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 244 | |
| 245 | [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 }, |
| 246 | [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 }, |
| 247 | [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY, |
| 248 | .len = IEEE80211_MAX_DATA_LEN }, |
| 249 | [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY, |
| 250 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 251 | [NL80211_ATTR_STA_AID] = { .type = NLA_U16 }, |
| 252 | [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED }, |
| 253 | [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 }, |
| 254 | [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY, |
| 255 | .len = NL80211_MAX_SUPP_RATES }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 256 | [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 257 | [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 }, |
Johannes Berg | 0a9542e | 2008-10-15 11:54:04 +0200 | [diff] [blame] | 258 | [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 259 | [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 260 | .len = IEEE80211_MAX_MESH_ID_LEN }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 261 | [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 262 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 263 | [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 }, |
| 264 | [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED }, |
| 265 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 266 | [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 }, |
| 267 | [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 }, |
| 268 | [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 }, |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 269 | [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY, |
| 270 | .len = NL80211_MAX_SUPP_RATES }, |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 271 | [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 }, |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 272 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 273 | [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 274 | [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 275 | |
Johannes Berg | 6c73941 | 2011-11-03 09:27:01 +0100 | [diff] [blame] | 276 | [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 277 | |
| 278 | [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 }, |
| 279 | [NL80211_ATTR_IE] = { .type = NLA_BINARY, |
| 280 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 281 | [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED }, |
| 282 | [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 283 | |
| 284 | [NL80211_ATTR_SSID] = { .type = NLA_BINARY, |
| 285 | .len = IEEE80211_MAX_SSID_LEN }, |
| 286 | [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 }, |
| 287 | [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 288 | [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG }, |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 289 | [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG }, |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 290 | [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 }, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 291 | [NL80211_ATTR_STA_FLAGS2] = { |
| 292 | .len = sizeof(struct nl80211_sta_flag_update), |
| 293 | }, |
Jouni Malinen | 3f77316c | 2009-05-11 21:57:57 +0300 | [diff] [blame] | 294 | [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG }, |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 295 | [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 }, |
| 296 | [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG }, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 297 | [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG }, |
| 298 | [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 }, |
| 299 | [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 300 | [NL80211_ATTR_PID] = { .type = NLA_U32 }, |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 301 | [NL80211_ATTR_4ADDR] = { .type = NLA_U8 }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 302 | [NL80211_ATTR_PMKID] = { .type = NLA_BINARY, |
| 303 | .len = WLAN_PMKID_LEN }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 304 | [NL80211_ATTR_DURATION] = { .type = NLA_U32 }, |
| 305 | [NL80211_ATTR_COOKIE] = { .type = NLA_U64 }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 306 | [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 307 | [NL80211_ATTR_FRAME] = { .type = NLA_BINARY, |
| 308 | .len = IEEE80211_MAX_DATA_LEN }, |
| 309 | [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 310 | [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 311 | [NL80211_ATTR_CQM] = { .type = NLA_NESTED, }, |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 312 | [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG }, |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 313 | [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 }, |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 314 | [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 }, |
| 315 | [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 }, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 316 | [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 }, |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 317 | [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 }, |
| 318 | [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 }, |
Felix Fietkau | 885a46d | 2010-11-11 15:07:22 +0100 | [diff] [blame] | 319 | [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 }, |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 320 | [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 321 | [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 322 | [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED }, |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 323 | [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 }, |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 324 | [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 }, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 325 | [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED }, |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 326 | [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED }, |
Jouni Malinen | 32e9de8 | 2011-08-10 23:53:31 +0300 | [diff] [blame] | 327 | [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 }, |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 328 | [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY, |
| 329 | .len = IEEE80211_MAX_DATA_LEN }, |
| 330 | [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY, |
| 331 | .len = IEEE80211_MAX_DATA_LEN }, |
Vivek Natarajan | f4b34b5 | 2011-08-29 14:23:03 +0530 | [diff] [blame] | 332 | [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG }, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 333 | [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED }, |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 334 | [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 335 | [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 }, |
| 336 | [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 }, |
| 337 | [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 }, |
| 338 | [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG }, |
| 339 | [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG }, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 340 | [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG }, |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 341 | [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY, |
| 342 | .len = IEEE80211_MAX_DATA_LEN }, |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 343 | [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 }, |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 344 | [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG }, |
| 345 | [NL80211_ATTR_HT_CAPABILITY_MASK] = { |
| 346 | .len = NL80211_HT_CAPABILITY_LEN |
| 347 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 348 | [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 }, |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 349 | [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 }, |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 350 | [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 }, |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 351 | [NL80211_ATTR_WDEV] = { .type = NLA_U64 }, |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 352 | [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 }, |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 353 | [NL80211_ATTR_SAE_DATA] = { .type = NLA_BINARY, }, |
Mahesh Palivela | f461be3e | 2012-10-11 08:04:52 +0000 | [diff] [blame] | 354 | [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN }, |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 355 | [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 }, |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 356 | [NL80211_ATTR_P2P_CTWINDOW] = { .type = NLA_U8 }, |
| 357 | [NL80211_ATTR_P2P_OPPPS] = { .type = NLA_U8 }, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 358 | [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 }, |
| 359 | [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED }, |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 360 | [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 }, |
| 361 | [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, }, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 362 | [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, }, |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 363 | [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG }, |
| 364 | [NL80211_ATTR_VHT_CAPABILITY_MASK] = { |
| 365 | .len = NL80211_VHT_CAPABILITY_LEN, |
| 366 | }, |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 367 | [NL80211_ATTR_MDID] = { .type = NLA_U16 }, |
| 368 | [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY, |
| 369 | .len = IEEE80211_MAX_DATA_LEN }, |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 370 | [NL80211_ATTR_PEER_AID] = { .type = NLA_U16 }, |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 371 | [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 }, |
| 372 | [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG }, |
| 373 | [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED }, |
| 374 | [NL80211_ATTR_CSA_C_OFF_BEACON] = { .type = NLA_U16 }, |
| 375 | [NL80211_ATTR_CSA_C_OFF_PRESP] = { .type = NLA_U16 }, |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 376 | [NL80211_ATTR_STA_SUPPORTED_CHANNELS] = { .type = NLA_BINARY }, |
| 377 | [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES] = { .type = NLA_BINARY }, |
Simon Wunderlich | 5336fa8 | 2013-10-07 18:41:05 +0200 | [diff] [blame] | 378 | [NL80211_ATTR_HANDLE_DFS] = { .type = NLA_FLAG }, |
Marek Kwaczynski | 60f4a7b | 2013-12-03 10:04:59 +0100 | [diff] [blame] | 379 | [NL80211_ATTR_OPMODE_NOTIF] = { .type = NLA_U8 }, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 380 | [NL80211_ATTR_VENDOR_ID] = { .type = NLA_U32 }, |
| 381 | [NL80211_ATTR_VENDOR_SUBCMD] = { .type = NLA_U32 }, |
| 382 | [NL80211_ATTR_VENDOR_DATA] = { .type = NLA_BINARY }, |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 383 | [NL80211_ATTR_QOS_MAP] = { .type = NLA_BINARY, |
| 384 | .len = IEEE80211_QOS_MAP_LEN_MAX }, |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 385 | [NL80211_ATTR_MAC_HINT] = { .len = ETH_ALEN }, |
| 386 | [NL80211_ATTR_WIPHY_FREQ_HINT] = { .type = NLA_U32 }, |
Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 387 | [NL80211_ATTR_TDLS_PEER_CAPABILITY] = { .type = NLA_U32 }, |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 388 | [NL80211_ATTR_IFACE_SOCKET_OWNER] = { .type = NLA_FLAG }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 389 | }; |
| 390 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 391 | /* policy for the key attributes */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 392 | static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 393 | [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 394 | [NL80211_KEY_IDX] = { .type = NLA_U8 }, |
| 395 | [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, |
Jouni Malinen | 8196226 | 2011-11-02 23:36:31 +0200 | [diff] [blame] | 396 | [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 397 | [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, |
| 398 | [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 399 | [NL80211_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 400 | [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
| 401 | }; |
| 402 | |
| 403 | /* policy for the key default flags */ |
| 404 | static const struct nla_policy |
| 405 | nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = { |
| 406 | [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG }, |
| 407 | [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 408 | }; |
| 409 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 410 | /* policy for WoWLAN attributes */ |
| 411 | static const struct nla_policy |
| 412 | nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = { |
| 413 | [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG }, |
| 414 | [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG }, |
| 415 | [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG }, |
| 416 | [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED }, |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 417 | [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG }, |
| 418 | [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG }, |
| 419 | [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG }, |
| 420 | [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG }, |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 421 | [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED }, |
| 422 | }; |
| 423 | |
| 424 | static const struct nla_policy |
| 425 | nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = { |
| 426 | [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 }, |
| 427 | [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 }, |
| 428 | [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN }, |
| 429 | [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 }, |
| 430 | [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 }, |
| 431 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 }, |
| 432 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = { |
| 433 | .len = sizeof(struct nl80211_wowlan_tcp_data_seq) |
| 434 | }, |
| 435 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = { |
| 436 | .len = sizeof(struct nl80211_wowlan_tcp_data_token) |
| 437 | }, |
| 438 | [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 }, |
| 439 | [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 }, |
| 440 | [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 441 | }; |
| 442 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 443 | /* policy for coalesce rule attributes */ |
| 444 | static const struct nla_policy |
| 445 | nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = { |
| 446 | [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 }, |
| 447 | [NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 }, |
| 448 | [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED }, |
| 449 | }; |
| 450 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 451 | /* policy for GTK rekey offload attributes */ |
| 452 | static const struct nla_policy |
| 453 | nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = { |
| 454 | [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN }, |
| 455 | [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN }, |
| 456 | [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN }, |
| 457 | }; |
| 458 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 459 | static const struct nla_policy |
| 460 | nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = { |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 461 | [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 462 | .len = IEEE80211_MAX_SSID_LEN }, |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 463 | [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 }, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 464 | }; |
| 465 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 466 | static int nl80211_prepare_wdev_dump(struct sk_buff *skb, |
| 467 | struct netlink_callback *cb, |
| 468 | struct cfg80211_registered_device **rdev, |
| 469 | struct wireless_dev **wdev) |
Holger Schurig | a043897 | 2009-11-11 11:30:02 +0100 | [diff] [blame] | 470 | { |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 471 | int err; |
| 472 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 473 | rtnl_lock(); |
| 474 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 475 | if (!cb->args[0]) { |
| 476 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 477 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 478 | nl80211_policy); |
| 479 | if (err) |
| 480 | goto out_unlock; |
| 481 | |
| 482 | *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk), |
| 483 | nl80211_fam.attrbuf); |
| 484 | if (IS_ERR(*wdev)) { |
| 485 | err = PTR_ERR(*wdev); |
| 486 | goto out_unlock; |
| 487 | } |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 488 | *rdev = wiphy_to_rdev((*wdev)->wiphy); |
Johannes Berg | c319d50 | 2013-07-30 22:34:28 +0200 | [diff] [blame] | 489 | /* 0 is the first index - add 1 to parse only once */ |
| 490 | cb->args[0] = (*rdev)->wiphy_idx + 1; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 491 | cb->args[1] = (*wdev)->identifier; |
| 492 | } else { |
Johannes Berg | c319d50 | 2013-07-30 22:34:28 +0200 | [diff] [blame] | 493 | /* subtract the 1 again here */ |
| 494 | struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1); |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 495 | struct wireless_dev *tmp; |
| 496 | |
| 497 | if (!wiphy) { |
| 498 | err = -ENODEV; |
| 499 | goto out_unlock; |
| 500 | } |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 501 | *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 502 | *wdev = NULL; |
| 503 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 504 | list_for_each_entry(tmp, &(*rdev)->wdev_list, list) { |
| 505 | if (tmp->identifier == cb->args[1]) { |
| 506 | *wdev = tmp; |
| 507 | break; |
| 508 | } |
| 509 | } |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 510 | |
| 511 | if (!*wdev) { |
| 512 | err = -ENODEV; |
| 513 | goto out_unlock; |
| 514 | } |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 515 | } |
| 516 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 517 | return 0; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 518 | out_unlock: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 519 | rtnl_unlock(); |
| 520 | return err; |
| 521 | } |
| 522 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 523 | static void nl80211_finish_wdev_dump(struct cfg80211_registered_device *rdev) |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 524 | { |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 525 | rtnl_unlock(); |
| 526 | } |
| 527 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 528 | /* IE validation */ |
| 529 | static bool is_valid_ie_attr(const struct nlattr *attr) |
| 530 | { |
| 531 | const u8 *pos; |
| 532 | int len; |
| 533 | |
| 534 | if (!attr) |
| 535 | return true; |
| 536 | |
| 537 | pos = nla_data(attr); |
| 538 | len = nla_len(attr); |
| 539 | |
| 540 | while (len) { |
| 541 | u8 elemlen; |
| 542 | |
| 543 | if (len < 2) |
| 544 | return false; |
| 545 | len -= 2; |
| 546 | |
| 547 | elemlen = pos[1]; |
| 548 | if (elemlen > len) |
| 549 | return false; |
| 550 | |
| 551 | len -= elemlen; |
| 552 | pos += 2 + elemlen; |
| 553 | } |
| 554 | |
| 555 | return true; |
| 556 | } |
| 557 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 558 | /* message building helper */ |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 559 | 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] | 560 | int flags, u8 cmd) |
| 561 | { |
| 562 | /* since there is no private header just add the generic one */ |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 563 | return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 564 | } |
| 565 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 566 | static int nl80211_msg_put_channel(struct sk_buff *msg, |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 567 | struct ieee80211_channel *chan, |
| 568 | bool large) |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 569 | { |
Rostislav Lisovy | ea077c1 | 2014-04-15 14:37:55 +0200 | [diff] [blame^] | 570 | /* Some channels must be completely excluded from the |
| 571 | * list to protect old user-space tools from breaking |
| 572 | */ |
| 573 | if (!large && chan->flags & |
| 574 | (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ)) |
| 575 | return 0; |
| 576 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 577 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
| 578 | chan->center_freq)) |
| 579 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 580 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 581 | if ((chan->flags & IEEE80211_CHAN_DISABLED) && |
| 582 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED)) |
| 583 | goto nla_put_failure; |
Luis R. Rodriguez | 8fe02e1 | 2013-10-21 19:22:25 +0200 | [diff] [blame] | 584 | if (chan->flags & IEEE80211_CHAN_NO_IR) { |
| 585 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR)) |
| 586 | goto nla_put_failure; |
| 587 | if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS)) |
| 588 | goto nla_put_failure; |
| 589 | } |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 590 | if (chan->flags & IEEE80211_CHAN_RADAR) { |
| 591 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR)) |
| 592 | goto nla_put_failure; |
| 593 | if (large) { |
| 594 | u32 time; |
| 595 | |
| 596 | time = elapsed_jiffies_msecs(chan->dfs_state_entered); |
| 597 | |
| 598 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE, |
| 599 | chan->dfs_state)) |
| 600 | goto nla_put_failure; |
| 601 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME, |
| 602 | time)) |
| 603 | goto nla_put_failure; |
Janusz Dziedzic | 089027e | 2014-02-21 19:46:12 +0100 | [diff] [blame] | 604 | if (nla_put_u32(msg, |
| 605 | NL80211_FREQUENCY_ATTR_DFS_CAC_TIME, |
| 606 | chan->dfs_cac_ms)) |
| 607 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 608 | } |
| 609 | } |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 610 | |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 611 | if (large) { |
| 612 | if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) && |
| 613 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS)) |
| 614 | goto nla_put_failure; |
| 615 | if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) && |
| 616 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS)) |
| 617 | goto nla_put_failure; |
| 618 | if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) && |
| 619 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ)) |
| 620 | goto nla_put_failure; |
| 621 | if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) && |
| 622 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ)) |
| 623 | goto nla_put_failure; |
David Spinadel | 570dbde | 2014-02-23 09:12:59 +0200 | [diff] [blame] | 624 | if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) && |
| 625 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY)) |
| 626 | goto nla_put_failure; |
| 627 | if ((chan->flags & IEEE80211_CHAN_GO_CONCURRENT) && |
| 628 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_GO_CONCURRENT)) |
| 629 | goto nla_put_failure; |
Rostislav Lisovy | ea077c1 | 2014-04-15 14:37:55 +0200 | [diff] [blame^] | 630 | if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) && |
| 631 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ)) |
| 632 | goto nla_put_failure; |
| 633 | if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) && |
| 634 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ)) |
| 635 | goto nla_put_failure; |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 636 | } |
| 637 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 638 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
| 639 | DBM_TO_MBM(chan->max_power))) |
| 640 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 641 | |
| 642 | return 0; |
| 643 | |
| 644 | nla_put_failure: |
| 645 | return -ENOBUFS; |
| 646 | } |
| 647 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 648 | /* netlink command implementations */ |
| 649 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 650 | struct key_parse { |
| 651 | struct key_params p; |
| 652 | int idx; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 653 | int type; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 654 | bool def, defmgmt; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 655 | bool def_uni, def_multi; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 656 | }; |
| 657 | |
| 658 | static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k) |
| 659 | { |
| 660 | struct nlattr *tb[NL80211_KEY_MAX + 1]; |
| 661 | int err = nla_parse_nested(tb, NL80211_KEY_MAX, key, |
| 662 | nl80211_key_policy); |
| 663 | if (err) |
| 664 | return err; |
| 665 | |
| 666 | k->def = !!tb[NL80211_KEY_DEFAULT]; |
| 667 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; |
| 668 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 669 | if (k->def) { |
| 670 | k->def_uni = true; |
| 671 | k->def_multi = true; |
| 672 | } |
| 673 | if (k->defmgmt) |
| 674 | k->def_multi = true; |
| 675 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 676 | if (tb[NL80211_KEY_IDX]) |
| 677 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); |
| 678 | |
| 679 | if (tb[NL80211_KEY_DATA]) { |
| 680 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); |
| 681 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); |
| 682 | } |
| 683 | |
| 684 | if (tb[NL80211_KEY_SEQ]) { |
| 685 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); |
| 686 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); |
| 687 | } |
| 688 | |
| 689 | if (tb[NL80211_KEY_CIPHER]) |
| 690 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); |
| 691 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 692 | if (tb[NL80211_KEY_TYPE]) { |
| 693 | k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); |
| 694 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 695 | return -EINVAL; |
| 696 | } |
| 697 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 698 | if (tb[NL80211_KEY_DEFAULT_TYPES]) { |
| 699 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
Johannes Berg | 2da8f41 | 2012-01-20 13:52:37 +0100 | [diff] [blame] | 700 | err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 701 | tb[NL80211_KEY_DEFAULT_TYPES], |
| 702 | nl80211_key_default_policy); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 703 | if (err) |
| 704 | return err; |
| 705 | |
| 706 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 707 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 708 | } |
| 709 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 710 | return 0; |
| 711 | } |
| 712 | |
| 713 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) |
| 714 | { |
| 715 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { |
| 716 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 717 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 718 | } |
| 719 | |
| 720 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { |
| 721 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 722 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 723 | } |
| 724 | |
| 725 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 726 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 727 | |
| 728 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) |
| 729 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); |
| 730 | |
| 731 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; |
| 732 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; |
| 733 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 734 | if (k->def) { |
| 735 | k->def_uni = true; |
| 736 | k->def_multi = true; |
| 737 | } |
| 738 | if (k->defmgmt) |
| 739 | k->def_multi = true; |
| 740 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 741 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 742 | k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 743 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 744 | return -EINVAL; |
| 745 | } |
| 746 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 747 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { |
| 748 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
| 749 | int err = nla_parse_nested( |
| 750 | kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 751 | info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], |
| 752 | nl80211_key_default_policy); |
| 753 | if (err) |
| 754 | return err; |
| 755 | |
| 756 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 757 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 758 | } |
| 759 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 760 | return 0; |
| 761 | } |
| 762 | |
| 763 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) |
| 764 | { |
| 765 | int err; |
| 766 | |
| 767 | memset(k, 0, sizeof(*k)); |
| 768 | k->idx = -1; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 769 | k->type = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 770 | |
| 771 | if (info->attrs[NL80211_ATTR_KEY]) |
| 772 | err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k); |
| 773 | else |
| 774 | err = nl80211_parse_key_old(info, k); |
| 775 | |
| 776 | if (err) |
| 777 | return err; |
| 778 | |
| 779 | if (k->def && k->defmgmt) |
| 780 | return -EINVAL; |
| 781 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 782 | if (k->defmgmt) { |
| 783 | if (k->def_uni || !k->def_multi) |
| 784 | return -EINVAL; |
| 785 | } |
| 786 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 787 | if (k->idx != -1) { |
| 788 | if (k->defmgmt) { |
| 789 | if (k->idx < 4 || k->idx > 5) |
| 790 | return -EINVAL; |
| 791 | } else if (k->def) { |
| 792 | if (k->idx < 0 || k->idx > 3) |
| 793 | return -EINVAL; |
| 794 | } else { |
| 795 | if (k->idx < 0 || k->idx > 5) |
| 796 | return -EINVAL; |
| 797 | } |
| 798 | } |
| 799 | |
| 800 | return 0; |
| 801 | } |
| 802 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 803 | static struct cfg80211_cached_keys * |
| 804 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 805 | struct nlattr *keys, bool *no_ht) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 806 | { |
| 807 | struct key_parse parse; |
| 808 | struct nlattr *key; |
| 809 | struct cfg80211_cached_keys *result; |
| 810 | int rem, err, def = 0; |
| 811 | |
| 812 | result = kzalloc(sizeof(*result), GFP_KERNEL); |
| 813 | if (!result) |
| 814 | return ERR_PTR(-ENOMEM); |
| 815 | |
| 816 | result->def = -1; |
| 817 | result->defmgmt = -1; |
| 818 | |
| 819 | nla_for_each_nested(key, keys, rem) { |
| 820 | memset(&parse, 0, sizeof(parse)); |
| 821 | parse.idx = -1; |
| 822 | |
| 823 | err = nl80211_parse_key_new(key, &parse); |
| 824 | if (err) |
| 825 | goto error; |
| 826 | err = -EINVAL; |
| 827 | if (!parse.p.key) |
| 828 | goto error; |
| 829 | if (parse.idx < 0 || parse.idx > 4) |
| 830 | goto error; |
| 831 | if (parse.def) { |
| 832 | if (def) |
| 833 | goto error; |
| 834 | def = 1; |
| 835 | result->def = parse.idx; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 836 | if (!parse.def_uni || !parse.def_multi) |
| 837 | goto error; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 838 | } else if (parse.defmgmt) |
| 839 | goto error; |
| 840 | err = cfg80211_validate_key_settings(rdev, &parse.p, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 841 | parse.idx, false, NULL); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 842 | if (err) |
| 843 | goto error; |
| 844 | result->params[parse.idx].cipher = parse.p.cipher; |
| 845 | result->params[parse.idx].key_len = parse.p.key_len; |
| 846 | result->params[parse.idx].key = result->data[parse.idx]; |
| 847 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 848 | |
| 849 | if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 || |
| 850 | parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) { |
| 851 | if (no_ht) |
| 852 | *no_ht = true; |
| 853 | } |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 854 | } |
| 855 | |
| 856 | return result; |
| 857 | error: |
| 858 | kfree(result); |
| 859 | return ERR_PTR(err); |
| 860 | } |
| 861 | |
| 862 | static int nl80211_key_allowed(struct wireless_dev *wdev) |
| 863 | { |
| 864 | ASSERT_WDEV_LOCK(wdev); |
| 865 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 866 | switch (wdev->iftype) { |
| 867 | case NL80211_IFTYPE_AP: |
| 868 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 869 | case NL80211_IFTYPE_P2P_GO: |
Thomas Pedersen | ff973af | 2011-05-03 16:57:12 -0700 | [diff] [blame] | 870 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 871 | break; |
| 872 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 873 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 874 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 875 | if (!wdev->current_bss) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 876 | return -ENOLINK; |
| 877 | break; |
| 878 | default: |
| 879 | return -EINVAL; |
| 880 | } |
| 881 | |
| 882 | return 0; |
| 883 | } |
| 884 | |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 885 | static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy, |
| 886 | struct nlattr *tb) |
| 887 | { |
| 888 | struct ieee80211_channel *chan; |
| 889 | |
| 890 | if (tb == NULL) |
| 891 | return NULL; |
| 892 | chan = ieee80211_get_channel(wiphy, nla_get_u32(tb)); |
| 893 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) |
| 894 | return NULL; |
| 895 | return chan; |
| 896 | } |
| 897 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 898 | static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) |
| 899 | { |
| 900 | struct nlattr *nl_modes = nla_nest_start(msg, attr); |
| 901 | int i; |
| 902 | |
| 903 | if (!nl_modes) |
| 904 | goto nla_put_failure; |
| 905 | |
| 906 | i = 0; |
| 907 | while (ifmodes) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 908 | if ((ifmodes & 1) && nla_put_flag(msg, i)) |
| 909 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 910 | ifmodes >>= 1; |
| 911 | i++; |
| 912 | } |
| 913 | |
| 914 | nla_nest_end(msg, nl_modes); |
| 915 | return 0; |
| 916 | |
| 917 | nla_put_failure: |
| 918 | return -ENOBUFS; |
| 919 | } |
| 920 | |
| 921 | static int nl80211_put_iface_combinations(struct wiphy *wiphy, |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 922 | struct sk_buff *msg, |
| 923 | bool large) |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 924 | { |
| 925 | struct nlattr *nl_combis; |
| 926 | int i, j; |
| 927 | |
| 928 | nl_combis = nla_nest_start(msg, |
| 929 | NL80211_ATTR_INTERFACE_COMBINATIONS); |
| 930 | if (!nl_combis) |
| 931 | goto nla_put_failure; |
| 932 | |
| 933 | for (i = 0; i < wiphy->n_iface_combinations; i++) { |
| 934 | const struct ieee80211_iface_combination *c; |
| 935 | struct nlattr *nl_combi, *nl_limits; |
| 936 | |
| 937 | c = &wiphy->iface_combinations[i]; |
| 938 | |
| 939 | nl_combi = nla_nest_start(msg, i + 1); |
| 940 | if (!nl_combi) |
| 941 | goto nla_put_failure; |
| 942 | |
| 943 | nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS); |
| 944 | if (!nl_limits) |
| 945 | goto nla_put_failure; |
| 946 | |
| 947 | for (j = 0; j < c->n_limits; j++) { |
| 948 | struct nlattr *nl_limit; |
| 949 | |
| 950 | nl_limit = nla_nest_start(msg, j + 1); |
| 951 | if (!nl_limit) |
| 952 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 953 | if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX, |
| 954 | c->limits[j].max)) |
| 955 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 956 | if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, |
| 957 | c->limits[j].types)) |
| 958 | goto nla_put_failure; |
| 959 | nla_nest_end(msg, nl_limit); |
| 960 | } |
| 961 | |
| 962 | nla_nest_end(msg, nl_limits); |
| 963 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 964 | if (c->beacon_int_infra_match && |
| 965 | nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH)) |
| 966 | goto nla_put_failure; |
| 967 | if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, |
| 968 | c->num_different_channels) || |
| 969 | nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM, |
| 970 | c->max_interfaces)) |
| 971 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 972 | if (large && |
| 973 | nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS, |
| 974 | c->radar_detect_widths)) |
| 975 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 976 | |
| 977 | nla_nest_end(msg, nl_combi); |
| 978 | } |
| 979 | |
| 980 | nla_nest_end(msg, nl_combis); |
| 981 | |
| 982 | return 0; |
| 983 | nla_put_failure: |
| 984 | return -ENOBUFS; |
| 985 | } |
| 986 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 987 | #ifdef CONFIG_PM |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 988 | static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev, |
| 989 | struct sk_buff *msg) |
| 990 | { |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 991 | const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp; |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 992 | struct nlattr *nl_tcp; |
| 993 | |
| 994 | if (!tcp) |
| 995 | return 0; |
| 996 | |
| 997 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); |
| 998 | if (!nl_tcp) |
| 999 | return -ENOBUFS; |
| 1000 | |
| 1001 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 1002 | tcp->data_payload_max)) |
| 1003 | return -ENOBUFS; |
| 1004 | |
| 1005 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 1006 | tcp->data_payload_max)) |
| 1007 | return -ENOBUFS; |
| 1008 | |
| 1009 | if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ)) |
| 1010 | return -ENOBUFS; |
| 1011 | |
| 1012 | if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, |
| 1013 | sizeof(*tcp->tok), tcp->tok)) |
| 1014 | return -ENOBUFS; |
| 1015 | |
| 1016 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, |
| 1017 | tcp->data_interval_max)) |
| 1018 | return -ENOBUFS; |
| 1019 | |
| 1020 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, |
| 1021 | tcp->wake_payload_max)) |
| 1022 | return -ENOBUFS; |
| 1023 | |
| 1024 | nla_nest_end(msg, nl_tcp); |
| 1025 | return 0; |
| 1026 | } |
| 1027 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1028 | static int nl80211_send_wowlan(struct sk_buff *msg, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1029 | struct cfg80211_registered_device *rdev, |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1030 | bool large) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1031 | { |
| 1032 | struct nlattr *nl_wowlan; |
| 1033 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1034 | if (!rdev->wiphy.wowlan) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1035 | return 0; |
| 1036 | |
| 1037 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); |
| 1038 | if (!nl_wowlan) |
| 1039 | return -ENOBUFS; |
| 1040 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1041 | if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1042 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1043 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1044 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1045 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1046 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1047 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1048 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1049 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1050 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1051 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1052 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1053 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1054 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1055 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1056 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 1057 | return -ENOBUFS; |
| 1058 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1059 | if (rdev->wiphy.wowlan->n_patterns) { |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 1060 | struct nl80211_pattern_support pat = { |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1061 | .max_patterns = rdev->wiphy.wowlan->n_patterns, |
| 1062 | .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len, |
| 1063 | .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len, |
| 1064 | .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1065 | }; |
| 1066 | |
| 1067 | if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 1068 | sizeof(pat), &pat)) |
| 1069 | return -ENOBUFS; |
| 1070 | } |
| 1071 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1072 | if (large && nl80211_send_wowlan_tcp_caps(rdev, msg)) |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1073 | return -ENOBUFS; |
| 1074 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1075 | nla_nest_end(msg, nl_wowlan); |
| 1076 | |
| 1077 | return 0; |
| 1078 | } |
| 1079 | #endif |
| 1080 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1081 | static int nl80211_send_coalesce(struct sk_buff *msg, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1082 | struct cfg80211_registered_device *rdev) |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1083 | { |
| 1084 | struct nl80211_coalesce_rule_support rule; |
| 1085 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1086 | if (!rdev->wiphy.coalesce) |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1087 | return 0; |
| 1088 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1089 | rule.max_rules = rdev->wiphy.coalesce->n_rules; |
| 1090 | rule.max_delay = rdev->wiphy.coalesce->max_delay; |
| 1091 | rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns; |
| 1092 | rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len; |
| 1093 | rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len; |
| 1094 | rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset; |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1095 | |
| 1096 | if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule)) |
| 1097 | return -ENOBUFS; |
| 1098 | |
| 1099 | return 0; |
| 1100 | } |
| 1101 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1102 | static int nl80211_send_band_rateinfo(struct sk_buff *msg, |
| 1103 | struct ieee80211_supported_band *sband) |
| 1104 | { |
| 1105 | struct nlattr *nl_rates, *nl_rate; |
| 1106 | struct ieee80211_rate *rate; |
| 1107 | int i; |
| 1108 | |
| 1109 | /* add HT info */ |
| 1110 | if (sband->ht_cap.ht_supported && |
| 1111 | (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET, |
| 1112 | sizeof(sband->ht_cap.mcs), |
| 1113 | &sband->ht_cap.mcs) || |
| 1114 | nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA, |
| 1115 | sband->ht_cap.cap) || |
| 1116 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, |
| 1117 | sband->ht_cap.ampdu_factor) || |
| 1118 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, |
| 1119 | sband->ht_cap.ampdu_density))) |
| 1120 | return -ENOBUFS; |
| 1121 | |
| 1122 | /* add VHT info */ |
| 1123 | if (sband->vht_cap.vht_supported && |
| 1124 | (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET, |
| 1125 | sizeof(sband->vht_cap.vht_mcs), |
| 1126 | &sband->vht_cap.vht_mcs) || |
| 1127 | nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA, |
| 1128 | sband->vht_cap.cap))) |
| 1129 | return -ENOBUFS; |
| 1130 | |
| 1131 | /* add bitrates */ |
| 1132 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); |
| 1133 | if (!nl_rates) |
| 1134 | return -ENOBUFS; |
| 1135 | |
| 1136 | for (i = 0; i < sband->n_bitrates; i++) { |
| 1137 | nl_rate = nla_nest_start(msg, i); |
| 1138 | if (!nl_rate) |
| 1139 | return -ENOBUFS; |
| 1140 | |
| 1141 | rate = &sband->bitrates[i]; |
| 1142 | if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE, |
| 1143 | rate->bitrate)) |
| 1144 | return -ENOBUFS; |
| 1145 | if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) && |
| 1146 | nla_put_flag(msg, |
| 1147 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE)) |
| 1148 | return -ENOBUFS; |
| 1149 | |
| 1150 | nla_nest_end(msg, nl_rate); |
| 1151 | } |
| 1152 | |
| 1153 | nla_nest_end(msg, nl_rates); |
| 1154 | |
| 1155 | return 0; |
| 1156 | } |
| 1157 | |
| 1158 | static int |
| 1159 | nl80211_send_mgmt_stypes(struct sk_buff *msg, |
| 1160 | const struct ieee80211_txrx_stypes *mgmt_stypes) |
| 1161 | { |
| 1162 | u16 stypes; |
| 1163 | struct nlattr *nl_ftypes, *nl_ifs; |
| 1164 | enum nl80211_iftype ift; |
| 1165 | int i; |
| 1166 | |
| 1167 | if (!mgmt_stypes) |
| 1168 | return 0; |
| 1169 | |
| 1170 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES); |
| 1171 | if (!nl_ifs) |
| 1172 | return -ENOBUFS; |
| 1173 | |
| 1174 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 1175 | nl_ftypes = nla_nest_start(msg, ift); |
| 1176 | if (!nl_ftypes) |
| 1177 | return -ENOBUFS; |
| 1178 | i = 0; |
| 1179 | stypes = mgmt_stypes[ift].tx; |
| 1180 | while (stypes) { |
| 1181 | if ((stypes & 1) && |
| 1182 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1183 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1184 | return -ENOBUFS; |
| 1185 | stypes >>= 1; |
| 1186 | i++; |
| 1187 | } |
| 1188 | nla_nest_end(msg, nl_ftypes); |
| 1189 | } |
| 1190 | |
| 1191 | nla_nest_end(msg, nl_ifs); |
| 1192 | |
| 1193 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES); |
| 1194 | if (!nl_ifs) |
| 1195 | return -ENOBUFS; |
| 1196 | |
| 1197 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 1198 | nl_ftypes = nla_nest_start(msg, ift); |
| 1199 | if (!nl_ftypes) |
| 1200 | return -ENOBUFS; |
| 1201 | i = 0; |
| 1202 | stypes = mgmt_stypes[ift].rx; |
| 1203 | while (stypes) { |
| 1204 | if ((stypes & 1) && |
| 1205 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1206 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1207 | return -ENOBUFS; |
| 1208 | stypes >>= 1; |
| 1209 | i++; |
| 1210 | } |
| 1211 | nla_nest_end(msg, nl_ftypes); |
| 1212 | } |
| 1213 | nla_nest_end(msg, nl_ifs); |
| 1214 | |
| 1215 | return 0; |
| 1216 | } |
| 1217 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1218 | struct nl80211_dump_wiphy_state { |
| 1219 | s64 filter_wiphy; |
| 1220 | long start; |
| 1221 | long split_start, band_start, chan_start; |
| 1222 | bool split; |
| 1223 | }; |
| 1224 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1225 | static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1226 | struct sk_buff *msg, u32 portid, u32 seq, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1227 | int flags, struct nl80211_dump_wiphy_state *state) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1228 | { |
| 1229 | void *hdr; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1230 | struct nlattr *nl_bands, *nl_band; |
| 1231 | struct nlattr *nl_freqs, *nl_freq; |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1232 | struct nlattr *nl_cmds; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1233 | enum ieee80211_band band; |
| 1234 | struct ieee80211_channel *chan; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1235 | int i; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1236 | const struct ieee80211_txrx_stypes *mgmt_stypes = |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1237 | rdev->wiphy.mgmt_stypes; |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1238 | u32 features; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1239 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 1240 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_WIPHY); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1241 | if (!hdr) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1242 | return -ENOBUFS; |
| 1243 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1244 | if (WARN_ON(!state)) |
| 1245 | return -EINVAL; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1246 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1247 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1248 | nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1249 | wiphy_name(&rdev->wiphy)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1250 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1251 | cfg80211_rdev_list_generation)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1252 | goto nla_put_failure; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1253 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1254 | switch (state->split_start) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1255 | case 0: |
| 1256 | if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1257 | rdev->wiphy.retry_short) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1258 | nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1259 | rdev->wiphy.retry_long) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1260 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1261 | rdev->wiphy.frag_threshold) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1262 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1263 | rdev->wiphy.rts_threshold) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1264 | nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1265 | rdev->wiphy.coverage_class) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1266 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1267 | rdev->wiphy.max_scan_ssids) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1268 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1269 | rdev->wiphy.max_sched_scan_ssids) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1270 | nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1271 | rdev->wiphy.max_scan_ie_len) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1272 | nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1273 | rdev->wiphy.max_sched_scan_ie_len) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1274 | nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1275 | rdev->wiphy.max_match_sets)) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1276 | goto nla_put_failure; |
| 1277 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1278 | if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1279 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN)) |
| 1280 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1281 | if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1282 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH)) |
| 1283 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1284 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1285 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD)) |
| 1286 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1287 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1288 | nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT)) |
| 1289 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1290 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1291 | nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT)) |
| 1292 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1293 | if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1294 | nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1295 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1296 | state->split_start++; |
| 1297 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1298 | break; |
| 1299 | case 1: |
| 1300 | if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1301 | sizeof(u32) * rdev->wiphy.n_cipher_suites, |
| 1302 | rdev->wiphy.cipher_suites)) |
Mahesh Palivela | bf0c111e | 2012-06-22 07:27:46 +0000 | [diff] [blame] | 1303 | goto nla_put_failure; |
| 1304 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1305 | if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1306 | rdev->wiphy.max_num_pmkids)) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1307 | goto nla_put_failure; |
| 1308 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1309 | if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1310 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE)) |
| 1311 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1312 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1313 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1314 | rdev->wiphy.available_antennas_tx) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1315 | nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1316 | rdev->wiphy.available_antennas_rx)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1317 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1318 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1319 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1320 | nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1321 | rdev->wiphy.probe_resp_offload)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1322 | goto nla_put_failure; |
Jouni Malinen | e2f367f26 | 2008-11-21 19:01:30 +0200 | [diff] [blame] | 1323 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1324 | if ((rdev->wiphy.available_antennas_tx || |
| 1325 | rdev->wiphy.available_antennas_rx) && |
| 1326 | rdev->ops->get_antenna) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1327 | u32 tx_ant = 0, rx_ant = 0; |
| 1328 | int res; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1329 | res = rdev_get_antenna(rdev, &tx_ant, &rx_ant); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1330 | if (!res) { |
| 1331 | if (nla_put_u32(msg, |
| 1332 | NL80211_ATTR_WIPHY_ANTENNA_TX, |
| 1333 | tx_ant) || |
| 1334 | nla_put_u32(msg, |
| 1335 | NL80211_ATTR_WIPHY_ANTENNA_RX, |
| 1336 | rx_ant)) |
| 1337 | goto nla_put_failure; |
| 1338 | } |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1339 | } |
| 1340 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1341 | state->split_start++; |
| 1342 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1343 | break; |
| 1344 | case 2: |
| 1345 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1346 | rdev->wiphy.interface_modes)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1347 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1348 | state->split_start++; |
| 1349 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1350 | break; |
| 1351 | case 3: |
| 1352 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); |
| 1353 | if (!nl_bands) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1354 | goto nla_put_failure; |
| 1355 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1356 | for (band = state->band_start; |
| 1357 | band < IEEE80211_NUM_BANDS; band++) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1358 | struct ieee80211_supported_band *sband; |
| 1359 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1360 | sband = rdev->wiphy.bands[band]; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1361 | |
| 1362 | if (!sband) |
| 1363 | continue; |
| 1364 | |
| 1365 | nl_band = nla_nest_start(msg, band); |
| 1366 | if (!nl_band) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1367 | goto nla_put_failure; |
| 1368 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1369 | switch (state->chan_start) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1370 | case 0: |
| 1371 | if (nl80211_send_band_rateinfo(msg, sband)) |
| 1372 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1373 | state->chan_start++; |
| 1374 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1375 | break; |
| 1376 | default: |
| 1377 | /* add frequencies */ |
| 1378 | nl_freqs = nla_nest_start( |
| 1379 | msg, NL80211_BAND_ATTR_FREQS); |
| 1380 | if (!nl_freqs) |
| 1381 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1382 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1383 | for (i = state->chan_start - 1; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1384 | i < sband->n_channels; |
| 1385 | i++) { |
| 1386 | nl_freq = nla_nest_start(msg, i); |
| 1387 | if (!nl_freq) |
| 1388 | goto nla_put_failure; |
| 1389 | |
| 1390 | chan = &sband->channels[i]; |
| 1391 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1392 | if (nl80211_msg_put_channel( |
| 1393 | msg, chan, |
| 1394 | state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1395 | goto nla_put_failure; |
| 1396 | |
| 1397 | nla_nest_end(msg, nl_freq); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1398 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1399 | break; |
| 1400 | } |
| 1401 | if (i < sband->n_channels) |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1402 | state->chan_start = i + 2; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1403 | else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1404 | state->chan_start = 0; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1405 | nla_nest_end(msg, nl_freqs); |
| 1406 | } |
| 1407 | |
| 1408 | nla_nest_end(msg, nl_band); |
| 1409 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1410 | if (state->split) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1411 | /* start again here */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1412 | if (state->chan_start) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1413 | band--; |
| 1414 | break; |
| 1415 | } |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1416 | } |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1417 | nla_nest_end(msg, nl_bands); |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1418 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1419 | if (band < IEEE80211_NUM_BANDS) |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1420 | state->band_start = band + 1; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1421 | else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1422 | state->band_start = 0; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1423 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1424 | /* if bands & channels are done, continue outside */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1425 | if (state->band_start == 0 && state->chan_start == 0) |
| 1426 | state->split_start++; |
| 1427 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1428 | break; |
| 1429 | case 4: |
| 1430 | nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); |
| 1431 | if (!nl_cmds) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1432 | goto nla_put_failure; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1433 | |
| 1434 | i = 0; |
| 1435 | #define CMD(op, n) \ |
| 1436 | do { \ |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1437 | if (rdev->ops->op) { \ |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1438 | i++; \ |
| 1439 | if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \ |
| 1440 | goto nla_put_failure; \ |
| 1441 | } \ |
| 1442 | } while (0) |
| 1443 | |
| 1444 | CMD(add_virtual_intf, NEW_INTERFACE); |
| 1445 | CMD(change_virtual_intf, SET_INTERFACE); |
| 1446 | CMD(add_key, NEW_KEY); |
| 1447 | CMD(start_ap, START_AP); |
| 1448 | CMD(add_station, NEW_STATION); |
| 1449 | CMD(add_mpath, NEW_MPATH); |
| 1450 | CMD(update_mesh_config, SET_MESH_CONFIG); |
| 1451 | CMD(change_bss, SET_BSS); |
| 1452 | CMD(auth, AUTHENTICATE); |
| 1453 | CMD(assoc, ASSOCIATE); |
| 1454 | CMD(deauth, DEAUTHENTICATE); |
| 1455 | CMD(disassoc, DISASSOCIATE); |
| 1456 | CMD(join_ibss, JOIN_IBSS); |
| 1457 | CMD(join_mesh, JOIN_MESH); |
| 1458 | CMD(set_pmksa, SET_PMKSA); |
| 1459 | CMD(del_pmksa, DEL_PMKSA); |
| 1460 | CMD(flush_pmksa, FLUSH_PMKSA); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1461 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1462 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); |
| 1463 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); |
| 1464 | CMD(mgmt_tx, FRAME); |
| 1465 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1466 | if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1467 | i++; |
| 1468 | if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS)) |
| 1469 | goto nla_put_failure; |
| 1470 | } |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1471 | if (rdev->ops->set_monitor_channel || rdev->ops->start_ap || |
| 1472 | rdev->ops->join_mesh) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1473 | i++; |
| 1474 | if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL)) |
| 1475 | goto nla_put_failure; |
| 1476 | } |
| 1477 | CMD(set_wds_peer, SET_WDS_PEER); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1478 | if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1479 | CMD(tdls_mgmt, TDLS_MGMT); |
| 1480 | CMD(tdls_oper, TDLS_OPER); |
| 1481 | } |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1482 | if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1483 | CMD(sched_scan_start, START_SCHED_SCAN); |
| 1484 | CMD(probe_client, PROBE_CLIENT); |
| 1485 | CMD(set_noack_map, SET_NOACK_MAP); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1486 | if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1487 | i++; |
| 1488 | if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS)) |
| 1489 | goto nla_put_failure; |
| 1490 | } |
| 1491 | CMD(start_p2p_device, START_P2P_DEVICE); |
| 1492 | CMD(set_mcast_rate, SET_MCAST_RATE); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1493 | if (state->split) { |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 1494 | CMD(crit_proto_start, CRIT_PROTOCOL_START); |
| 1495 | CMD(crit_proto_stop, CRIT_PROTOCOL_STOP); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1496 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 1497 | CMD(channel_switch, CHANNEL_SWITCH); |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 1498 | } |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 1499 | CMD(set_qos_map, SET_QOS_MAP); |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1500 | |
Kalle Valo | 4745fc0 | 2011-11-17 19:06:10 +0200 | [diff] [blame] | 1501 | #ifdef CONFIG_NL80211_TESTMODE |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1502 | CMD(testmode_cmd, TESTMODE); |
Kalle Valo | 4745fc0 | 2011-11-17 19:06:10 +0200 | [diff] [blame] | 1503 | #endif |
| 1504 | |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1505 | #undef CMD |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1506 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1507 | if (rdev->ops->connect || rdev->ops->auth) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1508 | i++; |
| 1509 | if (nla_put_u32(msg, i, NL80211_CMD_CONNECT)) |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1510 | goto nla_put_failure; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1511 | } |
| 1512 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1513 | if (rdev->ops->disconnect || rdev->ops->deauth) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1514 | i++; |
| 1515 | if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT)) |
| 1516 | goto nla_put_failure; |
| 1517 | } |
Johannes Berg | 74b70a4 | 2010-08-24 12:15:53 +0200 | [diff] [blame] | 1518 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1519 | nla_nest_end(msg, nl_cmds); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1520 | state->split_start++; |
| 1521 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1522 | break; |
| 1523 | case 5: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1524 | if (rdev->ops->remain_on_channel && |
| 1525 | (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1526 | nla_put_u32(msg, |
| 1527 | NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1528 | rdev->wiphy.max_remain_on_channel_duration)) |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1529 | goto nla_put_failure; |
| 1530 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1531 | if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1532 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) |
| 1533 | goto nla_put_failure; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1534 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1535 | if (nl80211_send_mgmt_stypes(msg, mgmt_stypes)) |
| 1536 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1537 | state->split_start++; |
| 1538 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1539 | break; |
| 1540 | case 6: |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 1541 | #ifdef CONFIG_PM |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1542 | if (nl80211_send_wowlan(msg, rdev, state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1543 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1544 | state->split_start++; |
| 1545 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1546 | break; |
| 1547 | #else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1548 | state->split_start++; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1549 | #endif |
| 1550 | case 7: |
| 1551 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1552 | rdev->wiphy.software_iftypes)) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1553 | goto nla_put_failure; |
| 1554 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1555 | if (nl80211_put_iface_combinations(&rdev->wiphy, msg, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1556 | state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1557 | goto nla_put_failure; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1558 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1559 | state->split_start++; |
| 1560 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1561 | break; |
| 1562 | case 8: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1563 | if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1564 | nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1565 | rdev->wiphy.ap_sme_capa)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1566 | goto nla_put_failure; |
| 1567 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1568 | features = rdev->wiphy.features; |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1569 | /* |
| 1570 | * We can only add the per-channel limit information if the |
| 1571 | * dump is split, otherwise it makes it too big. Therefore |
| 1572 | * only advertise it in that case. |
| 1573 | */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1574 | if (state->split) |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1575 | features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS; |
| 1576 | if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1577 | goto nla_put_failure; |
| 1578 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1579 | if (rdev->wiphy.ht_capa_mod_mask && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1580 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1581 | sizeof(*rdev->wiphy.ht_capa_mod_mask), |
| 1582 | rdev->wiphy.ht_capa_mod_mask)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1583 | goto nla_put_failure; |
| 1584 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1585 | if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME && |
| 1586 | rdev->wiphy.max_acl_mac_addrs && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1587 | nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1588 | rdev->wiphy.max_acl_mac_addrs)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1589 | goto nla_put_failure; |
| 1590 | |
| 1591 | /* |
| 1592 | * Any information below this point is only available to |
| 1593 | * applications that can deal with it being split. This |
| 1594 | * helps ensure that newly added capabilities don't break |
| 1595 | * older tools by overrunning their buffers. |
| 1596 | * |
| 1597 | * We still increment split_start so that in the split |
| 1598 | * case we'll continue with more data in the next round, |
| 1599 | * but break unconditionally so unsplit data stops here. |
| 1600 | */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1601 | state->split_start++; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1602 | break; |
| 1603 | case 9: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1604 | if (rdev->wiphy.extended_capabilities && |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1605 | (nla_put(msg, NL80211_ATTR_EXT_CAPA, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1606 | rdev->wiphy.extended_capabilities_len, |
| 1607 | rdev->wiphy.extended_capabilities) || |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1608 | nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1609 | rdev->wiphy.extended_capabilities_len, |
| 1610 | rdev->wiphy.extended_capabilities_mask))) |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1611 | goto nla_put_failure; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1612 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1613 | if (rdev->wiphy.vht_capa_mod_mask && |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 1614 | nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1615 | sizeof(*rdev->wiphy.vht_capa_mod_mask), |
| 1616 | rdev->wiphy.vht_capa_mod_mask)) |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 1617 | goto nla_put_failure; |
| 1618 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1619 | state->split_start++; |
| 1620 | break; |
| 1621 | case 10: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1622 | if (nl80211_send_coalesce(msg, rdev)) |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1623 | goto nla_put_failure; |
| 1624 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1625 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) && |
Felix Fietkau | 01e0daa | 2013-11-09 14:57:54 +0100 | [diff] [blame] | 1626 | (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) || |
| 1627 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ))) |
| 1628 | goto nla_put_failure; |
Jouni Malinen | b43504c | 2014-01-15 00:01:08 +0200 | [diff] [blame] | 1629 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1630 | if (rdev->wiphy.max_ap_assoc_sta && |
Jouni Malinen | b43504c | 2014-01-15 00:01:08 +0200 | [diff] [blame] | 1631 | nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1632 | rdev->wiphy.max_ap_assoc_sta)) |
Jouni Malinen | b43504c | 2014-01-15 00:01:08 +0200 | [diff] [blame] | 1633 | goto nla_put_failure; |
| 1634 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 1635 | state->split_start++; |
| 1636 | break; |
| 1637 | case 11: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1638 | if (rdev->wiphy.n_vendor_commands) { |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1639 | const struct nl80211_vendor_cmd_info *info; |
| 1640 | struct nlattr *nested; |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 1641 | |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1642 | nested = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); |
| 1643 | if (!nested) |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 1644 | goto nla_put_failure; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1645 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1646 | for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { |
| 1647 | info = &rdev->wiphy.vendor_commands[i].info; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1648 | if (nla_put(msg, i + 1, sizeof(*info), info)) |
| 1649 | goto nla_put_failure; |
| 1650 | } |
| 1651 | nla_nest_end(msg, nested); |
| 1652 | } |
| 1653 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1654 | if (rdev->wiphy.n_vendor_events) { |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1655 | const struct nl80211_vendor_cmd_info *info; |
| 1656 | struct nlattr *nested; |
| 1657 | |
| 1658 | nested = nla_nest_start(msg, |
| 1659 | NL80211_ATTR_VENDOR_EVENTS); |
| 1660 | if (!nested) |
| 1661 | goto nla_put_failure; |
| 1662 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1663 | for (i = 0; i < rdev->wiphy.n_vendor_events; i++) { |
| 1664 | info = &rdev->wiphy.vendor_events[i]; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1665 | if (nla_put(msg, i + 1, sizeof(*info), info)) |
| 1666 | goto nla_put_failure; |
| 1667 | } |
| 1668 | nla_nest_end(msg, nested); |
| 1669 | } |
Felix Fietkau | 01e0daa | 2013-11-09 14:57:54 +0100 | [diff] [blame] | 1670 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1671 | /* done */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1672 | state->split_start = 0; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1673 | break; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1674 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1675 | return genlmsg_end(msg, hdr); |
| 1676 | |
| 1677 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 1678 | genlmsg_cancel(msg, hdr); |
| 1679 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1680 | } |
| 1681 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1682 | static int nl80211_dump_wiphy_parse(struct sk_buff *skb, |
| 1683 | struct netlink_callback *cb, |
| 1684 | struct nl80211_dump_wiphy_state *state) |
| 1685 | { |
| 1686 | struct nlattr **tb = nl80211_fam.attrbuf; |
| 1687 | int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 1688 | tb, nl80211_fam.maxattr, nl80211_policy); |
| 1689 | /* ignore parse errors for backward compatibility */ |
| 1690 | if (ret) |
| 1691 | return 0; |
| 1692 | |
| 1693 | state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP]; |
| 1694 | if (tb[NL80211_ATTR_WIPHY]) |
| 1695 | state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]); |
| 1696 | if (tb[NL80211_ATTR_WDEV]) |
| 1697 | state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32; |
| 1698 | if (tb[NL80211_ATTR_IFINDEX]) { |
| 1699 | struct net_device *netdev; |
| 1700 | struct cfg80211_registered_device *rdev; |
| 1701 | int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); |
| 1702 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 1703 | netdev = __dev_get_by_index(sock_net(skb->sk), ifidx); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1704 | if (!netdev) |
| 1705 | return -ENODEV; |
| 1706 | if (netdev->ieee80211_ptr) { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 1707 | rdev = wiphy_to_rdev( |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1708 | netdev->ieee80211_ptr->wiphy); |
| 1709 | state->filter_wiphy = rdev->wiphy_idx; |
| 1710 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1711 | } |
| 1712 | |
| 1713 | return 0; |
| 1714 | } |
| 1715 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1716 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) |
| 1717 | { |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1718 | int idx = 0, ret; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1719 | struct nl80211_dump_wiphy_state *state = (void *)cb->args[0]; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1720 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 3a5a423 | 2013-06-19 10:09:57 +0200 | [diff] [blame] | 1721 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1722 | rtnl_lock(); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1723 | if (!state) { |
| 1724 | state = kzalloc(sizeof(*state), GFP_KERNEL); |
John W. Linville | 57ed5cd | 2013-06-28 13:18:21 -0400 | [diff] [blame] | 1725 | if (!state) { |
| 1726 | rtnl_unlock(); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1727 | return -ENOMEM; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1728 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1729 | state->filter_wiphy = -1; |
| 1730 | ret = nl80211_dump_wiphy_parse(skb, cb, state); |
| 1731 | if (ret) { |
| 1732 | kfree(state); |
| 1733 | rtnl_unlock(); |
| 1734 | return ret; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1735 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1736 | cb->args[0] = (long)state; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1737 | } |
| 1738 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1739 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 1740 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1741 | continue; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1742 | if (++idx <= state->start) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1743 | continue; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1744 | if (state->filter_wiphy != -1 && |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1745 | state->filter_wiphy != rdev->wiphy_idx) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1746 | continue; |
| 1747 | /* attempt to fit multiple wiphy data chunks into the skb */ |
| 1748 | do { |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1749 | ret = nl80211_send_wiphy(rdev, skb, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1750 | NETLINK_CB(cb->skb).portid, |
| 1751 | cb->nlh->nlmsg_seq, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1752 | NLM_F_MULTI, state); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1753 | if (ret < 0) { |
| 1754 | /* |
| 1755 | * If sending the wiphy data didn't fit (ENOBUFS |
| 1756 | * or EMSGSIZE returned), this SKB is still |
| 1757 | * empty (so it's not too big because another |
| 1758 | * wiphy dataset is already in the skb) and |
| 1759 | * we've not tried to adjust the dump allocation |
| 1760 | * yet ... then adjust the alloc size to be |
| 1761 | * bigger, and return 1 but with the empty skb. |
| 1762 | * This results in an empty message being RX'ed |
| 1763 | * in userspace, but that is ignored. |
| 1764 | * |
| 1765 | * We can then retry with the larger buffer. |
| 1766 | */ |
| 1767 | if ((ret == -ENOBUFS || ret == -EMSGSIZE) && |
Pontus Fuchs | f12cb28 | 2014-01-16 15:00:40 +0100 | [diff] [blame] | 1768 | !skb->len && !state->split && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1769 | cb->min_dump_alloc < 4096) { |
| 1770 | cb->min_dump_alloc = 4096; |
Pontus Fuchs | f12cb28 | 2014-01-16 15:00:40 +0100 | [diff] [blame] | 1771 | state->split_start = 0; |
David S. Miller | d98cae64e | 2013-06-19 16:49:39 -0700 | [diff] [blame] | 1772 | rtnl_unlock(); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1773 | return 1; |
| 1774 | } |
| 1775 | idx--; |
| 1776 | break; |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1777 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1778 | } while (state->split_start > 0); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1779 | break; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1780 | } |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1781 | rtnl_unlock(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1782 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1783 | state->start = idx; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1784 | |
| 1785 | return skb->len; |
| 1786 | } |
| 1787 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1788 | static int nl80211_dump_wiphy_done(struct netlink_callback *cb) |
| 1789 | { |
| 1790 | kfree((void *)cb->args[0]); |
| 1791 | return 0; |
| 1792 | } |
| 1793 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1794 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1795 | { |
| 1796 | struct sk_buff *msg; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1797 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1798 | struct nl80211_dump_wiphy_state state = {}; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1799 | |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1800 | msg = nlmsg_new(4096, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1801 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1802 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1803 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1804 | if (nl80211_send_wiphy(rdev, msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1805 | &state) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1806 | nlmsg_free(msg); |
| 1807 | return -ENOBUFS; |
| 1808 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1809 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 1810 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1811 | } |
| 1812 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1813 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
| 1814 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, |
| 1815 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, |
| 1816 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, |
| 1817 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, |
| 1818 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, |
| 1819 | }; |
| 1820 | |
| 1821 | static int parse_txq_params(struct nlattr *tb[], |
| 1822 | struct ieee80211_txq_params *txq_params) |
| 1823 | { |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1824 | if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] || |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1825 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
| 1826 | !tb[NL80211_TXQ_ATTR_AIFS]) |
| 1827 | return -EINVAL; |
| 1828 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1829 | txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1830 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
| 1831 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); |
| 1832 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); |
| 1833 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); |
| 1834 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1835 | if (txq_params->ac >= NL80211_NUM_ACS) |
| 1836 | return -EINVAL; |
| 1837 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1838 | return 0; |
| 1839 | } |
| 1840 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1841 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
| 1842 | { |
| 1843 | /* |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1844 | * You can only set the channel explicitly for WDS interfaces, |
| 1845 | * all others have their channel managed via their respective |
| 1846 | * "establish a connection" command (connect, join, ...) |
| 1847 | * |
| 1848 | * For AP/GO and mesh mode, the channel can be set with the |
| 1849 | * channel userspace API, but is only stored and passed to the |
| 1850 | * low-level driver when the AP starts or the mesh is joined. |
| 1851 | * This is for backward compatibility, userspace can also give |
| 1852 | * the channel in the start-ap or join-mesh commands instead. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1853 | * |
| 1854 | * Monitors are special as they are normally slaved to |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1855 | * whatever else is going on, so they have their own special |
| 1856 | * operation to set the monitor channel if possible. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1857 | */ |
| 1858 | return !wdev || |
| 1859 | wdev->iftype == NL80211_IFTYPE_AP || |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1860 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 1861 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
| 1862 | wdev->iftype == NL80211_IFTYPE_P2P_GO; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1863 | } |
| 1864 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1865 | static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev, |
| 1866 | struct genl_info *info, |
| 1867 | struct cfg80211_chan_def *chandef) |
| 1868 | { |
Mahesh Palivela | dbeca2e | 2012-11-29 14:11:07 +0530 | [diff] [blame] | 1869 | u32 control_freq; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1870 | |
| 1871 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 1872 | return -EINVAL; |
| 1873 | |
| 1874 | control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 1875 | |
| 1876 | chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1877 | chandef->width = NL80211_CHAN_WIDTH_20_NOHT; |
| 1878 | chandef->center_freq1 = control_freq; |
| 1879 | chandef->center_freq2 = 0; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1880 | |
| 1881 | /* Primary channel not allowed */ |
| 1882 | if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) |
| 1883 | return -EINVAL; |
| 1884 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1885 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 1886 | enum nl80211_channel_type chantype; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1887 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1888 | chantype = nla_get_u32( |
| 1889 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 1890 | |
| 1891 | switch (chantype) { |
| 1892 | case NL80211_CHAN_NO_HT: |
| 1893 | case NL80211_CHAN_HT20: |
| 1894 | case NL80211_CHAN_HT40PLUS: |
| 1895 | case NL80211_CHAN_HT40MINUS: |
| 1896 | cfg80211_chandef_create(chandef, chandef->chan, |
| 1897 | chantype); |
| 1898 | break; |
| 1899 | default: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1900 | return -EINVAL; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1901 | } |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1902 | } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) { |
| 1903 | chandef->width = |
| 1904 | nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]); |
| 1905 | if (info->attrs[NL80211_ATTR_CENTER_FREQ1]) |
| 1906 | chandef->center_freq1 = |
| 1907 | nla_get_u32( |
| 1908 | info->attrs[NL80211_ATTR_CENTER_FREQ1]); |
| 1909 | if (info->attrs[NL80211_ATTR_CENTER_FREQ2]) |
| 1910 | chandef->center_freq2 = |
| 1911 | nla_get_u32( |
| 1912 | info->attrs[NL80211_ATTR_CENTER_FREQ2]); |
| 1913 | } |
| 1914 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 1915 | if (!cfg80211_chandef_valid(chandef)) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1916 | return -EINVAL; |
| 1917 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 1918 | if (!cfg80211_chandef_usable(&rdev->wiphy, chandef, |
| 1919 | IEEE80211_CHAN_DISABLED)) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1920 | return -EINVAL; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1921 | |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 1922 | if ((chandef->width == NL80211_CHAN_WIDTH_5 || |
| 1923 | chandef->width == NL80211_CHAN_WIDTH_10) && |
| 1924 | !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ)) |
| 1925 | return -EINVAL; |
| 1926 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1927 | return 0; |
| 1928 | } |
| 1929 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1930 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
| 1931 | struct wireless_dev *wdev, |
| 1932 | struct genl_info *info) |
| 1933 | { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1934 | struct cfg80211_chan_def chandef; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1935 | int result; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1936 | enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR; |
| 1937 | |
| 1938 | if (wdev) |
| 1939 | iftype = wdev->iftype; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1940 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1941 | if (!nl80211_can_set_dev_channel(wdev)) |
| 1942 | return -EOPNOTSUPP; |
| 1943 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1944 | result = nl80211_parse_chandef(rdev, info, &chandef); |
| 1945 | if (result) |
| 1946 | return result; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1947 | |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1948 | switch (iftype) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1949 | case NL80211_IFTYPE_AP: |
| 1950 | case NL80211_IFTYPE_P2P_GO: |
| 1951 | if (wdev->beacon_interval) { |
| 1952 | result = -EBUSY; |
| 1953 | break; |
| 1954 | } |
Ilan Peer | 174e0cd | 2014-02-23 09:13:01 +0200 | [diff] [blame] | 1955 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef, iftype)) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1956 | result = -EINVAL; |
| 1957 | break; |
| 1958 | } |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1959 | wdev->preset_chandef = chandef; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1960 | result = 0; |
| 1961 | break; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1962 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1963 | result = cfg80211_set_mesh_channel(rdev, wdev, &chandef); |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1964 | break; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1965 | case NL80211_IFTYPE_MONITOR: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1966 | result = cfg80211_set_monitor_channel(rdev, &chandef); |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1967 | break; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1968 | default: |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1969 | result = -EINVAL; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1970 | } |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1971 | |
| 1972 | return result; |
| 1973 | } |
| 1974 | |
| 1975 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) |
| 1976 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1977 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1978 | struct net_device *netdev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1979 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1980 | return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1981 | } |
| 1982 | |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1983 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
| 1984 | { |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1985 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1986 | struct net_device *dev = info->user_ptr[1]; |
| 1987 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 388ac77 | 2010-10-07 13:11:09 +0200 | [diff] [blame] | 1988 | const u8 *bssid; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1989 | |
| 1990 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 1991 | return -EINVAL; |
| 1992 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1993 | if (netif_running(dev)) |
| 1994 | return -EBUSY; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1995 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1996 | if (!rdev->ops->set_wds_peer) |
| 1997 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1998 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1999 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
| 2000 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2001 | |
| 2002 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2003 | return rdev_set_wds_peer(rdev, dev, bssid); |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2004 | } |
| 2005 | |
| 2006 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2007 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 2008 | { |
| 2009 | struct cfg80211_registered_device *rdev; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2010 | struct net_device *netdev = NULL; |
| 2011 | struct wireless_dev *wdev; |
Bill Jordan | a1e567c | 2010-09-10 11:22:32 -0400 | [diff] [blame] | 2012 | int result = 0, rem_txq_params = 0; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2013 | struct nlattr *nl_txq_params; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2014 | u32 changed; |
| 2015 | u8 retry_short = 0, retry_long = 0; |
| 2016 | u32 frag_threshold = 0, rts_threshold = 0; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2017 | u8 coverage_class = 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2018 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2019 | ASSERT_RTNL(); |
| 2020 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2021 | /* |
| 2022 | * Try to find the wiphy and netdev. Normally this |
| 2023 | * function shouldn't need the netdev, but this is |
| 2024 | * done for backward compatibility -- previously |
| 2025 | * setting the channel was done per wiphy, but now |
| 2026 | * it is per netdev. Previous userland like hostapd |
| 2027 | * also passed a netdev to set_wiphy, so that it is |
| 2028 | * possible to let that go to the right netdev! |
| 2029 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2030 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2031 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
| 2032 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); |
| 2033 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2034 | netdev = __dev_get_by_index(genl_info_net(info), ifindex); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2035 | if (netdev && netdev->ieee80211_ptr) |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 2036 | rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2037 | else |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2038 | netdev = NULL; |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2039 | } |
| 2040 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2041 | if (!netdev) { |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 2042 | rdev = __cfg80211_rdev_from_attrs(genl_info_net(info), |
| 2043 | info->attrs); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2044 | if (IS_ERR(rdev)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2045 | return PTR_ERR(rdev); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2046 | wdev = NULL; |
| 2047 | netdev = NULL; |
| 2048 | result = 0; |
Johannes Berg | 71fe96b | 2012-10-24 10:04:58 +0200 | [diff] [blame] | 2049 | } else |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2050 | wdev = netdev->ieee80211_ptr; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2051 | |
| 2052 | /* |
| 2053 | * end workaround code, by now the rdev is available |
| 2054 | * and locked, and wdev may or may not be NULL. |
| 2055 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2056 | |
| 2057 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2058 | result = cfg80211_dev_rename( |
| 2059 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2060 | |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2061 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2062 | return result; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2063 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2064 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { |
| 2065 | struct ieee80211_txq_params txq_params; |
| 2066 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; |
| 2067 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2068 | if (!rdev->ops->set_txq_params) |
| 2069 | return -EOPNOTSUPP; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2070 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2071 | if (!netdev) |
| 2072 | return -EINVAL; |
Eliad Peller | f70f01c | 2011-09-25 20:06:53 +0300 | [diff] [blame] | 2073 | |
Johannes Berg | 133a3ff | 2011-11-03 14:50:13 +0100 | [diff] [blame] | 2074 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2075 | netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2076 | return -EINVAL; |
Johannes Berg | 133a3ff | 2011-11-03 14:50:13 +0100 | [diff] [blame] | 2077 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2078 | if (!netif_running(netdev)) |
| 2079 | return -ENETDOWN; |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 2080 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2081 | nla_for_each_nested(nl_txq_params, |
| 2082 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], |
| 2083 | rem_txq_params) { |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 2084 | result = nla_parse(tb, NL80211_TXQ_ATTR_MAX, |
| 2085 | nla_data(nl_txq_params), |
| 2086 | nla_len(nl_txq_params), |
| 2087 | txq_params_policy); |
| 2088 | if (result) |
| 2089 | return result; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2090 | result = parse_txq_params(tb, &txq_params); |
| 2091 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2092 | return result; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2093 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2094 | result = rdev_set_txq_params(rdev, netdev, |
| 2095 | &txq_params); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2096 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2097 | return result; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2098 | } |
| 2099 | } |
| 2100 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2101 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 71fe96b | 2012-10-24 10:04:58 +0200 | [diff] [blame] | 2102 | result = __nl80211_set_channel(rdev, |
| 2103 | nl80211_can_set_dev_channel(wdev) ? wdev : NULL, |
| 2104 | info); |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2105 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2106 | return result; |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2107 | } |
| 2108 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2109 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2110 | struct wireless_dev *txp_wdev = wdev; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2111 | enum nl80211_tx_power_setting type; |
| 2112 | int idx, mbm = 0; |
| 2113 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2114 | if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER)) |
| 2115 | txp_wdev = NULL; |
| 2116 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2117 | if (!rdev->ops->set_tx_power) |
| 2118 | return -EOPNOTSUPP; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2119 | |
| 2120 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; |
| 2121 | type = nla_get_u32(info->attrs[idx]); |
| 2122 | |
| 2123 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2124 | (type != NL80211_TX_POWER_AUTOMATIC)) |
| 2125 | return -EINVAL; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2126 | |
| 2127 | if (type != NL80211_TX_POWER_AUTOMATIC) { |
| 2128 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; |
| 2129 | mbm = nla_get_u32(info->attrs[idx]); |
| 2130 | } |
| 2131 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2132 | result = rdev_set_tx_power(rdev, txp_wdev, type, mbm); |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2133 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2134 | return result; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2135 | } |
| 2136 | |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2137 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
| 2138 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { |
| 2139 | u32 tx_ant, rx_ant; |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2140 | if ((!rdev->wiphy.available_antennas_tx && |
| 2141 | !rdev->wiphy.available_antennas_rx) || |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2142 | !rdev->ops->set_antenna) |
| 2143 | return -EOPNOTSUPP; |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2144 | |
| 2145 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); |
| 2146 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); |
| 2147 | |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2148 | /* reject antenna configurations which don't match the |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2149 | * available antenna masks, except for the "all" mask */ |
| 2150 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2151 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) |
| 2152 | return -EINVAL; |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2153 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2154 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
| 2155 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2156 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2157 | result = rdev_set_antenna(rdev, tx_ant, rx_ant); |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2158 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2159 | return result; |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2160 | } |
| 2161 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2162 | changed = 0; |
| 2163 | |
| 2164 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { |
| 2165 | retry_short = nla_get_u8( |
| 2166 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2167 | if (retry_short == 0) |
| 2168 | return -EINVAL; |
| 2169 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2170 | changed |= WIPHY_PARAM_RETRY_SHORT; |
| 2171 | } |
| 2172 | |
| 2173 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { |
| 2174 | retry_long = nla_get_u8( |
| 2175 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2176 | if (retry_long == 0) |
| 2177 | return -EINVAL; |
| 2178 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2179 | changed |= WIPHY_PARAM_RETRY_LONG; |
| 2180 | } |
| 2181 | |
| 2182 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { |
| 2183 | frag_threshold = nla_get_u32( |
| 2184 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2185 | if (frag_threshold < 256) |
| 2186 | return -EINVAL; |
| 2187 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2188 | if (frag_threshold != (u32) -1) { |
| 2189 | /* |
| 2190 | * Fragments (apart from the last one) are required to |
| 2191 | * have even length. Make the fragmentation code |
| 2192 | * simpler by stripping LSB should someone try to use |
| 2193 | * odd threshold value. |
| 2194 | */ |
| 2195 | frag_threshold &= ~0x1; |
| 2196 | } |
| 2197 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; |
| 2198 | } |
| 2199 | |
| 2200 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { |
| 2201 | rts_threshold = nla_get_u32( |
| 2202 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); |
| 2203 | changed |= WIPHY_PARAM_RTS_THRESHOLD; |
| 2204 | } |
| 2205 | |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2206 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
| 2207 | coverage_class = nla_get_u8( |
| 2208 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); |
| 2209 | changed |= WIPHY_PARAM_COVERAGE_CLASS; |
| 2210 | } |
| 2211 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2212 | if (changed) { |
| 2213 | u8 old_retry_short, old_retry_long; |
| 2214 | u32 old_frag_threshold, old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2215 | u8 old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2216 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2217 | if (!rdev->ops->set_wiphy_params) |
| 2218 | return -EOPNOTSUPP; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2219 | |
| 2220 | old_retry_short = rdev->wiphy.retry_short; |
| 2221 | old_retry_long = rdev->wiphy.retry_long; |
| 2222 | old_frag_threshold = rdev->wiphy.frag_threshold; |
| 2223 | old_rts_threshold = rdev->wiphy.rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2224 | old_coverage_class = rdev->wiphy.coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2225 | |
| 2226 | if (changed & WIPHY_PARAM_RETRY_SHORT) |
| 2227 | rdev->wiphy.retry_short = retry_short; |
| 2228 | if (changed & WIPHY_PARAM_RETRY_LONG) |
| 2229 | rdev->wiphy.retry_long = retry_long; |
| 2230 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) |
| 2231 | rdev->wiphy.frag_threshold = frag_threshold; |
| 2232 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) |
| 2233 | rdev->wiphy.rts_threshold = rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2234 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
| 2235 | rdev->wiphy.coverage_class = coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2236 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2237 | result = rdev_set_wiphy_params(rdev, changed); |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2238 | if (result) { |
| 2239 | rdev->wiphy.retry_short = old_retry_short; |
| 2240 | rdev->wiphy.retry_long = old_retry_long; |
| 2241 | rdev->wiphy.frag_threshold = old_frag_threshold; |
| 2242 | rdev->wiphy.rts_threshold = old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2243 | rdev->wiphy.coverage_class = old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2244 | } |
| 2245 | } |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2246 | return 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2247 | } |
| 2248 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 2249 | static inline u64 wdev_id(struct wireless_dev *wdev) |
| 2250 | { |
| 2251 | return (u64)wdev->identifier | |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 2252 | ((u64)wiphy_to_rdev(wdev->wiphy)->wiphy_idx << 32); |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 2253 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2254 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2255 | static int nl80211_send_chandef(struct sk_buff *msg, |
Janusz Dziedzic | d2859df | 2013-11-06 13:55:51 +0100 | [diff] [blame] | 2256 | const struct cfg80211_chan_def *chandef) |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2257 | { |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 2258 | WARN_ON(!cfg80211_chandef_valid(chandef)); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2259 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2260 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
| 2261 | chandef->chan->center_freq)) |
| 2262 | return -ENOBUFS; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2263 | switch (chandef->width) { |
| 2264 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 2265 | case NL80211_CHAN_WIDTH_20: |
| 2266 | case NL80211_CHAN_WIDTH_40: |
| 2267 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 2268 | cfg80211_get_chandef_type(chandef))) |
| 2269 | return -ENOBUFS; |
| 2270 | break; |
| 2271 | default: |
| 2272 | break; |
| 2273 | } |
| 2274 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width)) |
| 2275 | return -ENOBUFS; |
| 2276 | if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1)) |
| 2277 | return -ENOBUFS; |
| 2278 | if (chandef->center_freq2 && |
| 2279 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2)) |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2280 | return -ENOBUFS; |
| 2281 | return 0; |
| 2282 | } |
| 2283 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2284 | 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] | 2285 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2286 | struct wireless_dev *wdev) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2287 | { |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2288 | struct net_device *dev = wdev->netdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2289 | void *hdr; |
| 2290 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2291 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_INTERFACE); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2292 | if (!hdr) |
| 2293 | return -1; |
| 2294 | |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2295 | if (dev && |
| 2296 | (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2297 | nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name))) |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2298 | goto nla_put_failure; |
| 2299 | |
| 2300 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 2301 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 2302 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2303 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2304 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
| 2305 | rdev->devlist_generation ^ |
| 2306 | (cfg80211_rdev_list_generation << 2))) |
| 2307 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2308 | |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 2309 | if (rdev->ops->get_channel) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2310 | int ret; |
| 2311 | struct cfg80211_chan_def chandef; |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 2312 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2313 | ret = rdev_get_channel(rdev, wdev, &chandef); |
| 2314 | if (ret == 0) { |
| 2315 | if (nl80211_send_chandef(msg, &chandef)) |
| 2316 | goto nla_put_failure; |
| 2317 | } |
Pontus Fuchs | d91df0e | 2012-04-03 16:39:58 +0200 | [diff] [blame] | 2318 | } |
| 2319 | |
Antonio Quartulli | b84e7a0 | 2012-11-07 12:52:20 +0100 | [diff] [blame] | 2320 | if (wdev->ssid_len) { |
| 2321 | if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid)) |
| 2322 | goto nla_put_failure; |
| 2323 | } |
| 2324 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2325 | return genlmsg_end(msg, hdr); |
| 2326 | |
| 2327 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 2328 | genlmsg_cancel(msg, hdr); |
| 2329 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2330 | } |
| 2331 | |
| 2332 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) |
| 2333 | { |
| 2334 | int wp_idx = 0; |
| 2335 | int if_idx = 0; |
| 2336 | int wp_start = cb->args[0]; |
| 2337 | int if_start = cb->args[1]; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2338 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2339 | struct wireless_dev *wdev; |
| 2340 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2341 | rtnl_lock(); |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2342 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 2343 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2344 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2345 | if (wp_idx < wp_start) { |
| 2346 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2347 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2348 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2349 | if_idx = 0; |
| 2350 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 2351 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2352 | if (if_idx < if_start) { |
| 2353 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2354 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2355 | } |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2356 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2357 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2358 | rdev, wdev) < 0) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2359 | goto out; |
| 2360 | } |
| 2361 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2362 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2363 | |
| 2364 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2365 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2366 | out: |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2367 | rtnl_unlock(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2368 | |
| 2369 | cb->args[0] = wp_idx; |
| 2370 | cb->args[1] = if_idx; |
| 2371 | |
| 2372 | return skb->len; |
| 2373 | } |
| 2374 | |
| 2375 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) |
| 2376 | { |
| 2377 | struct sk_buff *msg; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2378 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2379 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2380 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2381 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2382 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2383 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2384 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2385 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2386 | rdev, wdev) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2387 | nlmsg_free(msg); |
| 2388 | return -ENOBUFS; |
| 2389 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2390 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 2391 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2392 | } |
| 2393 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2394 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
| 2395 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, |
| 2396 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, |
| 2397 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, |
| 2398 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, |
| 2399 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2400 | [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG }, |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2401 | }; |
| 2402 | |
| 2403 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) |
| 2404 | { |
| 2405 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; |
| 2406 | int flag; |
| 2407 | |
| 2408 | *mntrflags = 0; |
| 2409 | |
| 2410 | if (!nla) |
| 2411 | return -EINVAL; |
| 2412 | |
| 2413 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, |
| 2414 | nla, mntr_flags_policy)) |
| 2415 | return -EINVAL; |
| 2416 | |
| 2417 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) |
| 2418 | if (flags[flag]) |
| 2419 | *mntrflags |= (1<<flag); |
| 2420 | |
| 2421 | return 0; |
| 2422 | } |
| 2423 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2424 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2425 | struct net_device *netdev, u8 use_4addr, |
| 2426 | enum nl80211_iftype iftype) |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2427 | { |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2428 | if (!use_4addr) { |
Jiri Pirko | f350a0a8 | 2010-06-15 06:50:45 +0000 | [diff] [blame] | 2429 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2430 | return -EBUSY; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2431 | return 0; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2432 | } |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2433 | |
| 2434 | switch (iftype) { |
| 2435 | case NL80211_IFTYPE_AP_VLAN: |
| 2436 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) |
| 2437 | return 0; |
| 2438 | break; |
| 2439 | case NL80211_IFTYPE_STATION: |
| 2440 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) |
| 2441 | return 0; |
| 2442 | break; |
| 2443 | default: |
| 2444 | break; |
| 2445 | } |
| 2446 | |
| 2447 | return -EOPNOTSUPP; |
| 2448 | } |
| 2449 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2450 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
| 2451 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2452 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2453 | struct vif_params params; |
Johannes Berg | e36d56b | 2009-06-09 21:04:43 +0200 | [diff] [blame] | 2454 | int err; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2455 | enum nl80211_iftype otype, ntype; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2456 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2457 | u32 _flags, *flags = NULL; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2458 | bool change = false; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2459 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2460 | memset(¶ms, 0, sizeof(params)); |
| 2461 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2462 | otype = ntype = dev->ieee80211_ptr->iftype; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2463 | |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 2464 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2465 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2466 | if (otype != ntype) |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2467 | change = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2468 | if (ntype > NL80211_IFTYPE_MAX) |
| 2469 | return -EINVAL; |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 2470 | } |
| 2471 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2472 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2473 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2474 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2475 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
| 2476 | return -EINVAL; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2477 | if (netif_running(dev)) |
| 2478 | return -EBUSY; |
| 2479 | |
| 2480 | wdev_lock(wdev); |
| 2481 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 2482 | IEEE80211_MAX_MESH_ID_LEN); |
| 2483 | wdev->mesh_id_up_len = |
| 2484 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 2485 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 2486 | wdev->mesh_id_up_len); |
| 2487 | wdev_unlock(wdev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2488 | } |
| 2489 | |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2490 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
| 2491 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
| 2492 | change = true; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2493 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2494 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2495 | return err; |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2496 | } else { |
| 2497 | params.use_4addr = -1; |
| 2498 | } |
| 2499 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2500 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2501 | if (ntype != NL80211_IFTYPE_MONITOR) |
| 2502 | return -EINVAL; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2503 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
| 2504 | &_flags); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2505 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2506 | return err; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2507 | |
| 2508 | flags = &_flags; |
| 2509 | change = true; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2510 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2511 | |
Luciano Coelho | 1800329 | 2013-08-29 13:26:57 +0300 | [diff] [blame] | 2512 | if (flags && (*flags & MONITOR_FLAG_ACTIVE) && |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2513 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
| 2514 | return -EOPNOTSUPP; |
| 2515 | |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2516 | if (change) |
Johannes Berg | 3d54d25 | 2009-08-21 14:51:05 +0200 | [diff] [blame] | 2517 | err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2518 | else |
| 2519 | err = 0; |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 2520 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2521 | if (!err && params.use_4addr != -1) |
| 2522 | dev->ieee80211_ptr->use_4addr = params.use_4addr; |
| 2523 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2524 | return err; |
| 2525 | } |
| 2526 | |
| 2527 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) |
| 2528 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2529 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2530 | struct vif_params params; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2531 | struct wireless_dev *wdev; |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2532 | struct sk_buff *msg; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2533 | int err; |
| 2534 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2535 | u32 flags; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2536 | |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 2537 | /* to avoid failing a new interface creation due to pending removal */ |
| 2538 | cfg80211_destroy_ifaces(rdev); |
| 2539 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2540 | memset(¶ms, 0, sizeof(params)); |
| 2541 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2542 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
| 2543 | return -EINVAL; |
| 2544 | |
| 2545 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
| 2546 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
| 2547 | if (type > NL80211_IFTYPE_MAX) |
| 2548 | return -EINVAL; |
| 2549 | } |
| 2550 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2551 | if (!rdev->ops->add_virtual_intf || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2552 | !(rdev->wiphy.interface_modes & (1 << type))) |
| 2553 | return -EOPNOTSUPP; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2554 | |
Arend van Spriel | 1c18f14 | 2013-01-08 10:17:27 +0100 | [diff] [blame] | 2555 | if (type == NL80211_IFTYPE_P2P_DEVICE && info->attrs[NL80211_ATTR_MAC]) { |
| 2556 | nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC], |
| 2557 | ETH_ALEN); |
| 2558 | if (!is_valid_ether_addr(params.macaddr)) |
| 2559 | return -EADDRNOTAVAIL; |
| 2560 | } |
| 2561 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2562 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2563 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2564 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2565 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2566 | return err; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2567 | } |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2568 | |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2569 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 2570 | if (!msg) |
| 2571 | return -ENOMEM; |
| 2572 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2573 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
| 2574 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, |
| 2575 | &flags); |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2576 | |
Luciano Coelho | 1800329 | 2013-08-29 13:26:57 +0300 | [diff] [blame] | 2577 | if (!err && (flags & MONITOR_FLAG_ACTIVE) && |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2578 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
| 2579 | return -EOPNOTSUPP; |
| 2580 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2581 | wdev = rdev_add_virtual_intf(rdev, |
| 2582 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), |
| 2583 | type, err ? NULL : &flags, ¶ms); |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2584 | if (IS_ERR(wdev)) { |
| 2585 | nlmsg_free(msg); |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2586 | return PTR_ERR(wdev); |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2587 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2588 | |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 2589 | if (info->attrs[NL80211_ATTR_IFACE_SOCKET_OWNER]) |
| 2590 | wdev->owner_nlportid = info->snd_portid; |
| 2591 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2592 | switch (type) { |
| 2593 | case NL80211_IFTYPE_MESH_POINT: |
| 2594 | if (!info->attrs[NL80211_ATTR_MESH_ID]) |
| 2595 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2596 | wdev_lock(wdev); |
| 2597 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 2598 | IEEE80211_MAX_MESH_ID_LEN); |
| 2599 | wdev->mesh_id_up_len = |
| 2600 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 2601 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 2602 | wdev->mesh_id_up_len); |
| 2603 | wdev_unlock(wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2604 | break; |
| 2605 | case NL80211_IFTYPE_P2P_DEVICE: |
| 2606 | /* |
| 2607 | * P2P Device doesn't have a netdev, so doesn't go |
| 2608 | * through the netdev notifier and must be added here |
| 2609 | */ |
| 2610 | mutex_init(&wdev->mtx); |
| 2611 | INIT_LIST_HEAD(&wdev->event_list); |
| 2612 | spin_lock_init(&wdev->event_lock); |
| 2613 | INIT_LIST_HEAD(&wdev->mgmt_registrations); |
| 2614 | spin_lock_init(&wdev->mgmt_registrations_lock); |
| 2615 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2616 | wdev->identifier = ++rdev->wdev_id; |
| 2617 | list_add_rcu(&wdev->list, &rdev->wdev_list); |
| 2618 | rdev->devlist_generation++; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2619 | break; |
| 2620 | default: |
| 2621 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2622 | } |
| 2623 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2624 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2625 | rdev, wdev) < 0) { |
| 2626 | nlmsg_free(msg); |
| 2627 | return -ENOBUFS; |
| 2628 | } |
| 2629 | |
| 2630 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2631 | } |
| 2632 | |
| 2633 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) |
| 2634 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2635 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2636 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2637 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2638 | if (!rdev->ops->del_virtual_intf) |
| 2639 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2640 | |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2641 | /* |
| 2642 | * If we remove a wireless device without a netdev then clear |
| 2643 | * user_ptr[1] so that nl80211_post_doit won't dereference it |
| 2644 | * to check if it needs to do dev_put(). Otherwise it crashes |
| 2645 | * since the wdev has been freed, unlike with a netdev where |
| 2646 | * we need the dev_put() for the netdev to really be freed. |
| 2647 | */ |
| 2648 | if (!wdev->netdev) |
| 2649 | info->user_ptr[1] = NULL; |
| 2650 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2651 | return rdev_del_virtual_intf(rdev, wdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2652 | } |
| 2653 | |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 2654 | static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info) |
| 2655 | { |
| 2656 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2657 | struct net_device *dev = info->user_ptr[1]; |
| 2658 | u16 noack_map; |
| 2659 | |
| 2660 | if (!info->attrs[NL80211_ATTR_NOACK_MAP]) |
| 2661 | return -EINVAL; |
| 2662 | |
| 2663 | if (!rdev->ops->set_noack_map) |
| 2664 | return -EOPNOTSUPP; |
| 2665 | |
| 2666 | noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]); |
| 2667 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2668 | return rdev_set_noack_map(rdev, dev, noack_map); |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 2669 | } |
| 2670 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2671 | struct get_key_cookie { |
| 2672 | struct sk_buff *msg; |
| 2673 | int error; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2674 | int idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2675 | }; |
| 2676 | |
| 2677 | static void get_key_callback(void *c, struct key_params *params) |
| 2678 | { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2679 | struct nlattr *key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2680 | struct get_key_cookie *cookie = c; |
| 2681 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2682 | if ((params->key && |
| 2683 | nla_put(cookie->msg, NL80211_ATTR_KEY_DATA, |
| 2684 | params->key_len, params->key)) || |
| 2685 | (params->seq && |
| 2686 | nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ, |
| 2687 | params->seq_len, params->seq)) || |
| 2688 | (params->cipher && |
| 2689 | nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER, |
| 2690 | params->cipher))) |
| 2691 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2692 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2693 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
| 2694 | if (!key) |
| 2695 | goto nla_put_failure; |
| 2696 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2697 | if ((params->key && |
| 2698 | nla_put(cookie->msg, NL80211_KEY_DATA, |
| 2699 | params->key_len, params->key)) || |
| 2700 | (params->seq && |
| 2701 | nla_put(cookie->msg, NL80211_KEY_SEQ, |
| 2702 | params->seq_len, params->seq)) || |
| 2703 | (params->cipher && |
| 2704 | nla_put_u32(cookie->msg, NL80211_KEY_CIPHER, |
| 2705 | params->cipher))) |
| 2706 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2707 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2708 | if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx)) |
| 2709 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2710 | |
| 2711 | nla_nest_end(cookie->msg, key); |
| 2712 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2713 | return; |
| 2714 | nla_put_failure: |
| 2715 | cookie->error = 1; |
| 2716 | } |
| 2717 | |
| 2718 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) |
| 2719 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2720 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2721 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2722 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2723 | u8 key_idx = 0; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2724 | const u8 *mac_addr = NULL; |
| 2725 | bool pairwise; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2726 | struct get_key_cookie cookie = { |
| 2727 | .error = 0, |
| 2728 | }; |
| 2729 | void *hdr; |
| 2730 | struct sk_buff *msg; |
| 2731 | |
| 2732 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 2733 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 2734 | |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 2735 | if (key_idx > 5) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2736 | return -EINVAL; |
| 2737 | |
| 2738 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2739 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2740 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2741 | pairwise = !!mac_addr; |
| 2742 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 2743 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 2744 | if (kt >= NUM_NL80211_KEYTYPES) |
| 2745 | return -EINVAL; |
| 2746 | if (kt != NL80211_KEYTYPE_GROUP && |
| 2747 | kt != NL80211_KEYTYPE_PAIRWISE) |
| 2748 | return -EINVAL; |
| 2749 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; |
| 2750 | } |
| 2751 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2752 | if (!rdev->ops->get_key) |
| 2753 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2754 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2755 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2756 | if (!msg) |
| 2757 | return -ENOMEM; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2758 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2759 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2760 | NL80211_CMD_NEW_KEY); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 2761 | if (!hdr) |
Johannes Berg | 9fe271a | 2013-10-25 11:15:12 +0200 | [diff] [blame] | 2762 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2763 | |
| 2764 | cookie.msg = msg; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2765 | cookie.idx = key_idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2766 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2767 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 2768 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) |
| 2769 | goto nla_put_failure; |
| 2770 | if (mac_addr && |
| 2771 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 2772 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2773 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2774 | if (pairwise && mac_addr && |
| 2775 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 2776 | return -ENOENT; |
| 2777 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2778 | err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie, |
| 2779 | get_key_callback); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2780 | |
| 2781 | if (err) |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 2782 | goto free_msg; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2783 | |
| 2784 | if (cookie.error) |
| 2785 | goto nla_put_failure; |
| 2786 | |
| 2787 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2788 | return genlmsg_reply(msg, info); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2789 | |
| 2790 | nla_put_failure: |
| 2791 | err = -ENOBUFS; |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 2792 | free_msg: |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2793 | nlmsg_free(msg); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2794 | return err; |
| 2795 | } |
| 2796 | |
| 2797 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) |
| 2798 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2799 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2800 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2801 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2802 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2803 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2804 | err = nl80211_parse_key(info, &key); |
| 2805 | if (err) |
| 2806 | return err; |
| 2807 | |
| 2808 | if (key.idx < 0) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2809 | return -EINVAL; |
| 2810 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2811 | /* only support setting default key */ |
| 2812 | if (!key.def && !key.defmgmt) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2813 | return -EINVAL; |
| 2814 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2815 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2816 | |
| 2817 | if (key.def) { |
| 2818 | if (!rdev->ops->set_default_key) { |
| 2819 | err = -EOPNOTSUPP; |
| 2820 | goto out; |
| 2821 | } |
| 2822 | |
| 2823 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2824 | if (err) |
| 2825 | goto out; |
| 2826 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2827 | err = rdev_set_default_key(rdev, dev, key.idx, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2828 | key.def_uni, key.def_multi); |
| 2829 | |
| 2830 | if (err) |
| 2831 | goto out; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2832 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 2833 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2834 | dev->ieee80211_ptr->wext.default_key = key.idx; |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2835 | #endif |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2836 | } else { |
| 2837 | if (key.def_uni || !key.def_multi) { |
| 2838 | err = -EINVAL; |
| 2839 | goto out; |
| 2840 | } |
| 2841 | |
| 2842 | if (!rdev->ops->set_default_mgmt_key) { |
| 2843 | err = -EOPNOTSUPP; |
| 2844 | goto out; |
| 2845 | } |
| 2846 | |
| 2847 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2848 | if (err) |
| 2849 | goto out; |
| 2850 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2851 | err = rdev_set_default_mgmt_key(rdev, dev, key.idx); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2852 | if (err) |
| 2853 | goto out; |
| 2854 | |
| 2855 | #ifdef CONFIG_CFG80211_WEXT |
| 2856 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; |
| 2857 | #endif |
| 2858 | } |
| 2859 | |
| 2860 | out: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2861 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2862 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2863 | return err; |
| 2864 | } |
| 2865 | |
| 2866 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) |
| 2867 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2868 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2869 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2870 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2871 | struct key_parse key; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2872 | const u8 *mac_addr = NULL; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2873 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2874 | err = nl80211_parse_key(info, &key); |
| 2875 | if (err) |
| 2876 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2877 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2878 | if (!key.p.key) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2879 | return -EINVAL; |
| 2880 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2881 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2882 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2883 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2884 | if (key.type == -1) { |
| 2885 | if (mac_addr) |
| 2886 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 2887 | else |
| 2888 | key.type = NL80211_KEYTYPE_GROUP; |
| 2889 | } |
| 2890 | |
| 2891 | /* for now */ |
| 2892 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 2893 | key.type != NL80211_KEYTYPE_GROUP) |
| 2894 | return -EINVAL; |
| 2895 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2896 | if (!rdev->ops->add_key) |
| 2897 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2898 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2899 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
| 2900 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2901 | mac_addr)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2902 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2903 | |
| 2904 | wdev_lock(dev->ieee80211_ptr); |
| 2905 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2906 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2907 | err = rdev_add_key(rdev, dev, key.idx, |
| 2908 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2909 | mac_addr, &key.p); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2910 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2911 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2912 | return err; |
| 2913 | } |
| 2914 | |
| 2915 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) |
| 2916 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2917 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2918 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2919 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2920 | u8 *mac_addr = NULL; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2921 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2922 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2923 | err = nl80211_parse_key(info, &key); |
| 2924 | if (err) |
| 2925 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2926 | |
| 2927 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2928 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2929 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2930 | if (key.type == -1) { |
| 2931 | if (mac_addr) |
| 2932 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 2933 | else |
| 2934 | key.type = NL80211_KEYTYPE_GROUP; |
| 2935 | } |
| 2936 | |
| 2937 | /* for now */ |
| 2938 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 2939 | key.type != NL80211_KEYTYPE_GROUP) |
| 2940 | return -EINVAL; |
| 2941 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2942 | if (!rdev->ops->del_key) |
| 2943 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2944 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2945 | wdev_lock(dev->ieee80211_ptr); |
| 2946 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2947 | |
| 2948 | if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr && |
| 2949 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 2950 | err = -ENOENT; |
| 2951 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2952 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2953 | err = rdev_del_key(rdev, dev, key.idx, |
| 2954 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2955 | mac_addr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2956 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 2957 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2958 | if (!err) { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2959 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2960 | dev->ieee80211_ptr->wext.default_key = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2961 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2962 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
| 2963 | } |
| 2964 | #endif |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2965 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2966 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2967 | return err; |
| 2968 | } |
| 2969 | |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 2970 | /* This function returns an error or the number of nested attributes */ |
| 2971 | static int validate_acl_mac_addrs(struct nlattr *nl_attr) |
| 2972 | { |
| 2973 | struct nlattr *attr; |
| 2974 | int n_entries = 0, tmp; |
| 2975 | |
| 2976 | nla_for_each_nested(attr, nl_attr, tmp) { |
| 2977 | if (nla_len(attr) != ETH_ALEN) |
| 2978 | return -EINVAL; |
| 2979 | |
| 2980 | n_entries++; |
| 2981 | } |
| 2982 | |
| 2983 | return n_entries; |
| 2984 | } |
| 2985 | |
| 2986 | /* |
| 2987 | * This function parses ACL information and allocates memory for ACL data. |
| 2988 | * On successful return, the calling function is responsible to free the |
| 2989 | * ACL buffer returned by this function. |
| 2990 | */ |
| 2991 | static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy, |
| 2992 | struct genl_info *info) |
| 2993 | { |
| 2994 | enum nl80211_acl_policy acl_policy; |
| 2995 | struct nlattr *attr; |
| 2996 | struct cfg80211_acl_data *acl; |
| 2997 | int i = 0, n_entries, tmp; |
| 2998 | |
| 2999 | if (!wiphy->max_acl_mac_addrs) |
| 3000 | return ERR_PTR(-EOPNOTSUPP); |
| 3001 | |
| 3002 | if (!info->attrs[NL80211_ATTR_ACL_POLICY]) |
| 3003 | return ERR_PTR(-EINVAL); |
| 3004 | |
| 3005 | acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]); |
| 3006 | if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED && |
| 3007 | acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED) |
| 3008 | return ERR_PTR(-EINVAL); |
| 3009 | |
| 3010 | if (!info->attrs[NL80211_ATTR_MAC_ADDRS]) |
| 3011 | return ERR_PTR(-EINVAL); |
| 3012 | |
| 3013 | n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]); |
| 3014 | if (n_entries < 0) |
| 3015 | return ERR_PTR(n_entries); |
| 3016 | |
| 3017 | if (n_entries > wiphy->max_acl_mac_addrs) |
| 3018 | return ERR_PTR(-ENOTSUPP); |
| 3019 | |
| 3020 | acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries), |
| 3021 | GFP_KERNEL); |
| 3022 | if (!acl) |
| 3023 | return ERR_PTR(-ENOMEM); |
| 3024 | |
| 3025 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) { |
| 3026 | memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN); |
| 3027 | i++; |
| 3028 | } |
| 3029 | |
| 3030 | acl->n_acl_entries = n_entries; |
| 3031 | acl->acl_policy = acl_policy; |
| 3032 | |
| 3033 | return acl; |
| 3034 | } |
| 3035 | |
| 3036 | static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info) |
| 3037 | { |
| 3038 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3039 | struct net_device *dev = info->user_ptr[1]; |
| 3040 | struct cfg80211_acl_data *acl; |
| 3041 | int err; |
| 3042 | |
| 3043 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3044 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3045 | return -EOPNOTSUPP; |
| 3046 | |
| 3047 | if (!dev->ieee80211_ptr->beacon_interval) |
| 3048 | return -EINVAL; |
| 3049 | |
| 3050 | acl = parse_acl_data(&rdev->wiphy, info); |
| 3051 | if (IS_ERR(acl)) |
| 3052 | return PTR_ERR(acl); |
| 3053 | |
| 3054 | err = rdev_set_mac_acl(rdev, dev, acl); |
| 3055 | |
| 3056 | kfree(acl); |
| 3057 | |
| 3058 | return err; |
| 3059 | } |
| 3060 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3061 | static int nl80211_parse_beacon(struct nlattr *attrs[], |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3062 | struct cfg80211_beacon_data *bcn) |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3063 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3064 | bool haveinfo = false; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3065 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3066 | if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) || |
| 3067 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) || |
| 3068 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) || |
| 3069 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP])) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 3070 | return -EINVAL; |
| 3071 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3072 | memset(bcn, 0, sizeof(*bcn)); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3073 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3074 | if (attrs[NL80211_ATTR_BEACON_HEAD]) { |
| 3075 | bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]); |
| 3076 | bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3077 | if (!bcn->head_len) |
| 3078 | return -EINVAL; |
| 3079 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3080 | } |
| 3081 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3082 | if (attrs[NL80211_ATTR_BEACON_TAIL]) { |
| 3083 | bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]); |
| 3084 | bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3085 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3086 | } |
| 3087 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3088 | if (!haveinfo) |
| 3089 | return -EINVAL; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3090 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3091 | if (attrs[NL80211_ATTR_IE]) { |
| 3092 | bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]); |
| 3093 | bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 3094 | } |
| 3095 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3096 | if (attrs[NL80211_ATTR_IE_PROBE_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3097 | bcn->proberesp_ies = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3098 | nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3099 | bcn->proberesp_ies_len = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3100 | nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 3101 | } |
| 3102 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3103 | if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3104 | bcn->assocresp_ies = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3105 | nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3106 | bcn->assocresp_ies_len = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3107 | nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 3108 | } |
| 3109 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3110 | if (attrs[NL80211_ATTR_PROBE_RESP]) { |
| 3111 | bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]); |
| 3112 | bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]); |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 3113 | } |
| 3114 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3115 | return 0; |
| 3116 | } |
| 3117 | |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3118 | static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev, |
| 3119 | struct cfg80211_ap_settings *params) |
| 3120 | { |
| 3121 | struct wireless_dev *wdev; |
| 3122 | bool ret = false; |
| 3123 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 3124 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3125 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 3126 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 3127 | continue; |
| 3128 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3129 | if (!wdev->preset_chandef.chan) |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3130 | continue; |
| 3131 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3132 | params->chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3133 | ret = true; |
| 3134 | break; |
| 3135 | } |
| 3136 | |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3137 | return ret; |
| 3138 | } |
| 3139 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 3140 | static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev, |
| 3141 | enum nl80211_auth_type auth_type, |
| 3142 | enum nl80211_commands cmd) |
| 3143 | { |
| 3144 | if (auth_type > NL80211_AUTHTYPE_MAX) |
| 3145 | return false; |
| 3146 | |
| 3147 | switch (cmd) { |
| 3148 | case NL80211_CMD_AUTHENTICATE: |
| 3149 | if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && |
| 3150 | auth_type == NL80211_AUTHTYPE_SAE) |
| 3151 | return false; |
| 3152 | return true; |
| 3153 | case NL80211_CMD_CONNECT: |
| 3154 | case NL80211_CMD_START_AP: |
| 3155 | /* SAE not supported yet */ |
| 3156 | if (auth_type == NL80211_AUTHTYPE_SAE) |
| 3157 | return false; |
| 3158 | return true; |
| 3159 | default: |
| 3160 | return false; |
| 3161 | } |
| 3162 | } |
| 3163 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3164 | static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) |
| 3165 | { |
| 3166 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3167 | struct net_device *dev = info->user_ptr[1]; |
| 3168 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3169 | struct cfg80211_ap_settings params; |
| 3170 | int err; |
| 3171 | |
| 3172 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3173 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3174 | return -EOPNOTSUPP; |
| 3175 | |
| 3176 | if (!rdev->ops->start_ap) |
| 3177 | return -EOPNOTSUPP; |
| 3178 | |
| 3179 | if (wdev->beacon_interval) |
| 3180 | return -EALREADY; |
| 3181 | |
| 3182 | memset(¶ms, 0, sizeof(params)); |
| 3183 | |
| 3184 | /* these are required for START_AP */ |
| 3185 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || |
| 3186 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || |
| 3187 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) |
| 3188 | return -EINVAL; |
| 3189 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3190 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3191 | if (err) |
| 3192 | return err; |
| 3193 | |
| 3194 | params.beacon_interval = |
| 3195 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 3196 | params.dtim_period = |
| 3197 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 3198 | |
| 3199 | err = cfg80211_validate_beacon_int(rdev, params.beacon_interval); |
| 3200 | if (err) |
| 3201 | return err; |
| 3202 | |
| 3203 | /* |
| 3204 | * In theory, some of these attributes should be required here |
| 3205 | * but since they were not used when the command was originally |
| 3206 | * added, keep them optional for old user space programs to let |
| 3207 | * them continue to work with drivers that do not need the |
| 3208 | * additional information -- drivers must check! |
| 3209 | */ |
| 3210 | if (info->attrs[NL80211_ATTR_SSID]) { |
| 3211 | params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 3212 | params.ssid_len = |
| 3213 | nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 3214 | if (params.ssid_len == 0 || |
| 3215 | params.ssid_len > IEEE80211_MAX_SSID_LEN) |
| 3216 | return -EINVAL; |
| 3217 | } |
| 3218 | |
| 3219 | if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) { |
| 3220 | params.hidden_ssid = nla_get_u32( |
| 3221 | info->attrs[NL80211_ATTR_HIDDEN_SSID]); |
| 3222 | if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE && |
| 3223 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN && |
| 3224 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS) |
| 3225 | return -EINVAL; |
| 3226 | } |
| 3227 | |
| 3228 | params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
| 3229 | |
| 3230 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 3231 | params.auth_type = nla_get_u32( |
| 3232 | info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 3233 | if (!nl80211_valid_auth_type(rdev, params.auth_type, |
| 3234 | NL80211_CMD_START_AP)) |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3235 | return -EINVAL; |
| 3236 | } else |
| 3237 | params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 3238 | |
| 3239 | err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, |
| 3240 | NL80211_MAX_NR_CIPHER_SUITES); |
| 3241 | if (err) |
| 3242 | return err; |
| 3243 | |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 3244 | if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) { |
| 3245 | if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER)) |
| 3246 | return -EOPNOTSUPP; |
| 3247 | params.inactivity_timeout = nla_get_u16( |
| 3248 | info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]); |
| 3249 | } |
| 3250 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 3251 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 3252 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3253 | return -EINVAL; |
| 3254 | params.p2p_ctwindow = |
| 3255 | nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
| 3256 | if (params.p2p_ctwindow > 127) |
| 3257 | return -EINVAL; |
| 3258 | if (params.p2p_ctwindow != 0 && |
| 3259 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 3260 | return -EINVAL; |
| 3261 | } |
| 3262 | |
| 3263 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 3264 | u8 tmp; |
| 3265 | |
| 3266 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3267 | return -EINVAL; |
| 3268 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
| 3269 | if (tmp > 1) |
| 3270 | return -EINVAL; |
| 3271 | params.p2p_opp_ps = tmp; |
| 3272 | if (params.p2p_opp_ps != 0 && |
| 3273 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 3274 | return -EINVAL; |
| 3275 | } |
| 3276 | |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3277 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3278 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
| 3279 | if (err) |
| 3280 | return err; |
| 3281 | } else if (wdev->preset_chandef.chan) { |
| 3282 | params.chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3283 | } else if (!nl80211_get_ap_channel(rdev, ¶ms)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3284 | return -EINVAL; |
| 3285 | |
Ilan Peer | 174e0cd | 2014-02-23 09:13:01 +0200 | [diff] [blame] | 3286 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, ¶ms.chandef, |
| 3287 | wdev->iftype)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3288 | return -EINVAL; |
| 3289 | |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 3290 | if (info->attrs[NL80211_ATTR_ACL_POLICY]) { |
| 3291 | params.acl = parse_acl_data(&rdev->wiphy, info); |
| 3292 | if (IS_ERR(params.acl)) |
| 3293 | return PTR_ERR(params.acl); |
| 3294 | } |
| 3295 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 3296 | wdev_lock(wdev); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3297 | err = rdev_start_ap(rdev, dev, ¶ms); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3298 | if (!err) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3299 | wdev->preset_chandef = params.chandef; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3300 | wdev->beacon_interval = params.beacon_interval; |
Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 3301 | wdev->chandef = params.chandef; |
Antonio Quartulli | 06e191e | 2012-11-07 12:52:19 +0100 | [diff] [blame] | 3302 | wdev->ssid_len = params.ssid_len; |
| 3303 | memcpy(wdev->ssid, params.ssid, wdev->ssid_len); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3304 | } |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 3305 | wdev_unlock(wdev); |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 3306 | |
| 3307 | kfree(params.acl); |
| 3308 | |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 3309 | return err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3310 | } |
| 3311 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3312 | static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info) |
| 3313 | { |
| 3314 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3315 | struct net_device *dev = info->user_ptr[1]; |
| 3316 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3317 | struct cfg80211_beacon_data params; |
| 3318 | int err; |
| 3319 | |
| 3320 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3321 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3322 | return -EOPNOTSUPP; |
| 3323 | |
| 3324 | if (!rdev->ops->change_beacon) |
| 3325 | return -EOPNOTSUPP; |
| 3326 | |
| 3327 | if (!wdev->beacon_interval) |
| 3328 | return -EINVAL; |
| 3329 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3330 | err = nl80211_parse_beacon(info->attrs, ¶ms); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3331 | if (err) |
| 3332 | return err; |
| 3333 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 3334 | wdev_lock(wdev); |
| 3335 | err = rdev_change_beacon(rdev, dev, ¶ms); |
| 3336 | wdev_unlock(wdev); |
| 3337 | |
| 3338 | return err; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3339 | } |
| 3340 | |
| 3341 | 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] | 3342 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3343 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3344 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3345 | |
Ilan Peer | 7c8d5e0 | 2014-02-25 15:33:38 +0200 | [diff] [blame] | 3346 | return cfg80211_stop_ap(rdev, dev, false); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3347 | } |
| 3348 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3349 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
| 3350 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, |
| 3351 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, |
| 3352 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, |
Jouni Malinen | 0e46724 | 2009-05-11 21:57:55 +0300 | [diff] [blame] | 3353 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 3354 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
Johannes Berg | d83023d | 2011-12-14 09:29:15 +0100 | [diff] [blame] | 3355 | [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3356 | }; |
| 3357 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3358 | static int parse_station_flags(struct genl_info *info, |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3359 | enum nl80211_iftype iftype, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3360 | struct station_parameters *params) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3361 | { |
| 3362 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3363 | struct nlattr *nla; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3364 | int flag; |
| 3365 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3366 | /* |
| 3367 | * Try parsing the new attribute first so userspace |
| 3368 | * can specify both for older kernels. |
| 3369 | */ |
| 3370 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; |
| 3371 | if (nla) { |
| 3372 | struct nl80211_sta_flag_update *sta_flags; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3373 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3374 | sta_flags = nla_data(nla); |
| 3375 | params->sta_flags_mask = sta_flags->mask; |
| 3376 | params->sta_flags_set = sta_flags->set; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3377 | params->sta_flags_set &= params->sta_flags_mask; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3378 | if ((params->sta_flags_mask | |
| 3379 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) |
| 3380 | return -EINVAL; |
| 3381 | return 0; |
| 3382 | } |
| 3383 | |
| 3384 | /* if present, parse the old attribute */ |
| 3385 | |
| 3386 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3387 | if (!nla) |
| 3388 | return 0; |
| 3389 | |
| 3390 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, |
| 3391 | nla, sta_flags_policy)) |
| 3392 | return -EINVAL; |
| 3393 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3394 | /* |
| 3395 | * Only allow certain flags for interface types so that |
| 3396 | * other attributes are silently ignored. Remember that |
| 3397 | * this is backward compatibility code with old userspace |
| 3398 | * and shouldn't be hit in other cases anyway. |
| 3399 | */ |
| 3400 | switch (iftype) { |
| 3401 | case NL80211_IFTYPE_AP: |
| 3402 | case NL80211_IFTYPE_AP_VLAN: |
| 3403 | case NL80211_IFTYPE_P2P_GO: |
| 3404 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3405 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 3406 | BIT(NL80211_STA_FLAG_WME) | |
| 3407 | BIT(NL80211_STA_FLAG_MFP); |
| 3408 | break; |
| 3409 | case NL80211_IFTYPE_P2P_CLIENT: |
| 3410 | case NL80211_IFTYPE_STATION: |
| 3411 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3412 | BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3413 | break; |
| 3414 | case NL80211_IFTYPE_MESH_POINT: |
| 3415 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3416 | BIT(NL80211_STA_FLAG_MFP) | |
| 3417 | BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 3418 | default: |
| 3419 | return -EINVAL; |
| 3420 | } |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3421 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 3422 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) { |
| 3423 | if (flags[flag]) { |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3424 | params->sta_flags_set |= (1<<flag); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3425 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 3426 | /* no longer support new API additions in old API */ |
| 3427 | if (flag > NL80211_STA_FLAG_MAX_OLD_API) |
| 3428 | return -EINVAL; |
| 3429 | } |
| 3430 | } |
| 3431 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3432 | return 0; |
| 3433 | } |
| 3434 | |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3435 | static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, |
| 3436 | int attr) |
| 3437 | { |
| 3438 | struct nlattr *rate; |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 3439 | u32 bitrate; |
| 3440 | u16 bitrate_compat; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3441 | |
| 3442 | rate = nla_nest_start(msg, attr); |
| 3443 | if (!rate) |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 3444 | return false; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3445 | |
| 3446 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ |
| 3447 | bitrate = cfg80211_calculate_bitrate(info); |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 3448 | /* report 16-bit bitrate only if we can */ |
| 3449 | bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 3450 | if (bitrate > 0 && |
| 3451 | nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate)) |
| 3452 | return false; |
| 3453 | if (bitrate_compat > 0 && |
| 3454 | nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat)) |
| 3455 | return false; |
| 3456 | |
| 3457 | if (info->flags & RATE_INFO_FLAGS_MCS) { |
| 3458 | if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) |
| 3459 | return false; |
| 3460 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && |
| 3461 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) |
| 3462 | return false; |
| 3463 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 3464 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 3465 | return false; |
| 3466 | } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) { |
| 3467 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs)) |
| 3468 | return false; |
| 3469 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss)) |
| 3470 | return false; |
| 3471 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && |
| 3472 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) |
| 3473 | return false; |
| 3474 | if (info->flags & RATE_INFO_FLAGS_80_MHZ_WIDTH && |
| 3475 | nla_put_flag(msg, NL80211_RATE_INFO_80_MHZ_WIDTH)) |
| 3476 | return false; |
| 3477 | if (info->flags & RATE_INFO_FLAGS_80P80_MHZ_WIDTH && |
| 3478 | nla_put_flag(msg, NL80211_RATE_INFO_80P80_MHZ_WIDTH)) |
| 3479 | return false; |
| 3480 | if (info->flags & RATE_INFO_FLAGS_160_MHZ_WIDTH && |
| 3481 | nla_put_flag(msg, NL80211_RATE_INFO_160_MHZ_WIDTH)) |
| 3482 | return false; |
| 3483 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 3484 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 3485 | return false; |
| 3486 | } |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3487 | |
| 3488 | nla_nest_end(msg, rate); |
| 3489 | return true; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3490 | } |
| 3491 | |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 3492 | static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal, |
| 3493 | int id) |
| 3494 | { |
| 3495 | void *attr; |
| 3496 | int i = 0; |
| 3497 | |
| 3498 | if (!mask) |
| 3499 | return true; |
| 3500 | |
| 3501 | attr = nla_nest_start(msg, id); |
| 3502 | if (!attr) |
| 3503 | return false; |
| 3504 | |
| 3505 | for (i = 0; i < IEEE80211_MAX_CHAINS; i++) { |
| 3506 | if (!(mask & BIT(i))) |
| 3507 | continue; |
| 3508 | |
| 3509 | if (nla_put_u8(msg, i, signal[i])) |
| 3510 | return false; |
| 3511 | } |
| 3512 | |
| 3513 | nla_nest_end(msg, attr); |
| 3514 | |
| 3515 | return true; |
| 3516 | } |
| 3517 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3518 | 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] | 3519 | int flags, |
| 3520 | struct cfg80211_registered_device *rdev, |
| 3521 | struct net_device *dev, |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 3522 | const u8 *mac_addr, struct station_info *sinfo) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3523 | { |
| 3524 | void *hdr; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3525 | struct nlattr *sinfoattr, *bss_param; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3526 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3527 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3528 | if (!hdr) |
| 3529 | return -1; |
| 3530 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3531 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 3532 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 3533 | nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation)) |
| 3534 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 3535 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3536 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
| 3537 | if (!sinfoattr) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3538 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3539 | if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) && |
| 3540 | nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME, |
| 3541 | sinfo->connected_time)) |
| 3542 | goto nla_put_failure; |
| 3543 | if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) && |
| 3544 | nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME, |
| 3545 | sinfo->inactive_time)) |
| 3546 | goto nla_put_failure; |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3547 | if ((sinfo->filled & (STATION_INFO_RX_BYTES | |
| 3548 | STATION_INFO_RX_BYTES64)) && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3549 | nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES, |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3550 | (u32)sinfo->rx_bytes)) |
| 3551 | goto nla_put_failure; |
| 3552 | if ((sinfo->filled & (STATION_INFO_TX_BYTES | |
Felix Fietkau | 4325d72 | 2013-05-23 15:05:59 +0200 | [diff] [blame] | 3553 | STATION_INFO_TX_BYTES64)) && |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3554 | nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES, |
| 3555 | (u32)sinfo->tx_bytes)) |
| 3556 | goto nla_put_failure; |
| 3557 | if ((sinfo->filled & STATION_INFO_RX_BYTES64) && |
| 3558 | nla_put_u64(msg, NL80211_STA_INFO_RX_BYTES64, |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3559 | sinfo->rx_bytes)) |
| 3560 | goto nla_put_failure; |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3561 | if ((sinfo->filled & STATION_INFO_TX_BYTES64) && |
| 3562 | nla_put_u64(msg, NL80211_STA_INFO_TX_BYTES64, |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3563 | sinfo->tx_bytes)) |
| 3564 | goto nla_put_failure; |
| 3565 | if ((sinfo->filled & STATION_INFO_LLID) && |
| 3566 | nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid)) |
| 3567 | goto nla_put_failure; |
| 3568 | if ((sinfo->filled & STATION_INFO_PLID) && |
| 3569 | nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid)) |
| 3570 | goto nla_put_failure; |
| 3571 | if ((sinfo->filled & STATION_INFO_PLINK_STATE) && |
| 3572 | nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE, |
| 3573 | sinfo->plink_state)) |
| 3574 | goto nla_put_failure; |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3575 | switch (rdev->wiphy.signal_type) { |
| 3576 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3577 | if ((sinfo->filled & STATION_INFO_SIGNAL) && |
| 3578 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL, |
| 3579 | sinfo->signal)) |
| 3580 | goto nla_put_failure; |
| 3581 | if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) && |
| 3582 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG, |
| 3583 | sinfo->signal_avg)) |
| 3584 | goto nla_put_failure; |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3585 | break; |
| 3586 | default: |
| 3587 | break; |
| 3588 | } |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 3589 | if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL) { |
| 3590 | if (!nl80211_put_signal(msg, sinfo->chains, |
| 3591 | sinfo->chain_signal, |
| 3592 | NL80211_STA_INFO_CHAIN_SIGNAL)) |
| 3593 | goto nla_put_failure; |
| 3594 | } |
| 3595 | if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL_AVG) { |
| 3596 | if (!nl80211_put_signal(msg, sinfo->chains, |
| 3597 | sinfo->chain_signal_avg, |
| 3598 | NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) |
| 3599 | goto nla_put_failure; |
| 3600 | } |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3601 | if (sinfo->filled & STATION_INFO_TX_BITRATE) { |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3602 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
| 3603 | NL80211_STA_INFO_TX_BITRATE)) |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3604 | goto nla_put_failure; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3605 | } |
| 3606 | if (sinfo->filled & STATION_INFO_RX_BITRATE) { |
| 3607 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, |
| 3608 | NL80211_STA_INFO_RX_BITRATE)) |
| 3609 | goto nla_put_failure; |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3610 | } |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3611 | if ((sinfo->filled & STATION_INFO_RX_PACKETS) && |
| 3612 | nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS, |
| 3613 | sinfo->rx_packets)) |
| 3614 | goto nla_put_failure; |
| 3615 | if ((sinfo->filled & STATION_INFO_TX_PACKETS) && |
| 3616 | nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS, |
| 3617 | sinfo->tx_packets)) |
| 3618 | goto nla_put_failure; |
| 3619 | if ((sinfo->filled & STATION_INFO_TX_RETRIES) && |
| 3620 | nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES, |
| 3621 | sinfo->tx_retries)) |
| 3622 | goto nla_put_failure; |
| 3623 | if ((sinfo->filled & STATION_INFO_TX_FAILED) && |
| 3624 | nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED, |
| 3625 | sinfo->tx_failed)) |
| 3626 | goto nla_put_failure; |
| 3627 | if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) && |
| 3628 | nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS, |
| 3629 | sinfo->beacon_loss_count)) |
| 3630 | goto nla_put_failure; |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 3631 | if ((sinfo->filled & STATION_INFO_LOCAL_PM) && |
| 3632 | nla_put_u32(msg, NL80211_STA_INFO_LOCAL_PM, |
| 3633 | sinfo->local_pm)) |
| 3634 | goto nla_put_failure; |
| 3635 | if ((sinfo->filled & STATION_INFO_PEER_PM) && |
| 3636 | nla_put_u32(msg, NL80211_STA_INFO_PEER_PM, |
| 3637 | sinfo->peer_pm)) |
| 3638 | goto nla_put_failure; |
| 3639 | if ((sinfo->filled & STATION_INFO_NONPEER_PM) && |
| 3640 | nla_put_u32(msg, NL80211_STA_INFO_NONPEER_PM, |
| 3641 | sinfo->nonpeer_pm)) |
| 3642 | goto nla_put_failure; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3643 | if (sinfo->filled & STATION_INFO_BSS_PARAM) { |
| 3644 | bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); |
| 3645 | if (!bss_param) |
| 3646 | goto nla_put_failure; |
| 3647 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3648 | if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) && |
| 3649 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) || |
| 3650 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) && |
| 3651 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) || |
| 3652 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) && |
| 3653 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) || |
| 3654 | nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, |
| 3655 | sinfo->bss_param.dtim_period) || |
| 3656 | nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, |
| 3657 | sinfo->bss_param.beacon_interval)) |
| 3658 | goto nla_put_failure; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3659 | |
| 3660 | nla_nest_end(msg, bss_param); |
| 3661 | } |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3662 | if ((sinfo->filled & STATION_INFO_STA_FLAGS) && |
| 3663 | nla_put(msg, NL80211_STA_INFO_STA_FLAGS, |
| 3664 | sizeof(struct nl80211_sta_flag_update), |
| 3665 | &sinfo->sta_flags)) |
| 3666 | goto nla_put_failure; |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 3667 | if ((sinfo->filled & STATION_INFO_T_OFFSET) && |
| 3668 | nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET, |
| 3669 | sinfo->t_offset)) |
| 3670 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3671 | nla_nest_end(msg, sinfoattr); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3672 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3673 | if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) && |
| 3674 | nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, |
| 3675 | sinfo->assoc_req_ies)) |
| 3676 | goto nla_put_failure; |
Jouni Malinen | 50d3dfb | 2011-08-08 12:11:52 +0300 | [diff] [blame] | 3677 | |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3678 | return genlmsg_end(msg, hdr); |
| 3679 | |
| 3680 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 3681 | genlmsg_cancel(msg, hdr); |
| 3682 | return -EMSGSIZE; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3683 | } |
| 3684 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3685 | static int nl80211_dump_station(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3686 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3687 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3688 | struct station_info sinfo; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 3689 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3690 | struct wireless_dev *wdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3691 | u8 mac_addr[ETH_ALEN]; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3692 | int sta_idx = cb->args[2]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3693 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3694 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 3695 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3696 | if (err) |
| 3697 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3698 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3699 | if (!wdev->netdev) { |
| 3700 | err = -EINVAL; |
| 3701 | goto out_err; |
| 3702 | } |
| 3703 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 3704 | if (!rdev->ops->dump_station) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3705 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3706 | goto out_err; |
| 3707 | } |
| 3708 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3709 | while (1) { |
Jouni Malinen | f612ced | 2011-08-11 11:46:22 +0300 | [diff] [blame] | 3710 | memset(&sinfo, 0, sizeof(sinfo)); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 3711 | err = rdev_dump_station(rdev, wdev->netdev, sta_idx, |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3712 | mac_addr, &sinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3713 | if (err == -ENOENT) |
| 3714 | break; |
| 3715 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3716 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3717 | |
| 3718 | if (nl80211_send_station(skb, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3719 | NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3720 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 3721 | rdev, wdev->netdev, mac_addr, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3722 | &sinfo) < 0) |
| 3723 | goto out; |
| 3724 | |
| 3725 | sta_idx++; |
| 3726 | } |
| 3727 | |
| 3728 | |
| 3729 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3730 | cb->args[2] = sta_idx; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3731 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3732 | out_err: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 3733 | nl80211_finish_wdev_dump(rdev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3734 | |
| 3735 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3736 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3737 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3738 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
| 3739 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3740 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3741 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3742 | struct station_info sinfo; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3743 | struct sk_buff *msg; |
| 3744 | u8 *mac_addr = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3745 | int err; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3746 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3747 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3748 | |
| 3749 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3750 | return -EINVAL; |
| 3751 | |
| 3752 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3753 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3754 | if (!rdev->ops->get_station) |
| 3755 | return -EOPNOTSUPP; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3756 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3757 | err = rdev_get_station(rdev, dev, mac_addr, &sinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3758 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3759 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3760 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3761 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3762 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3763 | return -ENOMEM; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3764 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3765 | 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] | 3766 | rdev, dev, mac_addr, &sinfo) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3767 | nlmsg_free(msg); |
| 3768 | return -ENOBUFS; |
| 3769 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3770 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3771 | return genlmsg_reply(msg, info); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3772 | } |
| 3773 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3774 | int cfg80211_check_station_change(struct wiphy *wiphy, |
| 3775 | struct station_parameters *params, |
| 3776 | enum cfg80211_station_type statype) |
| 3777 | { |
| 3778 | if (params->listen_interval != -1) |
| 3779 | return -EINVAL; |
| 3780 | if (params->aid) |
| 3781 | return -EINVAL; |
| 3782 | |
| 3783 | /* When you run into this, adjust the code below for the new flag */ |
| 3784 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); |
| 3785 | |
| 3786 | switch (statype) { |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 3787 | case CFG80211_STA_MESH_PEER_KERNEL: |
| 3788 | case CFG80211_STA_MESH_PEER_USER: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3789 | /* |
| 3790 | * No ignoring the TDLS flag here -- the userspace mesh |
| 3791 | * code doesn't have the bug of including TDLS in the |
| 3792 | * mask everywhere. |
| 3793 | */ |
| 3794 | if (params->sta_flags_mask & |
| 3795 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3796 | BIT(NL80211_STA_FLAG_MFP) | |
| 3797 | BIT(NL80211_STA_FLAG_AUTHORIZED))) |
| 3798 | return -EINVAL; |
| 3799 | break; |
| 3800 | case CFG80211_STA_TDLS_PEER_SETUP: |
| 3801 | case CFG80211_STA_TDLS_PEER_ACTIVE: |
| 3802 | if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 3803 | return -EINVAL; |
| 3804 | /* ignore since it can't change */ |
| 3805 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3806 | break; |
| 3807 | default: |
| 3808 | /* disallow mesh-specific things */ |
| 3809 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) |
| 3810 | return -EINVAL; |
| 3811 | if (params->local_pm) |
| 3812 | return -EINVAL; |
| 3813 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
| 3814 | return -EINVAL; |
| 3815 | } |
| 3816 | |
| 3817 | if (statype != CFG80211_STA_TDLS_PEER_SETUP && |
| 3818 | statype != CFG80211_STA_TDLS_PEER_ACTIVE) { |
| 3819 | /* TDLS can't be set, ... */ |
| 3820 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
| 3821 | return -EINVAL; |
| 3822 | /* |
| 3823 | * ... but don't bother the driver with it. This works around |
| 3824 | * a hostapd/wpa_supplicant issue -- it always includes the |
| 3825 | * TLDS_PEER flag in the mask even for AP mode. |
| 3826 | */ |
| 3827 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3828 | } |
| 3829 | |
| 3830 | if (statype != CFG80211_STA_TDLS_PEER_SETUP) { |
| 3831 | /* reject other things that can't change */ |
| 3832 | if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) |
| 3833 | return -EINVAL; |
| 3834 | if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY) |
| 3835 | return -EINVAL; |
| 3836 | if (params->supported_rates) |
| 3837 | return -EINVAL; |
| 3838 | if (params->ext_capab || params->ht_capa || params->vht_capa) |
| 3839 | return -EINVAL; |
| 3840 | } |
| 3841 | |
| 3842 | if (statype != CFG80211_STA_AP_CLIENT) { |
| 3843 | if (params->vlan) |
| 3844 | return -EINVAL; |
| 3845 | } |
| 3846 | |
| 3847 | switch (statype) { |
| 3848 | case CFG80211_STA_AP_MLME_CLIENT: |
| 3849 | /* Use this only for authorizing/unauthorizing a station */ |
| 3850 | if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))) |
| 3851 | return -EOPNOTSUPP; |
| 3852 | break; |
| 3853 | case CFG80211_STA_AP_CLIENT: |
| 3854 | /* accept only the listed bits */ |
| 3855 | if (params->sta_flags_mask & |
| 3856 | ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3857 | BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3858 | BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 3859 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 3860 | BIT(NL80211_STA_FLAG_WME) | |
| 3861 | BIT(NL80211_STA_FLAG_MFP))) |
| 3862 | return -EINVAL; |
| 3863 | |
| 3864 | /* but authenticated/associated only if driver handles it */ |
| 3865 | if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
| 3866 | params->sta_flags_mask & |
| 3867 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3868 | BIT(NL80211_STA_FLAG_ASSOCIATED))) |
| 3869 | return -EINVAL; |
| 3870 | break; |
| 3871 | case CFG80211_STA_IBSS: |
| 3872 | case CFG80211_STA_AP_STA: |
| 3873 | /* reject any changes other than AUTHORIZED */ |
| 3874 | if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) |
| 3875 | return -EINVAL; |
| 3876 | break; |
| 3877 | case CFG80211_STA_TDLS_PEER_SETUP: |
| 3878 | /* reject any changes other than AUTHORIZED or WME */ |
| 3879 | if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3880 | BIT(NL80211_STA_FLAG_WME))) |
| 3881 | return -EINVAL; |
| 3882 | /* force (at least) rates when authorizing */ |
| 3883 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) && |
| 3884 | !params->supported_rates) |
| 3885 | return -EINVAL; |
| 3886 | break; |
| 3887 | case CFG80211_STA_TDLS_PEER_ACTIVE: |
| 3888 | /* reject any changes */ |
| 3889 | return -EINVAL; |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 3890 | case CFG80211_STA_MESH_PEER_KERNEL: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3891 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
| 3892 | return -EINVAL; |
| 3893 | break; |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 3894 | case CFG80211_STA_MESH_PEER_USER: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3895 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) |
| 3896 | return -EINVAL; |
| 3897 | break; |
| 3898 | } |
| 3899 | |
| 3900 | return 0; |
| 3901 | } |
| 3902 | EXPORT_SYMBOL(cfg80211_check_station_change); |
| 3903 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3904 | /* |
Felix Fietkau | c258d2d | 2009-11-11 17:23:31 +0100 | [diff] [blame] | 3905 | * 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] | 3906 | */ |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3907 | static struct net_device *get_vlan(struct genl_info *info, |
| 3908 | struct cfg80211_registered_device *rdev) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3909 | { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3910 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3911 | struct net_device *v; |
| 3912 | int ret; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3913 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3914 | if (!vlanattr) |
| 3915 | return NULL; |
| 3916 | |
| 3917 | v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); |
| 3918 | if (!v) |
| 3919 | return ERR_PTR(-ENODEV); |
| 3920 | |
| 3921 | if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { |
| 3922 | ret = -EINVAL; |
| 3923 | goto error; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3924 | } |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3925 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3926 | if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
| 3927 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3928 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { |
| 3929 | ret = -EINVAL; |
| 3930 | goto error; |
| 3931 | } |
| 3932 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3933 | if (!netif_running(v)) { |
| 3934 | ret = -ENETDOWN; |
| 3935 | goto error; |
| 3936 | } |
| 3937 | |
| 3938 | return v; |
| 3939 | error: |
| 3940 | dev_put(v); |
| 3941 | return ERR_PTR(ret); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3942 | } |
| 3943 | |
Johannes Berg | 94e860f | 2014-01-20 23:58:15 +0100 | [diff] [blame] | 3944 | static const struct nla_policy |
| 3945 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = { |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3946 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, |
| 3947 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, |
| 3948 | }; |
| 3949 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 3950 | static int nl80211_parse_sta_wme(struct genl_info *info, |
| 3951 | struct station_parameters *params) |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3952 | { |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3953 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; |
| 3954 | struct nlattr *nla; |
| 3955 | int err; |
| 3956 | |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3957 | /* parse WME attributes if present */ |
| 3958 | if (!info->attrs[NL80211_ATTR_STA_WME]) |
| 3959 | return 0; |
| 3960 | |
| 3961 | nla = info->attrs[NL80211_ATTR_STA_WME]; |
| 3962 | err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla, |
| 3963 | nl80211_sta_wme_policy); |
| 3964 | if (err) |
| 3965 | return err; |
| 3966 | |
| 3967 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) |
| 3968 | params->uapsd_queues = nla_get_u8( |
| 3969 | tb[NL80211_STA_WME_UAPSD_QUEUES]); |
| 3970 | if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) |
| 3971 | return -EINVAL; |
| 3972 | |
| 3973 | if (tb[NL80211_STA_WME_MAX_SP]) |
| 3974 | params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); |
| 3975 | |
| 3976 | if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) |
| 3977 | return -EINVAL; |
| 3978 | |
| 3979 | params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; |
| 3980 | |
| 3981 | return 0; |
| 3982 | } |
| 3983 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 3984 | static int nl80211_parse_sta_channel_info(struct genl_info *info, |
| 3985 | struct station_parameters *params) |
| 3986 | { |
| 3987 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) { |
| 3988 | params->supported_channels = |
| 3989 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); |
| 3990 | params->supported_channels_len = |
| 3991 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); |
| 3992 | /* |
| 3993 | * Need to include at least one (first channel, number of |
| 3994 | * channels) tuple for each subband, and must have proper |
| 3995 | * tuples for the rest of the data as well. |
| 3996 | */ |
| 3997 | if (params->supported_channels_len < 2) |
| 3998 | return -EINVAL; |
| 3999 | if (params->supported_channels_len % 2) |
| 4000 | return -EINVAL; |
| 4001 | } |
| 4002 | |
| 4003 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) { |
| 4004 | params->supported_oper_classes = |
| 4005 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); |
| 4006 | params->supported_oper_classes_len = |
| 4007 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); |
| 4008 | /* |
| 4009 | * The value of the Length field of the Supported Operating |
| 4010 | * Classes element is between 2 and 253. |
| 4011 | */ |
| 4012 | if (params->supported_oper_classes_len < 2 || |
| 4013 | params->supported_oper_classes_len > 253) |
| 4014 | return -EINVAL; |
| 4015 | } |
| 4016 | return 0; |
| 4017 | } |
| 4018 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4019 | static int nl80211_set_station_tdls(struct genl_info *info, |
| 4020 | struct station_parameters *params) |
| 4021 | { |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 4022 | int err; |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4023 | /* Dummy STA entry gets updated once the peer capabilities are known */ |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 4024 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
| 4025 | params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4026 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 4027 | params->ht_capa = |
| 4028 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
| 4029 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 4030 | params->vht_capa = |
| 4031 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 4032 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 4033 | err = nl80211_parse_sta_channel_info(info, params); |
| 4034 | if (err) |
| 4035 | return err; |
| 4036 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4037 | return nl80211_parse_sta_wme(info, params); |
| 4038 | } |
| 4039 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4040 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
| 4041 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4042 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4043 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4044 | struct station_parameters params; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4045 | u8 *mac_addr; |
| 4046 | int err; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4047 | |
| 4048 | memset(¶ms, 0, sizeof(params)); |
| 4049 | |
| 4050 | params.listen_interval = -1; |
| 4051 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4052 | if (!rdev->ops->change_station) |
| 4053 | return -EOPNOTSUPP; |
| 4054 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4055 | if (info->attrs[NL80211_ATTR_STA_AID]) |
| 4056 | return -EINVAL; |
| 4057 | |
| 4058 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4059 | return -EINVAL; |
| 4060 | |
| 4061 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4062 | |
| 4063 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { |
| 4064 | params.supported_rates = |
| 4065 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4066 | params.supported_rates_len = |
| 4067 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4068 | } |
| 4069 | |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 4070 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
| 4071 | params.capability = |
| 4072 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); |
| 4073 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; |
| 4074 | } |
| 4075 | |
| 4076 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { |
| 4077 | params.ext_capab = |
| 4078 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4079 | params.ext_capab_len = |
| 4080 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4081 | } |
| 4082 | |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 4083 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
Johannes Berg | ba23d20 | 2012-12-27 17:32:09 +0100 | [diff] [blame] | 4084 | return -EINVAL; |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 4085 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 4086 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4087 | return -EINVAL; |
| 4088 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4089 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4090 | params.plink_action = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4091 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 4092 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) |
| 4093 | return -EINVAL; |
| 4094 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4095 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4096 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) { |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 4097 | params.plink_state = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4098 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
| 4099 | if (params.plink_state >= NUM_NL80211_PLINK_STATES) |
| 4100 | return -EINVAL; |
| 4101 | params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE; |
| 4102 | } |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 4103 | |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4104 | if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) { |
| 4105 | enum nl80211_mesh_power_mode pm = nla_get_u32( |
| 4106 | info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]); |
| 4107 | |
| 4108 | if (pm <= NL80211_MESH_POWER_UNKNOWN || |
| 4109 | pm > NL80211_MESH_POWER_MAX) |
| 4110 | return -EINVAL; |
| 4111 | |
| 4112 | params.local_pm = pm; |
| 4113 | } |
| 4114 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4115 | /* Include parameters for TDLS peer (will check later) */ |
| 4116 | err = nl80211_set_station_tdls(info, ¶ms); |
| 4117 | if (err) |
| 4118 | return err; |
| 4119 | |
| 4120 | params.vlan = get_vlan(info, rdev); |
| 4121 | if (IS_ERR(params.vlan)) |
| 4122 | return PTR_ERR(params.vlan); |
| 4123 | |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4124 | switch (dev->ieee80211_ptr->iftype) { |
| 4125 | case NL80211_IFTYPE_AP: |
| 4126 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4127 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4128 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4129 | case NL80211_IFTYPE_STATION: |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 4130 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4131 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4132 | break; |
| 4133 | default: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4134 | err = -EOPNOTSUPP; |
| 4135 | goto out_put_vlan; |
Johannes Berg | 034d655 | 2009-05-27 10:35:29 +0200 | [diff] [blame] | 4136 | } |
| 4137 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4138 | /* driver will call cfg80211_check_station_change() */ |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4139 | err = rdev_change_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4140 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4141 | out_put_vlan: |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4142 | if (params.vlan) |
| 4143 | dev_put(params.vlan); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4144 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4145 | return err; |
| 4146 | } |
| 4147 | |
| 4148 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) |
| 4149 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4150 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4151 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4152 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4153 | struct station_parameters params; |
| 4154 | u8 *mac_addr = NULL; |
| 4155 | |
| 4156 | memset(¶ms, 0, sizeof(params)); |
| 4157 | |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4158 | if (!rdev->ops->add_station) |
| 4159 | return -EOPNOTSUPP; |
| 4160 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4161 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4162 | return -EINVAL; |
| 4163 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4164 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 4165 | return -EINVAL; |
| 4166 | |
| 4167 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) |
| 4168 | return -EINVAL; |
| 4169 | |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 4170 | if (!info->attrs[NL80211_ATTR_STA_AID] && |
| 4171 | !info->attrs[NL80211_ATTR_PEER_AID]) |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 4172 | return -EINVAL; |
| 4173 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4174 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4175 | params.supported_rates = |
| 4176 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4177 | params.supported_rates_len = |
| 4178 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4179 | params.listen_interval = |
| 4180 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 4181 | |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4182 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 4183 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4184 | else |
| 4185 | 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] | 4186 | if (!params.aid || params.aid > IEEE80211_MAX_AID) |
| 4187 | return -EINVAL; |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 4188 | |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 4189 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
| 4190 | params.capability = |
| 4191 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); |
| 4192 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; |
| 4193 | } |
| 4194 | |
| 4195 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { |
| 4196 | params.ext_capab = |
| 4197 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4198 | params.ext_capab_len = |
| 4199 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4200 | } |
| 4201 | |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 4202 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 4203 | params.ht_capa = |
| 4204 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4205 | |
Mahesh Palivela | f461be3e | 2012-10-11 08:04:52 +0000 | [diff] [blame] | 4206 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 4207 | params.vht_capa = |
| 4208 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 4209 | |
Marek Kwaczynski | 60f4a7b | 2013-12-03 10:04:59 +0100 | [diff] [blame] | 4210 | if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) { |
| 4211 | params.opmode_notif_used = true; |
| 4212 | params.opmode_notif = |
| 4213 | nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]); |
| 4214 | } |
| 4215 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4216 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 4217 | params.plink_action = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4218 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 4219 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) |
| 4220 | return -EINVAL; |
| 4221 | } |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 4222 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 4223 | err = nl80211_parse_sta_channel_info(info, ¶ms); |
| 4224 | if (err) |
| 4225 | return err; |
| 4226 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4227 | err = nl80211_parse_sta_wme(info, ¶ms); |
| 4228 | if (err) |
| 4229 | return err; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4230 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 4231 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4232 | return -EINVAL; |
| 4233 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4234 | /* When you run into this, adjust the code below for the new flag */ |
| 4235 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); |
| 4236 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4237 | switch (dev->ieee80211_ptr->iftype) { |
| 4238 | case NL80211_IFTYPE_AP: |
| 4239 | case NL80211_IFTYPE_AP_VLAN: |
| 4240 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4241 | /* ignore WME attributes if iface/sta is not capable */ |
| 4242 | if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) || |
| 4243 | !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) |
| 4244 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4245 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4246 | /* TDLS peers cannot be added */ |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4247 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
| 4248 | info->attrs[NL80211_ATTR_PEER_AID]) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 4249 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4250 | /* but don't bother the driver with it */ |
| 4251 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4252 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4253 | /* allow authenticated/associated only if driver handles it */ |
| 4254 | if (!(rdev->wiphy.features & |
| 4255 | NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
| 4256 | params.sta_flags_mask & |
| 4257 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 4258 | BIT(NL80211_STA_FLAG_ASSOCIATED))) |
| 4259 | return -EINVAL; |
| 4260 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4261 | /* must be last in here for error handling */ |
| 4262 | params.vlan = get_vlan(info, rdev); |
| 4263 | if (IS_ERR(params.vlan)) |
| 4264 | return PTR_ERR(params.vlan); |
| 4265 | break; |
| 4266 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4267 | /* ignore uAPSD data */ |
| 4268 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
| 4269 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4270 | /* associated is disallowed */ |
| 4271 | if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) |
| 4272 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4273 | /* TDLS peers cannot be added */ |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4274 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
| 4275 | info->attrs[NL80211_ATTR_PEER_AID]) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 4276 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4277 | break; |
| 4278 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 93d08f0 | 2013-03-04 09:29:46 +0100 | [diff] [blame] | 4279 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4280 | /* ignore uAPSD data */ |
| 4281 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
| 4282 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4283 | /* these are disallowed */ |
| 4284 | if (params.sta_flags_mask & |
| 4285 | (BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 4286 | BIT(NL80211_STA_FLAG_AUTHENTICATED))) |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4287 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4288 | /* Only TDLS peers can be added */ |
| 4289 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 4290 | return -EINVAL; |
| 4291 | /* Can only add if TDLS ... */ |
| 4292 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) |
| 4293 | return -EOPNOTSUPP; |
| 4294 | /* ... with external setup is supported */ |
| 4295 | if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) |
| 4296 | return -EOPNOTSUPP; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4297 | /* |
| 4298 | * Older wpa_supplicant versions always mark the TDLS peer |
| 4299 | * as authorized, but it shouldn't yet be. |
| 4300 | */ |
| 4301 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED); |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4302 | break; |
| 4303 | default: |
| 4304 | return -EOPNOTSUPP; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4305 | } |
| 4306 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4307 | /* be aware of params.vlan when changing code here */ |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4308 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4309 | err = rdev_add_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4310 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4311 | if (params.vlan) |
| 4312 | dev_put(params.vlan); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4313 | return err; |
| 4314 | } |
| 4315 | |
| 4316 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) |
| 4317 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4318 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4319 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4320 | u8 *mac_addr = NULL; |
| 4321 | |
| 4322 | if (info->attrs[NL80211_ATTR_MAC]) |
| 4323 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4324 | |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 4325 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Marco Porsch | d5d9de0 | 2010-03-30 10:00:16 +0200 | [diff] [blame] | 4326 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4327 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4328 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4329 | return -EINVAL; |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 4330 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4331 | if (!rdev->ops->del_station) |
| 4332 | return -EOPNOTSUPP; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4333 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4334 | return rdev_del_station(rdev, dev, mac_addr); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4335 | } |
| 4336 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4337 | 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] | 4338 | int flags, struct net_device *dev, |
| 4339 | u8 *dst, u8 *next_hop, |
| 4340 | struct mpath_info *pinfo) |
| 4341 | { |
| 4342 | void *hdr; |
| 4343 | struct nlattr *pinfoattr; |
| 4344 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4345 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4346 | if (!hdr) |
| 4347 | return -1; |
| 4348 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4349 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 4350 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || |
| 4351 | nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) || |
| 4352 | nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation)) |
| 4353 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 4354 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4355 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
| 4356 | if (!pinfoattr) |
| 4357 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4358 | if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) && |
| 4359 | nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN, |
| 4360 | pinfo->frame_qlen)) |
| 4361 | goto nla_put_failure; |
| 4362 | if (((pinfo->filled & MPATH_INFO_SN) && |
| 4363 | nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) || |
| 4364 | ((pinfo->filled & MPATH_INFO_METRIC) && |
| 4365 | nla_put_u32(msg, NL80211_MPATH_INFO_METRIC, |
| 4366 | pinfo->metric)) || |
| 4367 | ((pinfo->filled & MPATH_INFO_EXPTIME) && |
| 4368 | nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME, |
| 4369 | pinfo->exptime)) || |
| 4370 | ((pinfo->filled & MPATH_INFO_FLAGS) && |
| 4371 | nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS, |
| 4372 | pinfo->flags)) || |
| 4373 | ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) && |
| 4374 | nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, |
| 4375 | pinfo->discovery_timeout)) || |
| 4376 | ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) && |
| 4377 | nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, |
| 4378 | pinfo->discovery_retries))) |
| 4379 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4380 | |
| 4381 | nla_nest_end(msg, pinfoattr); |
| 4382 | |
| 4383 | return genlmsg_end(msg, hdr); |
| 4384 | |
| 4385 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 4386 | genlmsg_cancel(msg, hdr); |
| 4387 | return -EMSGSIZE; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4388 | } |
| 4389 | |
| 4390 | static int nl80211_dump_mpath(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4391 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4392 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4393 | struct mpath_info pinfo; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4394 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4395 | struct wireless_dev *wdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4396 | u8 dst[ETH_ALEN]; |
| 4397 | u8 next_hop[ETH_ALEN]; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4398 | int path_idx = cb->args[2]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4399 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4400 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4401 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4402 | if (err) |
| 4403 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4404 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4405 | if (!rdev->ops->dump_mpath) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4406 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4407 | goto out_err; |
| 4408 | } |
| 4409 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4410 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4411 | err = -EOPNOTSUPP; |
Roel Kluin | 0448b5f | 2009-08-22 21:15:49 +0200 | [diff] [blame] | 4412 | goto out_err; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4413 | } |
| 4414 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4415 | while (1) { |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4416 | err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4417 | next_hop, &pinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4418 | if (err == -ENOENT) |
| 4419 | break; |
| 4420 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4421 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4422 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4423 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4424 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4425 | wdev->netdev, dst, next_hop, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4426 | &pinfo) < 0) |
| 4427 | goto out; |
| 4428 | |
| 4429 | path_idx++; |
| 4430 | } |
| 4431 | |
| 4432 | |
| 4433 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4434 | cb->args[2] = path_idx; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4435 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4436 | out_err: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4437 | nl80211_finish_wdev_dump(rdev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4438 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4439 | } |
| 4440 | |
| 4441 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4442 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4443 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4444 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4445 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4446 | struct mpath_info pinfo; |
| 4447 | struct sk_buff *msg; |
| 4448 | u8 *dst = NULL; |
| 4449 | u8 next_hop[ETH_ALEN]; |
| 4450 | |
| 4451 | memset(&pinfo, 0, sizeof(pinfo)); |
| 4452 | |
| 4453 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4454 | return -EINVAL; |
| 4455 | |
| 4456 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4457 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4458 | if (!rdev->ops->get_mpath) |
| 4459 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4460 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4461 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4462 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4463 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4464 | err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4465 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4466 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4467 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4468 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4469 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4470 | return -ENOMEM; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4471 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4472 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4473 | dev, dst, next_hop, &pinfo) < 0) { |
| 4474 | nlmsg_free(msg); |
| 4475 | return -ENOBUFS; |
| 4476 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4477 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4478 | return genlmsg_reply(msg, info); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4479 | } |
| 4480 | |
| 4481 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4482 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4483 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4484 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4485 | u8 *dst = NULL; |
| 4486 | u8 *next_hop = NULL; |
| 4487 | |
| 4488 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4489 | return -EINVAL; |
| 4490 | |
| 4491 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 4492 | return -EINVAL; |
| 4493 | |
| 4494 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4495 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 4496 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4497 | if (!rdev->ops->change_mpath) |
| 4498 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4499 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4500 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4501 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4502 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4503 | return rdev_change_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4504 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4505 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4506 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4507 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4508 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4509 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4510 | u8 *dst = NULL; |
| 4511 | u8 *next_hop = NULL; |
| 4512 | |
| 4513 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4514 | return -EINVAL; |
| 4515 | |
| 4516 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 4517 | return -EINVAL; |
| 4518 | |
| 4519 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4520 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 4521 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4522 | if (!rdev->ops->add_mpath) |
| 4523 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4524 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4525 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4526 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4527 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4528 | return rdev_add_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4529 | } |
| 4530 | |
| 4531 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4532 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4533 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4534 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4535 | u8 *dst = NULL; |
| 4536 | |
| 4537 | if (info->attrs[NL80211_ATTR_MAC]) |
| 4538 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4539 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4540 | if (!rdev->ops->del_mpath) |
| 4541 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4542 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4543 | return rdev_del_mpath(rdev, dev, dst); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4544 | } |
| 4545 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4546 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
| 4547 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4548 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4549 | struct net_device *dev = info->user_ptr[1]; |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 4550 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4551 | struct bss_parameters params; |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 4552 | int err; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4553 | |
| 4554 | memset(¶ms, 0, sizeof(params)); |
| 4555 | /* default to not changing parameters */ |
| 4556 | params.use_cts_prot = -1; |
| 4557 | params.use_short_preamble = -1; |
| 4558 | params.use_short_slot_time = -1; |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 4559 | params.ap_isolate = -1; |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 4560 | params.ht_opmode = -1; |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 4561 | params.p2p_ctwindow = -1; |
| 4562 | params.p2p_opp_ps = -1; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4563 | |
| 4564 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) |
| 4565 | params.use_cts_prot = |
| 4566 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); |
| 4567 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) |
| 4568 | params.use_short_preamble = |
| 4569 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); |
| 4570 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) |
| 4571 | params.use_short_slot_time = |
| 4572 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 4573 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 4574 | params.basic_rates = |
| 4575 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 4576 | params.basic_rates_len = |
| 4577 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 4578 | } |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 4579 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
| 4580 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 4581 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
| 4582 | params.ht_opmode = |
| 4583 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4584 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 4585 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 4586 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4587 | return -EINVAL; |
| 4588 | params.p2p_ctwindow = |
| 4589 | nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
| 4590 | if (params.p2p_ctwindow < 0) |
| 4591 | return -EINVAL; |
| 4592 | if (params.p2p_ctwindow != 0 && |
| 4593 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 4594 | return -EINVAL; |
| 4595 | } |
| 4596 | |
| 4597 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 4598 | u8 tmp; |
| 4599 | |
| 4600 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4601 | return -EINVAL; |
| 4602 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
| 4603 | if (tmp > 1) |
| 4604 | return -EINVAL; |
| 4605 | params.p2p_opp_ps = tmp; |
| 4606 | if (params.p2p_opp_ps && |
| 4607 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 4608 | return -EINVAL; |
| 4609 | } |
| 4610 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4611 | if (!rdev->ops->change_bss) |
| 4612 | return -EOPNOTSUPP; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4613 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4614 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4615 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4616 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4617 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 4618 | wdev_lock(wdev); |
| 4619 | err = rdev_change_bss(rdev, dev, ¶ms); |
| 4620 | wdev_unlock(wdev); |
| 4621 | |
| 4622 | return err; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4623 | } |
| 4624 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 4625 | 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] | 4626 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
| 4627 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, |
| 4628 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, |
| 4629 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, |
| 4630 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, |
| 4631 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, |
Janusz Dziedzic | 089027e | 2014-02-21 19:46:12 +0100 | [diff] [blame] | 4632 | [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 }, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4633 | }; |
| 4634 | |
| 4635 | static int parse_reg_rule(struct nlattr *tb[], |
| 4636 | struct ieee80211_reg_rule *reg_rule) |
| 4637 | { |
| 4638 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; |
| 4639 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; |
| 4640 | |
| 4641 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) |
| 4642 | return -EINVAL; |
| 4643 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) |
| 4644 | return -EINVAL; |
| 4645 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) |
| 4646 | return -EINVAL; |
Janusz Dziedzic | b0dfd2e | 2014-02-20 13:52:16 +0100 | [diff] [blame] | 4647 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) |
| 4648 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4649 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) |
| 4650 | return -EINVAL; |
| 4651 | |
| 4652 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); |
| 4653 | |
| 4654 | freq_range->start_freq_khz = |
| 4655 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); |
| 4656 | freq_range->end_freq_khz = |
| 4657 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); |
Janusz Dziedzic | b0dfd2e | 2014-02-20 13:52:16 +0100 | [diff] [blame] | 4658 | freq_range->max_bandwidth_khz = |
| 4659 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4660 | |
| 4661 | power_rule->max_eirp = |
| 4662 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); |
| 4663 | |
| 4664 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) |
| 4665 | power_rule->max_antenna_gain = |
| 4666 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); |
| 4667 | |
Janusz Dziedzic | 089027e | 2014-02-21 19:46:12 +0100 | [diff] [blame] | 4668 | if (tb[NL80211_ATTR_DFS_CAC_TIME]) |
| 4669 | reg_rule->dfs_cac_ms = |
| 4670 | nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]); |
| 4671 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4672 | return 0; |
| 4673 | } |
| 4674 | |
| 4675 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 4676 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4677 | char *data = NULL; |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4678 | enum nl80211_user_reg_hint_type user_reg_hint_type; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4679 | |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 4680 | /* |
| 4681 | * You should only get this when cfg80211 hasn't yet initialized |
| 4682 | * completely when built-in to the kernel right between the time |
| 4683 | * window between nl80211_init() and regulatory_init(), if that is |
| 4684 | * even possible. |
| 4685 | */ |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4686 | if (unlikely(!rcu_access_pointer(cfg80211_regdomain))) |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 4687 | return -EINPROGRESS; |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 4688 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4689 | if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]) |
| 4690 | user_reg_hint_type = |
| 4691 | nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]); |
| 4692 | else |
| 4693 | user_reg_hint_type = NL80211_USER_REG_HINT_USER; |
| 4694 | |
| 4695 | switch (user_reg_hint_type) { |
| 4696 | case NL80211_USER_REG_HINT_USER: |
| 4697 | case NL80211_USER_REG_HINT_CELL_BASE: |
Ilan Peer | 52616f2 | 2014-02-25 16:26:00 +0200 | [diff] [blame] | 4698 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 4699 | return -EINVAL; |
| 4700 | |
| 4701 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 4702 | return regulatory_hint_user(data, user_reg_hint_type); |
| 4703 | case NL80211_USER_REG_HINT_INDOOR: |
| 4704 | return regulatory_hint_indoor_user(); |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4705 | default: |
| 4706 | return -EINVAL; |
| 4707 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4708 | } |
| 4709 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4710 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4711 | struct genl_info *info) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4712 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4713 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4714 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4715 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 4716 | struct mesh_config cur_params; |
| 4717 | int err = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4718 | void *hdr; |
| 4719 | struct nlattr *pinfoattr; |
| 4720 | struct sk_buff *msg; |
| 4721 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4722 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4723 | return -EOPNOTSUPP; |
| 4724 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4725 | if (!rdev->ops->get_mesh_config) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4726 | return -EOPNOTSUPP; |
Jouni Malinen | f3f9258 | 2009-03-20 17:57:36 +0200 | [diff] [blame] | 4727 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4728 | wdev_lock(wdev); |
| 4729 | /* If not connected, get default parameters */ |
| 4730 | if (!wdev->mesh_id_len) |
| 4731 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); |
| 4732 | else |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4733 | err = rdev_get_mesh_config(rdev, dev, &cur_params); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4734 | wdev_unlock(wdev); |
| 4735 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4736 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4737 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4738 | |
| 4739 | /* Draw up a netlink message to send back */ |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4740 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4741 | if (!msg) |
| 4742 | return -ENOMEM; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4743 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4744 | NL80211_CMD_GET_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4745 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4746 | goto out; |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4747 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4748 | if (!pinfoattr) |
| 4749 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4750 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 4751 | nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 4752 | cur_params.dot11MeshRetryTimeout) || |
| 4753 | nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 4754 | cur_params.dot11MeshConfirmTimeout) || |
| 4755 | nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 4756 | cur_params.dot11MeshHoldingTimeout) || |
| 4757 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 4758 | cur_params.dot11MeshMaxPeerLinks) || |
| 4759 | nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES, |
| 4760 | cur_params.dot11MeshMaxRetries) || |
| 4761 | nla_put_u8(msg, NL80211_MESHCONF_TTL, |
| 4762 | cur_params.dot11MeshTTL) || |
| 4763 | nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL, |
| 4764 | cur_params.element_ttl) || |
| 4765 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 4766 | cur_params.auto_open_plinks) || |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 4767 | nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 4768 | cur_params.dot11MeshNbrOffsetMaxNeighbor) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4769 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 4770 | cur_params.dot11MeshHWMPmaxPREQretries) || |
| 4771 | nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 4772 | cur_params.path_refresh_time) || |
| 4773 | nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 4774 | cur_params.min_discovery_timeout) || |
| 4775 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 4776 | cur_params.dot11MeshHWMPactivePathTimeout) || |
| 4777 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 4778 | cur_params.dot11MeshHWMPpreqMinInterval) || |
| 4779 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
| 4780 | cur_params.dot11MeshHWMPperrMinInterval) || |
| 4781 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 4782 | cur_params.dot11MeshHWMPnetDiameterTraversalTime) || |
| 4783 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 4784 | cur_params.dot11MeshHWMPRootMode) || |
| 4785 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
| 4786 | cur_params.dot11MeshHWMPRannInterval) || |
| 4787 | nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
| 4788 | cur_params.dot11MeshGateAnnouncementProtocol) || |
| 4789 | nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, |
| 4790 | cur_params.dot11MeshForwarding) || |
| 4791 | nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, |
Ashok Nagarajan | 70c33ea | 2012-04-30 14:20:32 -0700 | [diff] [blame] | 4792 | cur_params.rssi_threshold) || |
| 4793 | nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4794 | cur_params.ht_opmode) || |
| 4795 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 4796 | cur_params.dot11MeshHWMPactivePathToRootTimeout) || |
| 4797 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4798 | cur_params.dot11MeshHWMProotInterval) || |
| 4799 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4800 | cur_params.dot11MeshHWMPconfirmationInterval) || |
| 4801 | nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE, |
| 4802 | cur_params.power_mode) || |
| 4803 | nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW, |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 4804 | cur_params.dot11MeshAwakeWindowDuration) || |
| 4805 | nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT, |
| 4806 | cur_params.plink_timeout)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4807 | goto nla_put_failure; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4808 | nla_nest_end(msg, pinfoattr); |
| 4809 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4810 | return genlmsg_reply(msg, info); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4811 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4812 | nla_put_failure: |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4813 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4814 | out: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 4815 | nlmsg_free(msg); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4816 | return -ENOBUFS; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4817 | } |
| 4818 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 4819 | 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] | 4820 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
| 4821 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, |
| 4822 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, |
| 4823 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, |
| 4824 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, |
| 4825 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 4826 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4827 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 4828 | [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4829 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
| 4830 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, |
| 4831 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, |
| 4832 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, |
| 4833 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 4834 | [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4835 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
Javier Cardona | 699403d | 2011-08-09 16:45:09 -0700 | [diff] [blame] | 4836 | [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 }, |
Javier Cardona | 0507e15 | 2011-08-09 16:45:10 -0700 | [diff] [blame] | 4837 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 }, |
Javier Cardona | 16dd726 | 2011-08-09 16:45:11 -0700 | [diff] [blame] | 4838 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | 94f9065 | 2012-01-21 01:02:16 +0800 | [diff] [blame] | 4839 | [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4840 | [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 }, |
| 4841 | [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4842 | [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 }, |
| 4843 | [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4844 | [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 }, |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4845 | [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 }, |
| 4846 | [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 }, |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 4847 | [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4848 | }; |
| 4849 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4850 | static const struct nla_policy |
| 4851 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 4852 | [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4853 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
| 4854 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 4855 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
Colleen Twitty | 6e16d90 | 2013-05-08 11:45:59 -0700 | [diff] [blame] | 4856 | [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 }, |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 4857 | [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG }, |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4858 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4859 | .len = IEEE80211_MAX_DATA_LEN }, |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 4860 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4861 | }; |
| 4862 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4863 | static int nl80211_parse_mesh_config(struct genl_info *info, |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4864 | struct mesh_config *cfg, |
| 4865 | u32 *mask_out) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4866 | { |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4867 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4868 | u32 mask = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4869 | |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4870 | #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \ |
| 4871 | do { \ |
| 4872 | if (tb[attr]) { \ |
| 4873 | if (fn(tb[attr]) < min || fn(tb[attr]) > max) \ |
| 4874 | return -EINVAL; \ |
| 4875 | cfg->param = fn(tb[attr]); \ |
| 4876 | mask |= (1 << (attr - 1)); \ |
| 4877 | } \ |
| 4878 | } while (0) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4879 | |
| 4880 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4881 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4882 | return -EINVAL; |
| 4883 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4884 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4885 | nl80211_meshconf_params_policy)) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4886 | return -EINVAL; |
| 4887 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4888 | /* This makes sure that there aren't more than 32 mesh config |
| 4889 | * parameters (otherwise our bitfield scheme would not work.) */ |
| 4890 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); |
| 4891 | |
| 4892 | /* Fill in the params struct */ |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4893 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4894 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 4895 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4896 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4897 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 4898 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4899 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4900 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 4901 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4902 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4903 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 4904 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4905 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4906 | mask, NL80211_MESHCONF_MAX_RETRIES, |
| 4907 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4908 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4909 | mask, NL80211_MESHCONF_TTL, nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4910 | 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] | 4911 | mask, NL80211_MESHCONF_ELEMENT_TTL, |
| 4912 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4913 | 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] | 4914 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 4915 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4916 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, |
| 4917 | 1, 255, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4918 | NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 4919 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4920 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4921 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 4922 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4923 | 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] | 4924 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 4925 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4926 | 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] | 4927 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 4928 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4929 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
| 4930 | 1, 65535, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4931 | NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 4932 | nla_get_u32); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4933 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4934 | 1, 65535, mask, |
| 4935 | NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4936 | nla_get_u16); |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 4937 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4938 | 1, 65535, mask, |
| 4939 | NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4940 | nla_get_u16); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4941 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4942 | dot11MeshHWMPnetDiameterTraversalTime, |
| 4943 | 1, 65535, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4944 | NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 4945 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4946 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4, |
| 4947 | mask, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 4948 | nla_get_u8); |
| 4949 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535, |
| 4950 | mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4951 | nla_get_u16); |
Rui Paulo | 63c5723 | 2009-11-09 23:46:57 +0000 | [diff] [blame] | 4952 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4953 | dot11MeshGateAnnouncementProtocol, 0, 1, |
| 4954 | mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4955 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4956 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4957 | mask, NL80211_MESHCONF_FORWARDING, |
| 4958 | nla_get_u8); |
Chun-Yeow Yeoh | 83374fe | 2013-07-11 18:24:03 +0800 | [diff] [blame] | 4959 | 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] | 4960 | mask, NL80211_MESHCONF_RSSI_THRESHOLD, |
Chun-Yeow Yeoh | 83374fe | 2013-07-11 18:24:03 +0800 | [diff] [blame] | 4961 | nla_get_s32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4962 | 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] | 4963 | mask, NL80211_MESHCONF_HT_OPMODE, |
| 4964 | nla_get_u16); |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4965 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4966 | 1, 65535, mask, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4967 | NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 4968 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4969 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4970 | mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
| 4971 | nla_get_u16); |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4972 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4973 | dot11MeshHWMPconfirmationInterval, |
| 4974 | 1, 65535, mask, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4975 | NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
| 4976 | nla_get_u16); |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4977 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode, |
| 4978 | NL80211_MESH_POWER_ACTIVE, |
| 4979 | NL80211_MESH_POWER_MAX, |
| 4980 | mask, NL80211_MESHCONF_POWER_MODE, |
| 4981 | nla_get_u32); |
| 4982 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration, |
| 4983 | 0, 65535, mask, |
| 4984 | NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16); |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 4985 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 1, 0xffffffff, |
| 4986 | mask, NL80211_MESHCONF_PLINK_TIMEOUT, |
| 4987 | nla_get_u32); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4988 | if (mask_out) |
| 4989 | *mask_out = mask; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4990 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4991 | return 0; |
| 4992 | |
| 4993 | #undef FILL_IN_MESH_PARAM_IF_SET |
| 4994 | } |
| 4995 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4996 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
| 4997 | struct mesh_setup *setup) |
| 4998 | { |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 4999 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5000 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
| 5001 | |
| 5002 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) |
| 5003 | return -EINVAL; |
| 5004 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, |
| 5005 | info->attrs[NL80211_ATTR_MESH_SETUP], |
| 5006 | nl80211_mesh_setup_params_policy)) |
| 5007 | return -EINVAL; |
| 5008 | |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 5009 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC]) |
| 5010 | setup->sync_method = |
| 5011 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ? |
| 5012 | IEEE80211_SYNC_METHOD_VENDOR : |
| 5013 | IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET; |
| 5014 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5015 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
| 5016 | setup->path_sel_proto = |
| 5017 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? |
| 5018 | IEEE80211_PATH_PROTOCOL_VENDOR : |
| 5019 | IEEE80211_PATH_PROTOCOL_HWMP; |
| 5020 | |
| 5021 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) |
| 5022 | setup->path_metric = |
| 5023 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? |
| 5024 | IEEE80211_PATH_METRIC_VENDOR : |
| 5025 | IEEE80211_PATH_METRIC_AIRTIME; |
| 5026 | |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 5027 | |
| 5028 | if (tb[NL80211_MESH_SETUP_IE]) { |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5029 | struct nlattr *ieattr = |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 5030 | tb[NL80211_MESH_SETUP_IE]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5031 | if (!is_valid_ie_attr(ieattr)) |
| 5032 | return -EINVAL; |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 5033 | setup->ie = nla_data(ieattr); |
| 5034 | setup->ie_len = nla_len(ieattr); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5035 | } |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 5036 | if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] && |
| 5037 | !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM)) |
| 5038 | return -EINVAL; |
| 5039 | setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]); |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 5040 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
| 5041 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 5042 | if (setup->is_secure) |
| 5043 | setup->user_mpm = true; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5044 | |
Colleen Twitty | 6e16d90 | 2013-05-08 11:45:59 -0700 | [diff] [blame] | 5045 | if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) { |
| 5046 | if (!setup->user_mpm) |
| 5047 | return -EINVAL; |
| 5048 | setup->auth_id = |
| 5049 | nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]); |
| 5050 | } |
| 5051 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5052 | return 0; |
| 5053 | } |
| 5054 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5055 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5056 | struct genl_info *info) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5057 | { |
| 5058 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5059 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5060 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5061 | struct mesh_config cfg; |
| 5062 | u32 mask; |
| 5063 | int err; |
| 5064 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5065 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 5066 | return -EOPNOTSUPP; |
| 5067 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5068 | if (!rdev->ops->update_mesh_config) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5069 | return -EOPNOTSUPP; |
| 5070 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5071 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5072 | if (err) |
| 5073 | return err; |
| 5074 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5075 | wdev_lock(wdev); |
| 5076 | if (!wdev->mesh_id_len) |
| 5077 | err = -ENOLINK; |
| 5078 | |
| 5079 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5080 | err = rdev_update_mesh_config(rdev, dev, mask, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5081 | |
| 5082 | wdev_unlock(wdev); |
| 5083 | |
| 5084 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5085 | } |
| 5086 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5087 | static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info) |
| 5088 | { |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5089 | const struct ieee80211_regdomain *regdom; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5090 | struct sk_buff *msg; |
| 5091 | void *hdr = NULL; |
| 5092 | struct nlattr *nl_reg_rules; |
| 5093 | unsigned int i; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5094 | |
| 5095 | if (!cfg80211_regdomain) |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5096 | return -EINVAL; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5097 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 5098 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5099 | if (!msg) |
| 5100 | return -ENOBUFS; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5101 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5102 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5103 | NL80211_CMD_GET_REG); |
| 5104 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 5105 | goto put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5106 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 5107 | if (reg_last_request_cell_base() && |
| 5108 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, |
| 5109 | NL80211_USER_REG_HINT_CELL_BASE)) |
| 5110 | goto nla_put_failure; |
| 5111 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5112 | rcu_read_lock(); |
| 5113 | regdom = rcu_dereference(cfg80211_regdomain); |
| 5114 | |
| 5115 | if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) || |
| 5116 | (regdom->dfs_region && |
| 5117 | nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region))) |
| 5118 | goto nla_put_failure_rcu; |
| 5119 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5120 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
| 5121 | if (!nl_reg_rules) |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5122 | goto nla_put_failure_rcu; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5123 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5124 | for (i = 0; i < regdom->n_reg_rules; i++) { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5125 | struct nlattr *nl_reg_rule; |
| 5126 | const struct ieee80211_reg_rule *reg_rule; |
| 5127 | const struct ieee80211_freq_range *freq_range; |
| 5128 | const struct ieee80211_power_rule *power_rule; |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 5129 | unsigned int max_bandwidth_khz; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5130 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5131 | reg_rule = ®dom->reg_rules[i]; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5132 | freq_range = ®_rule->freq_range; |
| 5133 | power_rule = ®_rule->power_rule; |
| 5134 | |
| 5135 | nl_reg_rule = nla_nest_start(msg, i); |
| 5136 | if (!nl_reg_rule) |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5137 | goto nla_put_failure_rcu; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5138 | |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 5139 | max_bandwidth_khz = freq_range->max_bandwidth_khz; |
| 5140 | if (!max_bandwidth_khz) |
| 5141 | max_bandwidth_khz = reg_get_max_bandwidth(regdom, |
| 5142 | reg_rule); |
| 5143 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5144 | if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
| 5145 | reg_rule->flags) || |
| 5146 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START, |
| 5147 | freq_range->start_freq_khz) || |
| 5148 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END, |
| 5149 | freq_range->end_freq_khz) || |
| 5150 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 5151 | max_bandwidth_khz) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5152 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
| 5153 | power_rule->max_antenna_gain) || |
| 5154 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, |
Janusz Dziedzic | 089027e | 2014-02-21 19:46:12 +0100 | [diff] [blame] | 5155 | power_rule->max_eirp) || |
| 5156 | nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME, |
| 5157 | reg_rule->dfs_cac_ms)) |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5158 | goto nla_put_failure_rcu; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5159 | |
| 5160 | nla_nest_end(msg, nl_reg_rule); |
| 5161 | } |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5162 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5163 | |
| 5164 | nla_nest_end(msg, nl_reg_rules); |
| 5165 | |
| 5166 | genlmsg_end(msg, hdr); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5167 | return genlmsg_reply(msg, info); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5168 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5169 | nla_put_failure_rcu: |
| 5170 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5171 | nla_put_failure: |
| 5172 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 5173 | put_failure: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 5174 | nlmsg_free(msg); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5175 | return -EMSGSIZE; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5176 | } |
| 5177 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5178 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 5179 | { |
| 5180 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; |
| 5181 | struct nlattr *nl_reg_rule; |
| 5182 | char *alpha2 = NULL; |
| 5183 | int rem_reg_rules = 0, r = 0; |
| 5184 | u32 num_rules = 0, rule_idx = 0, size_of_regd; |
Luis R. Rodriguez | 4c7d398 | 2013-11-13 18:54:02 +0100 | [diff] [blame] | 5185 | enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5186 | struct ieee80211_regdomain *rd = NULL; |
| 5187 | |
| 5188 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 5189 | return -EINVAL; |
| 5190 | |
| 5191 | if (!info->attrs[NL80211_ATTR_REG_RULES]) |
| 5192 | return -EINVAL; |
| 5193 | |
| 5194 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 5195 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 5196 | if (info->attrs[NL80211_ATTR_DFS_REGION]) |
| 5197 | dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); |
| 5198 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5199 | 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] | 5200 | rem_reg_rules) { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5201 | num_rules++; |
| 5202 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) |
Luis R. Rodriguez | 4776c6e | 2009-05-13 17:04:39 -0400 | [diff] [blame] | 5203 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5204 | } |
| 5205 | |
Luis R. Rodriguez | e438768 | 2013-11-05 09:18:01 -0800 | [diff] [blame] | 5206 | if (!reg_is_valid_request(alpha2)) |
| 5207 | return -EINVAL; |
| 5208 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5209 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 5210 | num_rules * sizeof(struct ieee80211_reg_rule); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5211 | |
| 5212 | rd = kzalloc(size_of_regd, GFP_KERNEL); |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 5213 | if (!rd) |
| 5214 | return -ENOMEM; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5215 | |
| 5216 | rd->n_reg_rules = num_rules; |
| 5217 | rd->alpha2[0] = alpha2[0]; |
| 5218 | rd->alpha2[1] = alpha2[1]; |
| 5219 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 5220 | /* |
| 5221 | * Disable DFS master mode if the DFS region was |
| 5222 | * not supported or known on this kernel. |
| 5223 | */ |
| 5224 | if (reg_supported_dfs_region(dfs_region)) |
| 5225 | rd->dfs_region = dfs_region; |
| 5226 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5227 | 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] | 5228 | rem_reg_rules) { |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 5229 | r = nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, |
| 5230 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), |
| 5231 | reg_rule_policy); |
| 5232 | if (r) |
| 5233 | goto bad_reg; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5234 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
| 5235 | if (r) |
| 5236 | goto bad_reg; |
| 5237 | |
| 5238 | rule_idx++; |
| 5239 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 5240 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
| 5241 | r = -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5242 | goto bad_reg; |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 5243 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5244 | } |
| 5245 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5246 | r = set_regdom(rd); |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 5247 | /* set_regdom took ownership */ |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 5248 | rd = NULL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5249 | |
Johannes Berg | d2372b3 | 2008-10-24 20:32:20 +0200 | [diff] [blame] | 5250 | bad_reg: |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5251 | kfree(rd); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 5252 | return r; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5253 | } |
| 5254 | |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5255 | static int validate_scan_freqs(struct nlattr *freqs) |
| 5256 | { |
| 5257 | struct nlattr *attr1, *attr2; |
| 5258 | int n_channels = 0, tmp1, tmp2; |
| 5259 | |
| 5260 | nla_for_each_nested(attr1, freqs, tmp1) { |
| 5261 | n_channels++; |
| 5262 | /* |
| 5263 | * Some hardware has a limited channel list for |
| 5264 | * scanning, and it is pretty much nonsensical |
| 5265 | * to scan for a channel twice, so disallow that |
| 5266 | * and don't require drivers to check that the |
| 5267 | * channel list they get isn't longer than what |
| 5268 | * they can scan, as long as they can scan all |
| 5269 | * the channels they registered at once. |
| 5270 | */ |
| 5271 | nla_for_each_nested(attr2, freqs, tmp2) |
| 5272 | if (attr1 != attr2 && |
| 5273 | nla_get_u32(attr1) == nla_get_u32(attr2)) |
| 5274 | return 0; |
| 5275 | } |
| 5276 | |
| 5277 | return n_channels; |
| 5278 | } |
| 5279 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5280 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
| 5281 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5282 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 5283 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5284 | struct cfg80211_scan_request *request; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5285 | struct nlattr *attr; |
| 5286 | struct wiphy *wiphy; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5287 | int err, tmp, n_ssids = 0, n_channels, i; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5288 | size_t ie_len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5289 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5290 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5291 | return -EINVAL; |
| 5292 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5293 | wiphy = &rdev->wiphy; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5294 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5295 | if (!rdev->ops->scan) |
| 5296 | return -EOPNOTSUPP; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5297 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 5298 | if (rdev->scan_req || rdev->scan_msg) { |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5299 | err = -EBUSY; |
| 5300 | goto unlock; |
| 5301 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5302 | |
| 5303 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5304 | n_channels = validate_scan_freqs( |
| 5305 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5306 | if (!n_channels) { |
| 5307 | err = -EINVAL; |
| 5308 | goto unlock; |
| 5309 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5310 | } else { |
Ilan Peer | bdfbec2 | 2014-01-09 11:37:23 +0200 | [diff] [blame] | 5311 | n_channels = ieee80211_get_num_supported_channels(wiphy); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5312 | } |
| 5313 | |
| 5314 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 5315 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) |
| 5316 | n_ssids++; |
| 5317 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5318 | if (n_ssids > wiphy->max_scan_ssids) { |
| 5319 | err = -EINVAL; |
| 5320 | goto unlock; |
| 5321 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5322 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5323 | if (info->attrs[NL80211_ATTR_IE]) |
| 5324 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5325 | else |
| 5326 | ie_len = 0; |
| 5327 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5328 | if (ie_len > wiphy->max_scan_ie_len) { |
| 5329 | err = -EINVAL; |
| 5330 | goto unlock; |
| 5331 | } |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 5332 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5333 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 5334 | + sizeof(*request->ssids) * n_ssids |
| 5335 | + sizeof(*request->channels) * n_channels |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5336 | + ie_len, GFP_KERNEL); |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5337 | if (!request) { |
| 5338 | err = -ENOMEM; |
| 5339 | goto unlock; |
| 5340 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5341 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5342 | if (n_ssids) |
Johannes Berg | 5ba6353 | 2009-08-07 17:54:07 +0200 | [diff] [blame] | 5343 | request->ssids = (void *)&request->channels[n_channels]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5344 | request->n_ssids = n_ssids; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5345 | if (ie_len) { |
| 5346 | if (request->ssids) |
| 5347 | request->ie = (void *)(request->ssids + n_ssids); |
| 5348 | else |
| 5349 | request->ie = (void *)(request->channels + n_channels); |
| 5350 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5351 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5352 | i = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5353 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 5354 | /* user specified, bail out if channel not found */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5355 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5356 | struct ieee80211_channel *chan; |
| 5357 | |
| 5358 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 5359 | |
| 5360 | if (!chan) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5361 | err = -EINVAL; |
| 5362 | goto out_free; |
| 5363 | } |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5364 | |
| 5365 | /* ignore disabled channels */ |
| 5366 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5367 | continue; |
| 5368 | |
| 5369 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5370 | i++; |
| 5371 | } |
| 5372 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5373 | enum ieee80211_band band; |
| 5374 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5375 | /* all channels */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5376 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 5377 | int j; |
| 5378 | if (!wiphy->bands[band]) |
| 5379 | continue; |
| 5380 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5381 | struct ieee80211_channel *chan; |
| 5382 | |
| 5383 | chan = &wiphy->bands[band]->channels[j]; |
| 5384 | |
| 5385 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5386 | continue; |
| 5387 | |
| 5388 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5389 | i++; |
| 5390 | } |
| 5391 | } |
| 5392 | } |
| 5393 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5394 | if (!i) { |
| 5395 | err = -EINVAL; |
| 5396 | goto out_free; |
| 5397 | } |
| 5398 | |
| 5399 | request->n_channels = i; |
| 5400 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5401 | i = 0; |
| 5402 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 5403 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5404 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5405 | err = -EINVAL; |
| 5406 | goto out_free; |
| 5407 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5408 | request->ssids[i].ssid_len = nla_len(attr); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5409 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5410 | i++; |
| 5411 | } |
| 5412 | } |
| 5413 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5414 | if (info->attrs[NL80211_ATTR_IE]) { |
| 5415 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Johannes Berg | de95a54 | 2009-04-01 11:58:36 +0200 | [diff] [blame] | 5416 | memcpy((void *)request->ie, |
| 5417 | nla_data(info->attrs[NL80211_ATTR_IE]), |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5418 | request->ie_len); |
| 5419 | } |
| 5420 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5421 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) |
Johannes Berg | a401d2b | 2011-07-20 00:52:16 +0200 | [diff] [blame] | 5422 | if (wiphy->bands[i]) |
| 5423 | request->rates[i] = |
| 5424 | (1 << wiphy->bands[i]->n_bitrates) - 1; |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5425 | |
| 5426 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { |
| 5427 | nla_for_each_nested(attr, |
| 5428 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], |
| 5429 | tmp) { |
| 5430 | enum ieee80211_band band = nla_type(attr); |
| 5431 | |
Dan Carpenter | 8440462 | 2011-07-29 11:52:18 +0300 | [diff] [blame] | 5432 | if (band < 0 || band >= IEEE80211_NUM_BANDS) { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5433 | err = -EINVAL; |
| 5434 | goto out_free; |
| 5435 | } |
Felix Fietkau | 1b09cd8 | 2013-11-20 19:40:41 +0100 | [diff] [blame] | 5436 | |
| 5437 | if (!wiphy->bands[band]) |
| 5438 | continue; |
| 5439 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5440 | err = ieee80211_get_ratemask(wiphy->bands[band], |
| 5441 | nla_data(attr), |
| 5442 | nla_len(attr), |
| 5443 | &request->rates[band]); |
| 5444 | if (err) |
| 5445 | goto out_free; |
| 5446 | } |
| 5447 | } |
| 5448 | |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5449 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5450 | request->flags = nla_get_u32( |
| 5451 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); |
Johannes Berg | 00c3a6e | 2013-10-26 17:14:38 +0200 | [diff] [blame] | 5452 | if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 5453 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) { |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5454 | err = -EOPNOTSUPP; |
| 5455 | goto out_free; |
| 5456 | } |
| 5457 | } |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5458 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 5459 | request->no_cck = |
| 5460 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 5461 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 5462 | request->wdev = wdev; |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5463 | request->wiphy = &rdev->wiphy; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 5464 | request->scan_start = jiffies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5465 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5466 | rdev->scan_req = request; |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5467 | err = rdev_scan(rdev, request); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5468 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5469 | if (!err) { |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 5470 | nl80211_send_scan_start(rdev, wdev); |
| 5471 | if (wdev->netdev) |
| 5472 | dev_hold(wdev->netdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5473 | } else { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5474 | out_free: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5475 | rdev->scan_req = NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5476 | kfree(request); |
| 5477 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 5478 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5479 | unlock: |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5480 | return err; |
| 5481 | } |
| 5482 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5483 | static int nl80211_start_sched_scan(struct sk_buff *skb, |
| 5484 | struct genl_info *info) |
| 5485 | { |
| 5486 | struct cfg80211_sched_scan_request *request; |
| 5487 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5488 | struct net_device *dev = info->user_ptr[1]; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5489 | struct nlattr *attr; |
| 5490 | struct wiphy *wiphy; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5491 | 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] | 5492 | u32 interval; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5493 | enum ieee80211_band band; |
| 5494 | size_t ie_len; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5495 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 5496 | s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5497 | |
| 5498 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 5499 | !rdev->ops->sched_scan_start) |
| 5500 | return -EOPNOTSUPP; |
| 5501 | |
| 5502 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5503 | return -EINVAL; |
| 5504 | |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 5505 | if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
| 5506 | return -EINVAL; |
| 5507 | |
| 5508 | interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); |
| 5509 | if (interval == 0) |
| 5510 | return -EINVAL; |
| 5511 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5512 | wiphy = &rdev->wiphy; |
| 5513 | |
| 5514 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 5515 | n_channels = validate_scan_freqs( |
| 5516 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
| 5517 | if (!n_channels) |
| 5518 | return -EINVAL; |
| 5519 | } else { |
Ilan Peer | bdfbec2 | 2014-01-09 11:37:23 +0200 | [diff] [blame] | 5520 | n_channels = ieee80211_get_num_supported_channels(wiphy); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5521 | } |
| 5522 | |
| 5523 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 5524 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 5525 | tmp) |
| 5526 | n_ssids++; |
| 5527 | |
Luciano Coelho | 93b6aa6 | 2011-07-13 14:57:28 +0300 | [diff] [blame] | 5528 | if (n_ssids > wiphy->max_sched_scan_ssids) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5529 | return -EINVAL; |
| 5530 | |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 5531 | /* |
| 5532 | * First, count the number of 'real' matchsets. Due to an issue with |
| 5533 | * the old implementation, matchsets containing only the RSSI attribute |
| 5534 | * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default' |
| 5535 | * RSSI for all matchsets, rather than their own matchset for reporting |
| 5536 | * all APs with a strong RSSI. This is needed to be compatible with |
| 5537 | * older userspace that treated a matchset with only the RSSI as the |
| 5538 | * global RSSI for all other matchsets - if there are other matchsets. |
| 5539 | */ |
| 5540 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5541 | nla_for_each_nested(attr, |
| 5542 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 5543 | tmp) { |
| 5544 | struct nlattr *rssi; |
| 5545 | |
| 5546 | err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
| 5547 | nla_data(attr), nla_len(attr), |
| 5548 | nl80211_match_policy); |
| 5549 | if (err) |
| 5550 | return err; |
| 5551 | /* add other standalone attributes here */ |
| 5552 | if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]) { |
| 5553 | n_match_sets++; |
| 5554 | continue; |
| 5555 | } |
| 5556 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; |
| 5557 | if (rssi) |
| 5558 | default_match_rssi = nla_get_s32(rssi); |
| 5559 | } |
| 5560 | } |
| 5561 | |
| 5562 | /* However, if there's no other matchset, add the RSSI one */ |
| 5563 | if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF) |
| 5564 | n_match_sets = 1; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5565 | |
| 5566 | if (n_match_sets > wiphy->max_match_sets) |
| 5567 | return -EINVAL; |
| 5568 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5569 | if (info->attrs[NL80211_ATTR_IE]) |
| 5570 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5571 | else |
| 5572 | ie_len = 0; |
| 5573 | |
Luciano Coelho | 5a865ba | 2011-07-13 14:57:29 +0300 | [diff] [blame] | 5574 | if (ie_len > wiphy->max_sched_scan_ie_len) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5575 | return -EINVAL; |
| 5576 | |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 5577 | if (rdev->sched_scan_req) { |
| 5578 | err = -EINPROGRESS; |
| 5579 | goto out; |
| 5580 | } |
| 5581 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5582 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 5583 | + sizeof(*request->ssids) * n_ssids |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5584 | + sizeof(*request->match_sets) * n_match_sets |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 5585 | + sizeof(*request->channels) * n_channels |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5586 | + ie_len, GFP_KERNEL); |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 5587 | if (!request) { |
| 5588 | err = -ENOMEM; |
| 5589 | goto out; |
| 5590 | } |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5591 | |
| 5592 | if (n_ssids) |
| 5593 | request->ssids = (void *)&request->channels[n_channels]; |
| 5594 | request->n_ssids = n_ssids; |
| 5595 | if (ie_len) { |
| 5596 | if (request->ssids) |
| 5597 | request->ie = (void *)(request->ssids + n_ssids); |
| 5598 | else |
| 5599 | request->ie = (void *)(request->channels + n_channels); |
| 5600 | } |
| 5601 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5602 | if (n_match_sets) { |
| 5603 | if (request->ie) |
| 5604 | request->match_sets = (void *)(request->ie + ie_len); |
| 5605 | else if (request->ssids) |
| 5606 | request->match_sets = |
| 5607 | (void *)(request->ssids + n_ssids); |
| 5608 | else |
| 5609 | request->match_sets = |
| 5610 | (void *)(request->channels + n_channels); |
| 5611 | } |
| 5612 | request->n_match_sets = n_match_sets; |
| 5613 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5614 | i = 0; |
| 5615 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 5616 | /* user specified, bail out if channel not found */ |
| 5617 | nla_for_each_nested(attr, |
| 5618 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], |
| 5619 | tmp) { |
| 5620 | struct ieee80211_channel *chan; |
| 5621 | |
| 5622 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 5623 | |
| 5624 | if (!chan) { |
| 5625 | err = -EINVAL; |
| 5626 | goto out_free; |
| 5627 | } |
| 5628 | |
| 5629 | /* ignore disabled channels */ |
| 5630 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5631 | continue; |
| 5632 | |
| 5633 | request->channels[i] = chan; |
| 5634 | i++; |
| 5635 | } |
| 5636 | } else { |
| 5637 | /* all channels */ |
| 5638 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 5639 | int j; |
| 5640 | if (!wiphy->bands[band]) |
| 5641 | continue; |
| 5642 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
| 5643 | struct ieee80211_channel *chan; |
| 5644 | |
| 5645 | chan = &wiphy->bands[band]->channels[j]; |
| 5646 | |
| 5647 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5648 | continue; |
| 5649 | |
| 5650 | request->channels[i] = chan; |
| 5651 | i++; |
| 5652 | } |
| 5653 | } |
| 5654 | } |
| 5655 | |
| 5656 | if (!i) { |
| 5657 | err = -EINVAL; |
| 5658 | goto out_free; |
| 5659 | } |
| 5660 | |
| 5661 | request->n_channels = i; |
| 5662 | |
| 5663 | i = 0; |
| 5664 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 5665 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 5666 | tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5667 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5668 | err = -EINVAL; |
| 5669 | goto out_free; |
| 5670 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5671 | request->ssids[i].ssid_len = nla_len(attr); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5672 | memcpy(request->ssids[i].ssid, nla_data(attr), |
| 5673 | nla_len(attr)); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5674 | i++; |
| 5675 | } |
| 5676 | } |
| 5677 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5678 | i = 0; |
| 5679 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
| 5680 | nla_for_each_nested(attr, |
| 5681 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
| 5682 | tmp) { |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 5683 | struct nlattr *ssid, *rssi; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5684 | |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 5685 | err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
| 5686 | nla_data(attr), nla_len(attr), |
| 5687 | nl80211_match_policy); |
| 5688 | if (err) |
| 5689 | goto out_free; |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 5690 | ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5691 | if (ssid) { |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 5692 | if (WARN_ON(i >= n_match_sets)) { |
| 5693 | /* this indicates a programming error, |
| 5694 | * the loop above should have verified |
| 5695 | * things properly |
| 5696 | */ |
| 5697 | err = -EINVAL; |
| 5698 | goto out_free; |
| 5699 | } |
| 5700 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5701 | if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) { |
| 5702 | err = -EINVAL; |
| 5703 | goto out_free; |
| 5704 | } |
| 5705 | memcpy(request->match_sets[i].ssid.ssid, |
| 5706 | nla_data(ssid), nla_len(ssid)); |
| 5707 | request->match_sets[i].ssid.ssid_len = |
| 5708 | nla_len(ssid); |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 5709 | /* special attribute - old implemenation w/a */ |
| 5710 | request->match_sets[i].rssi_thold = |
| 5711 | default_match_rssi; |
| 5712 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; |
| 5713 | if (rssi) |
| 5714 | request->match_sets[i].rssi_thold = |
| 5715 | nla_get_s32(rssi); |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5716 | } |
| 5717 | i++; |
| 5718 | } |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 5719 | |
| 5720 | /* there was no other matchset, so the RSSI one is alone */ |
| 5721 | if (i == 0) |
| 5722 | request->match_sets[0].rssi_thold = default_match_rssi; |
| 5723 | |
| 5724 | request->min_rssi_thold = INT_MAX; |
| 5725 | for (i = 0; i < n_match_sets; i++) |
| 5726 | request->min_rssi_thold = |
| 5727 | min(request->match_sets[i].rssi_thold, |
| 5728 | request->min_rssi_thold); |
| 5729 | } else { |
| 5730 | request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5731 | } |
| 5732 | |
Johannes Berg | 9900e48 | 2014-02-04 21:01:25 +0100 | [diff] [blame] | 5733 | if (ie_len) { |
| 5734 | request->ie_len = ie_len; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5735 | memcpy((void *)request->ie, |
| 5736 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 5737 | request->ie_len); |
| 5738 | } |
| 5739 | |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5740 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5741 | request->flags = nla_get_u32( |
| 5742 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); |
Johannes Berg | 00c3a6e | 2013-10-26 17:14:38 +0200 | [diff] [blame] | 5743 | if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 5744 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) { |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5745 | err = -EOPNOTSUPP; |
| 5746 | goto out_free; |
| 5747 | } |
| 5748 | } |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5749 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5750 | request->dev = dev; |
| 5751 | request->wiphy = &rdev->wiphy; |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 5752 | request->interval = interval; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 5753 | request->scan_start = jiffies; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5754 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5755 | err = rdev_sched_scan_start(rdev, dev, request); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5756 | if (!err) { |
| 5757 | rdev->sched_scan_req = request; |
| 5758 | nl80211_send_sched_scan(rdev, dev, |
| 5759 | NL80211_CMD_START_SCHED_SCAN); |
| 5760 | goto out; |
| 5761 | } |
| 5762 | |
| 5763 | out_free: |
| 5764 | kfree(request); |
| 5765 | out: |
| 5766 | return err; |
| 5767 | } |
| 5768 | |
| 5769 | static int nl80211_stop_sched_scan(struct sk_buff *skb, |
| 5770 | struct genl_info *info) |
| 5771 | { |
| 5772 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5773 | |
| 5774 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 5775 | !rdev->ops->sched_scan_stop) |
| 5776 | return -EOPNOTSUPP; |
| 5777 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5778 | return __cfg80211_stop_sched_scan(rdev, false); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5779 | } |
| 5780 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5781 | static int nl80211_start_radar_detection(struct sk_buff *skb, |
| 5782 | struct genl_info *info) |
| 5783 | { |
| 5784 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5785 | struct net_device *dev = info->user_ptr[1]; |
| 5786 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 5787 | struct cfg80211_chan_def chandef; |
Luis R. Rodriguez | 55f7435 | 2013-11-25 20:56:10 +0100 | [diff] [blame] | 5788 | enum nl80211_dfs_regions dfs_region; |
Janusz Dziedzic | 31559f3 | 2014-02-21 19:46:13 +0100 | [diff] [blame] | 5789 | unsigned int cac_time_ms; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5790 | int err; |
| 5791 | |
Luis R. Rodriguez | 55f7435 | 2013-11-25 20:56:10 +0100 | [diff] [blame] | 5792 | dfs_region = reg_get_dfs_region(wdev->wiphy); |
| 5793 | if (dfs_region == NL80211_DFS_UNSET) |
| 5794 | return -EINVAL; |
| 5795 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5796 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 5797 | if (err) |
| 5798 | return err; |
| 5799 | |
Simon Wunderlich | ff311bc | 2013-09-03 19:43:18 +0200 | [diff] [blame] | 5800 | if (netif_carrier_ok(dev)) |
| 5801 | return -EBUSY; |
| 5802 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5803 | if (wdev->cac_started) |
| 5804 | return -EBUSY; |
| 5805 | |
Luciano Coelho | 2beb6da | 2014-02-18 11:40:36 +0200 | [diff] [blame] | 5806 | err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, |
| 5807 | NL80211_IFTYPE_UNSPECIFIED); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5808 | if (err < 0) |
| 5809 | return err; |
| 5810 | |
| 5811 | if (err == 0) |
| 5812 | return -EINVAL; |
| 5813 | |
Janusz Dziedzic | fe7c3a1 | 2013-11-05 14:48:48 +0100 | [diff] [blame] | 5814 | if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef)) |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5815 | return -EINVAL; |
| 5816 | |
| 5817 | if (!rdev->ops->start_radar_detection) |
| 5818 | return -EOPNOTSUPP; |
| 5819 | |
Janusz Dziedzic | 31559f3 | 2014-02-21 19:46:13 +0100 | [diff] [blame] | 5820 | cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef); |
| 5821 | if (WARN_ON(!cac_time_ms)) |
| 5822 | cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS; |
| 5823 | |
| 5824 | err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef, |
| 5825 | cac_time_ms); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5826 | if (!err) { |
Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 5827 | wdev->chandef = chandef; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5828 | wdev->cac_started = true; |
| 5829 | wdev->cac_start_time = jiffies; |
Janusz Dziedzic | 31559f3 | 2014-02-21 19:46:13 +0100 | [diff] [blame] | 5830 | wdev->cac_time_ms = cac_time_ms; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5831 | } |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5832 | return err; |
| 5833 | } |
| 5834 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5835 | static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info) |
| 5836 | { |
| 5837 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5838 | struct net_device *dev = info->user_ptr[1]; |
| 5839 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 5840 | struct cfg80211_csa_settings params; |
| 5841 | /* csa_attrs is defined static to avoid waste of stack size - this |
| 5842 | * function is called under RTNL lock, so this should not be a problem. |
| 5843 | */ |
| 5844 | static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1]; |
| 5845 | u8 radar_detect_width = 0; |
| 5846 | int err; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5847 | bool need_new_beacon = false; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5848 | |
| 5849 | if (!rdev->ops->channel_switch || |
| 5850 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)) |
| 5851 | return -EOPNOTSUPP; |
| 5852 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5853 | switch (dev->ieee80211_ptr->iftype) { |
| 5854 | case NL80211_IFTYPE_AP: |
| 5855 | case NL80211_IFTYPE_P2P_GO: |
| 5856 | need_new_beacon = true; |
| 5857 | |
| 5858 | /* useless if AP is not running */ |
| 5859 | if (!wdev->beacon_interval) |
Johannes Berg | 1ff79df | 2014-01-22 10:05:27 +0100 | [diff] [blame] | 5860 | return -ENOTCONN; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5861 | break; |
| 5862 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | 1ff79df | 2014-01-22 10:05:27 +0100 | [diff] [blame] | 5863 | if (!wdev->ssid_len) |
| 5864 | return -ENOTCONN; |
| 5865 | break; |
Chun-Yeow Yeoh | c6da674 | 2013-10-14 19:08:28 -0700 | [diff] [blame] | 5866 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 1ff79df | 2014-01-22 10:05:27 +0100 | [diff] [blame] | 5867 | if (!wdev->mesh_id_len) |
| 5868 | return -ENOTCONN; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5869 | break; |
| 5870 | default: |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5871 | return -EOPNOTSUPP; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5872 | } |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5873 | |
| 5874 | memset(¶ms, 0, sizeof(params)); |
| 5875 | |
| 5876 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 5877 | !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]) |
| 5878 | return -EINVAL; |
| 5879 | |
| 5880 | /* only important for AP, IBSS and mesh create IEs internally */ |
Andrei Otcheretianski | d0a361a | 2013-10-17 10:52:17 +0200 | [diff] [blame] | 5881 | if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES]) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5882 | return -EINVAL; |
| 5883 | |
| 5884 | params.count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]); |
| 5885 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5886 | if (!need_new_beacon) |
| 5887 | goto skip_beacons; |
| 5888 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5889 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon_after); |
| 5890 | if (err) |
| 5891 | return err; |
| 5892 | |
| 5893 | err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX, |
| 5894 | info->attrs[NL80211_ATTR_CSA_IES], |
| 5895 | nl80211_policy); |
| 5896 | if (err) |
| 5897 | return err; |
| 5898 | |
| 5899 | err = nl80211_parse_beacon(csa_attrs, ¶ms.beacon_csa); |
| 5900 | if (err) |
| 5901 | return err; |
| 5902 | |
| 5903 | if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]) |
| 5904 | return -EINVAL; |
| 5905 | |
| 5906 | params.counter_offset_beacon = |
| 5907 | nla_get_u16(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); |
| 5908 | if (params.counter_offset_beacon >= params.beacon_csa.tail_len) |
| 5909 | return -EINVAL; |
| 5910 | |
| 5911 | /* sanity check - counters should be the same */ |
| 5912 | if (params.beacon_csa.tail[params.counter_offset_beacon] != |
| 5913 | params.count) |
| 5914 | return -EINVAL; |
| 5915 | |
| 5916 | if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) { |
| 5917 | params.counter_offset_presp = |
| 5918 | nla_get_u16(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); |
| 5919 | if (params.counter_offset_presp >= |
| 5920 | params.beacon_csa.probe_resp_len) |
| 5921 | return -EINVAL; |
| 5922 | |
| 5923 | if (params.beacon_csa.probe_resp[params.counter_offset_presp] != |
| 5924 | params.count) |
| 5925 | return -EINVAL; |
| 5926 | } |
| 5927 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5928 | skip_beacons: |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5929 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
| 5930 | if (err) |
| 5931 | return err; |
| 5932 | |
Ilan Peer | 174e0cd | 2014-02-23 09:13:01 +0200 | [diff] [blame] | 5933 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, ¶ms.chandef, |
| 5934 | wdev->iftype)) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5935 | return -EINVAL; |
| 5936 | |
Luciano Coelho | 2beb6da | 2014-02-18 11:40:36 +0200 | [diff] [blame] | 5937 | err = cfg80211_chandef_dfs_required(wdev->wiphy, |
| 5938 | ¶ms.chandef, |
| 5939 | wdev->iftype); |
| 5940 | if (err < 0) |
| 5941 | return err; |
| 5942 | |
| 5943 | if (err > 0) { |
| 5944 | radar_detect_width = BIT(params.chandef.width); |
| 5945 | params.radar_required = true; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5946 | } |
| 5947 | |
Luciano Coelho | 73de86a | 2014-02-13 11:31:59 +0200 | [diff] [blame] | 5948 | /* TODO: I left this here for now. With channel switch, the |
| 5949 | * verification is a bit more complicated, because we only do |
| 5950 | * it later when the channel switch really happens. |
| 5951 | */ |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5952 | err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype, |
| 5953 | params.chandef.chan, |
| 5954 | CHAN_MODE_SHARED, |
| 5955 | radar_detect_width); |
| 5956 | if (err) |
| 5957 | return err; |
| 5958 | |
| 5959 | if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX]) |
| 5960 | params.block_tx = true; |
| 5961 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 5962 | wdev_lock(wdev); |
| 5963 | err = rdev_channel_switch(rdev, dev, ¶ms); |
| 5964 | wdev_unlock(wdev); |
| 5965 | |
| 5966 | return err; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5967 | } |
| 5968 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 5969 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
| 5970 | u32 seq, int flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5971 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5972 | struct wireless_dev *wdev, |
| 5973 | struct cfg80211_internal_bss *intbss) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5974 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5975 | struct cfg80211_bss *res = &intbss->pub; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5976 | const struct cfg80211_bss_ies *ies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5977 | void *hdr; |
| 5978 | struct nlattr *bss; |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5979 | bool tsf = false; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5980 | |
| 5981 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5982 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5983 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5984 | NL80211_CMD_NEW_SCAN_RESULTS); |
| 5985 | if (!hdr) |
| 5986 | return -1; |
| 5987 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 5988 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
| 5989 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5990 | if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation)) |
| 5991 | goto nla_put_failure; |
| 5992 | if (wdev->netdev && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5993 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex)) |
| 5994 | goto nla_put_failure; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5995 | if (nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 5996 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5997 | |
| 5998 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); |
| 5999 | if (!bss) |
| 6000 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6001 | if ((!is_zero_ether_addr(res->bssid) && |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 6002 | nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6003 | goto nla_put_failure; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 6004 | |
| 6005 | rcu_read_lock(); |
| 6006 | ies = rcu_dereference(res->ies); |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 6007 | if (ies) { |
| 6008 | if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf)) |
| 6009 | goto fail_unlock_rcu; |
| 6010 | tsf = true; |
| 6011 | if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS, |
| 6012 | ies->len, ies->data)) |
| 6013 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 6014 | } |
| 6015 | ies = rcu_dereference(res->beacon_ies); |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 6016 | if (ies) { |
| 6017 | if (!tsf && nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf)) |
| 6018 | goto fail_unlock_rcu; |
| 6019 | if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES, |
| 6020 | ies->len, ies->data)) |
| 6021 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 6022 | } |
| 6023 | rcu_read_unlock(); |
| 6024 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6025 | if (res->beacon_interval && |
| 6026 | nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval)) |
| 6027 | goto nla_put_failure; |
| 6028 | if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) || |
| 6029 | nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) || |
Simon Wunderlich | dcd6eac | 2013-07-08 16:55:49 +0200 | [diff] [blame] | 6030 | nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6031 | nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO, |
| 6032 | jiffies_to_msecs(jiffies - intbss->ts))) |
| 6033 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6034 | |
Johannes Berg | 77965c9 | 2009-02-18 18:45:06 +0100 | [diff] [blame] | 6035 | switch (rdev->wiphy.signal_type) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6036 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6037 | if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal)) |
| 6038 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6039 | break; |
| 6040 | case CFG80211_SIGNAL_TYPE_UNSPEC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6041 | if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal)) |
| 6042 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6043 | break; |
| 6044 | default: |
| 6045 | break; |
| 6046 | } |
| 6047 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6048 | switch (wdev->iftype) { |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6049 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6050 | case NL80211_IFTYPE_STATION: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6051 | if (intbss == wdev->current_bss && |
| 6052 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 6053 | NL80211_BSS_STATUS_ASSOCIATED)) |
| 6054 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6055 | break; |
| 6056 | case NL80211_IFTYPE_ADHOC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6057 | if (intbss == wdev->current_bss && |
| 6058 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 6059 | NL80211_BSS_STATUS_IBSS_JOINED)) |
| 6060 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6061 | break; |
| 6062 | default: |
| 6063 | break; |
| 6064 | } |
| 6065 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6066 | nla_nest_end(msg, bss); |
| 6067 | |
| 6068 | return genlmsg_end(msg, hdr); |
| 6069 | |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 6070 | fail_unlock_rcu: |
| 6071 | rcu_read_unlock(); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6072 | nla_put_failure: |
| 6073 | genlmsg_cancel(msg, hdr); |
| 6074 | return -EMSGSIZE; |
| 6075 | } |
| 6076 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6077 | 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] | 6078 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6079 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6080 | struct cfg80211_internal_bss *scan; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6081 | struct wireless_dev *wdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6082 | int start = cb->args[2], idx = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6083 | int err; |
| 6084 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6085 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 6086 | if (err) |
| 6087 | return err; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6088 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6089 | wdev_lock(wdev); |
| 6090 | spin_lock_bh(&rdev->bss_lock); |
| 6091 | cfg80211_bss_expire(rdev); |
| 6092 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 6093 | cb->seq = rdev->bss_generation; |
| 6094 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6095 | list_for_each_entry(scan, &rdev->bss_list, list) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6096 | if (++idx <= start) |
| 6097 | continue; |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 6098 | if (nl80211_send_bss(skb, cb, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6099 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6100 | rdev, wdev, scan) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6101 | idx--; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 6102 | break; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6103 | } |
| 6104 | } |
| 6105 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6106 | spin_unlock_bh(&rdev->bss_lock); |
| 6107 | wdev_unlock(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6108 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6109 | cb->args[2] = idx; |
| 6110 | nl80211_finish_wdev_dump(rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6111 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 6112 | return skb->len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6113 | } |
| 6114 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6115 | 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] | 6116 | int flags, struct net_device *dev, |
| 6117 | struct survey_info *survey) |
| 6118 | { |
| 6119 | void *hdr; |
| 6120 | struct nlattr *infoattr; |
| 6121 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6122 | hdr = nl80211hdr_put(msg, portid, seq, flags, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6123 | NL80211_CMD_NEW_SURVEY_RESULTS); |
| 6124 | if (!hdr) |
| 6125 | return -ENOMEM; |
| 6126 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6127 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
| 6128 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6129 | |
| 6130 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); |
| 6131 | if (!infoattr) |
| 6132 | goto nla_put_failure; |
| 6133 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6134 | if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY, |
| 6135 | survey->channel->center_freq)) |
| 6136 | goto nla_put_failure; |
| 6137 | |
| 6138 | if ((survey->filled & SURVEY_INFO_NOISE_DBM) && |
| 6139 | nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise)) |
| 6140 | goto nla_put_failure; |
| 6141 | if ((survey->filled & SURVEY_INFO_IN_USE) && |
| 6142 | nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE)) |
| 6143 | goto nla_put_failure; |
| 6144 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) && |
| 6145 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME, |
| 6146 | survey->channel_time)) |
| 6147 | goto nla_put_failure; |
| 6148 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) && |
| 6149 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY, |
| 6150 | survey->channel_time_busy)) |
| 6151 | goto nla_put_failure; |
| 6152 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) && |
| 6153 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY, |
| 6154 | survey->channel_time_ext_busy)) |
| 6155 | goto nla_put_failure; |
| 6156 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) && |
| 6157 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX, |
| 6158 | survey->channel_time_rx)) |
| 6159 | goto nla_put_failure; |
| 6160 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) && |
| 6161 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX, |
| 6162 | survey->channel_time_tx)) |
| 6163 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6164 | |
| 6165 | nla_nest_end(msg, infoattr); |
| 6166 | |
| 6167 | return genlmsg_end(msg, hdr); |
| 6168 | |
| 6169 | nla_put_failure: |
| 6170 | genlmsg_cancel(msg, hdr); |
| 6171 | return -EMSGSIZE; |
| 6172 | } |
| 6173 | |
| 6174 | static int nl80211_dump_survey(struct sk_buff *skb, |
| 6175 | struct netlink_callback *cb) |
| 6176 | { |
| 6177 | struct survey_info survey; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 6178 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6179 | struct wireless_dev *wdev; |
| 6180 | int survey_idx = cb->args[2]; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6181 | int res; |
| 6182 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 6183 | res = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 6184 | if (res) |
| 6185 | return res; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6186 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6187 | if (!wdev->netdev) { |
| 6188 | res = -EINVAL; |
| 6189 | goto out_err; |
| 6190 | } |
| 6191 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 6192 | if (!rdev->ops->dump_survey) { |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6193 | res = -EOPNOTSUPP; |
| 6194 | goto out_err; |
| 6195 | } |
| 6196 | |
| 6197 | while (1) { |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 6198 | struct ieee80211_channel *chan; |
| 6199 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 6200 | res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6201 | if (res == -ENOENT) |
| 6202 | break; |
| 6203 | if (res) |
| 6204 | goto out_err; |
| 6205 | |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 6206 | /* Survey without a channel doesn't make sense */ |
| 6207 | if (!survey.channel) { |
| 6208 | res = -EINVAL; |
| 6209 | goto out; |
| 6210 | } |
| 6211 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 6212 | chan = ieee80211_get_channel(&rdev->wiphy, |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 6213 | survey.channel->center_freq); |
| 6214 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) { |
| 6215 | survey_idx++; |
| 6216 | continue; |
| 6217 | } |
| 6218 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6219 | if (nl80211_send_survey(skb, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6220 | NETLINK_CB(cb->skb).portid, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6221 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6222 | wdev->netdev, &survey) < 0) |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6223 | goto out; |
| 6224 | survey_idx++; |
| 6225 | } |
| 6226 | |
| 6227 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6228 | cb->args[2] = survey_idx; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6229 | res = skb->len; |
| 6230 | out_err: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 6231 | nl80211_finish_wdev_dump(rdev); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6232 | return res; |
| 6233 | } |
| 6234 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6235 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
| 6236 | { |
| 6237 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | |
| 6238 | NL80211_WPA_VERSION_2)); |
| 6239 | } |
| 6240 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6241 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
| 6242 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6243 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6244 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6245 | struct ieee80211_channel *chan; |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 6246 | const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL; |
| 6247 | int err, ssid_len, ie_len = 0, sae_data_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6248 | enum nl80211_auth_type auth_type; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6249 | struct key_parse key; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6250 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6251 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6252 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6253 | return -EINVAL; |
| 6254 | |
| 6255 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6256 | return -EINVAL; |
| 6257 | |
Jouni Malinen | 1778092 | 2009-03-27 20:52:47 +0200 | [diff] [blame] | 6258 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
| 6259 | return -EINVAL; |
| 6260 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6261 | if (!info->attrs[NL80211_ATTR_SSID]) |
| 6262 | return -EINVAL; |
| 6263 | |
| 6264 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 6265 | return -EINVAL; |
| 6266 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6267 | err = nl80211_parse_key(info, &key); |
| 6268 | if (err) |
| 6269 | return err; |
| 6270 | |
| 6271 | if (key.idx >= 0) { |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 6272 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
| 6273 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6274 | if (!key.p.key || !key.p.key_len) |
| 6275 | return -EINVAL; |
| 6276 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || |
| 6277 | key.p.key_len != WLAN_KEY_LEN_WEP40) && |
| 6278 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || |
| 6279 | key.p.key_len != WLAN_KEY_LEN_WEP104)) |
| 6280 | return -EINVAL; |
| 6281 | if (key.idx > 4) |
| 6282 | return -EINVAL; |
| 6283 | } else { |
| 6284 | key.p.key_len = 0; |
| 6285 | key.p.key = NULL; |
| 6286 | } |
| 6287 | |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 6288 | if (key.idx >= 0) { |
| 6289 | int i; |
| 6290 | bool ok = false; |
| 6291 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { |
| 6292 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { |
| 6293 | ok = true; |
| 6294 | break; |
| 6295 | } |
| 6296 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6297 | if (!ok) |
| 6298 | return -EINVAL; |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 6299 | } |
| 6300 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6301 | if (!rdev->ops->auth) |
| 6302 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6303 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6304 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6305 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6306 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6307 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6308 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 6309 | chan = nl80211_get_valid_chan(&rdev->wiphy, |
| 6310 | info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 6311 | if (!chan) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6312 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6313 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6314 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 6315 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 6316 | |
| 6317 | if (info->attrs[NL80211_ATTR_IE]) { |
| 6318 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6319 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 6320 | } |
| 6321 | |
| 6322 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 6323 | if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6324 | return -EINVAL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6325 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 6326 | if (auth_type == NL80211_AUTHTYPE_SAE && |
| 6327 | !info->attrs[NL80211_ATTR_SAE_DATA]) |
| 6328 | return -EINVAL; |
| 6329 | |
| 6330 | if (info->attrs[NL80211_ATTR_SAE_DATA]) { |
| 6331 | if (auth_type != NL80211_AUTHTYPE_SAE) |
| 6332 | return -EINVAL; |
| 6333 | sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]); |
| 6334 | sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]); |
| 6335 | /* need to include at least Auth Transaction and Status Code */ |
| 6336 | if (sae_data_len < 4) |
| 6337 | return -EINVAL; |
| 6338 | } |
| 6339 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6340 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 6341 | |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 6342 | /* |
| 6343 | * Since we no longer track auth state, ignore |
| 6344 | * requests to only change local state. |
| 6345 | */ |
| 6346 | if (local_state_change) |
| 6347 | return 0; |
| 6348 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6349 | wdev_lock(dev->ieee80211_ptr); |
| 6350 | err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, |
| 6351 | ssid, ssid_len, ie, ie_len, |
| 6352 | key.p.key, key.p.key_len, key.idx, |
| 6353 | sae_data, sae_data_len); |
| 6354 | wdev_unlock(dev->ieee80211_ptr); |
| 6355 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6356 | } |
| 6357 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 6358 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 6359 | struct genl_info *info, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 6360 | struct cfg80211_crypto_settings *settings, |
| 6361 | int cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6362 | { |
Johannes Berg | c0b2bbd | 2009-07-25 16:54:36 +0200 | [diff] [blame] | 6363 | memset(settings, 0, sizeof(*settings)); |
| 6364 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6365 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
| 6366 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 6367 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
| 6368 | u16 proto; |
| 6369 | proto = nla_get_u16( |
| 6370 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); |
| 6371 | settings->control_port_ethertype = cpu_to_be16(proto); |
| 6372 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 6373 | proto != ETH_P_PAE) |
| 6374 | return -EINVAL; |
| 6375 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) |
| 6376 | settings->control_port_no_encrypt = true; |
| 6377 | } else |
| 6378 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); |
| 6379 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6380 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
| 6381 | void *data; |
| 6382 | int len, i; |
| 6383 | |
| 6384 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 6385 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 6386 | settings->n_ciphers_pairwise = len / sizeof(u32); |
| 6387 | |
| 6388 | if (len % sizeof(u32)) |
| 6389 | return -EINVAL; |
| 6390 | |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 6391 | if (settings->n_ciphers_pairwise > cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6392 | return -EINVAL; |
| 6393 | |
| 6394 | memcpy(settings->ciphers_pairwise, data, len); |
| 6395 | |
| 6396 | for (i = 0; i < settings->n_ciphers_pairwise; i++) |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 6397 | if (!cfg80211_supported_cipher_suite( |
| 6398 | &rdev->wiphy, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6399 | settings->ciphers_pairwise[i])) |
| 6400 | return -EINVAL; |
| 6401 | } |
| 6402 | |
| 6403 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { |
| 6404 | settings->cipher_group = |
| 6405 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 6406 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
| 6407 | settings->cipher_group)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6408 | return -EINVAL; |
| 6409 | } |
| 6410 | |
| 6411 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { |
| 6412 | settings->wpa_versions = |
| 6413 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); |
| 6414 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) |
| 6415 | return -EINVAL; |
| 6416 | } |
| 6417 | |
| 6418 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { |
| 6419 | void *data; |
Jouni Malinen | 6d30240 | 2011-09-21 18:11:33 +0300 | [diff] [blame] | 6420 | int len; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6421 | |
| 6422 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 6423 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 6424 | settings->n_akm_suites = len / sizeof(u32); |
| 6425 | |
| 6426 | if (len % sizeof(u32)) |
| 6427 | return -EINVAL; |
| 6428 | |
Jouni Malinen | 1b9ca02 | 2011-09-21 16:13:07 +0300 | [diff] [blame] | 6429 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) |
| 6430 | return -EINVAL; |
| 6431 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6432 | memcpy(settings->akm_suites, data, len); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6433 | } |
| 6434 | |
| 6435 | return 0; |
| 6436 | } |
| 6437 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6438 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
| 6439 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6440 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6441 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 6442 | struct ieee80211_channel *chan; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6443 | struct cfg80211_assoc_request req = {}; |
| 6444 | const u8 *bssid, *ssid; |
| 6445 | int err, ssid_len = 0; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6446 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6447 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6448 | return -EINVAL; |
| 6449 | |
| 6450 | if (!info->attrs[NL80211_ATTR_MAC] || |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6451 | !info->attrs[NL80211_ATTR_SSID] || |
| 6452 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6453 | return -EINVAL; |
| 6454 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6455 | if (!rdev->ops->assoc) |
| 6456 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6457 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6458 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6459 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6460 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6461 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6462 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6463 | |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 6464 | chan = nl80211_get_valid_chan(&rdev->wiphy, |
| 6465 | info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 6466 | if (!chan) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6467 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6468 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6469 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 6470 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6471 | |
| 6472 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6473 | req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6474 | req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6475 | } |
| 6476 | |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 6477 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 6478 | enum nl80211_mfp mfp = |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 6479 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 6480 | if (mfp == NL80211_MFP_REQUIRED) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6481 | req.use_mfp = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6482 | else if (mfp != NL80211_MFP_NO) |
| 6483 | return -EINVAL; |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 6484 | } |
| 6485 | |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 6486 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6487 | req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 6488 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6489 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6490 | req.flags |= ASSOC_REQ_DISABLE_HT; |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6491 | |
| 6492 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6493 | memcpy(&req.ht_capa_mask, |
| 6494 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 6495 | sizeof(req.ht_capa_mask)); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6496 | |
| 6497 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6498 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6499 | return -EINVAL; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6500 | memcpy(&req.ht_capa, |
| 6501 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 6502 | sizeof(req.ht_capa)); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6503 | } |
| 6504 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6505 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6506 | req.flags |= ASSOC_REQ_DISABLE_VHT; |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6507 | |
| 6508 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6509 | memcpy(&req.vht_capa_mask, |
| 6510 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), |
| 6511 | sizeof(req.vht_capa_mask)); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6512 | |
| 6513 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6514 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6515 | return -EINVAL; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6516 | memcpy(&req.vht_capa, |
| 6517 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), |
| 6518 | sizeof(req.vht_capa)); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6519 | } |
| 6520 | |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6521 | err = nl80211_crypto_settings(rdev, info, &req.crypto, 1); |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6522 | if (!err) { |
| 6523 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6524 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, |
| 6525 | ssid, ssid_len, &req); |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6526 | wdev_unlock(dev->ieee80211_ptr); |
| 6527 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6528 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6529 | return err; |
| 6530 | } |
| 6531 | |
| 6532 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) |
| 6533 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6534 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6535 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6536 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6537 | int ie_len = 0, err; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6538 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6539 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6540 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6541 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6542 | return -EINVAL; |
| 6543 | |
| 6544 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6545 | return -EINVAL; |
| 6546 | |
| 6547 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 6548 | return -EINVAL; |
| 6549 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6550 | if (!rdev->ops->deauth) |
| 6551 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6552 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6553 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6554 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6555 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6556 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6557 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6558 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6559 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 6560 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6561 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6562 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 6563 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6564 | |
| 6565 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6566 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6567 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6568 | } |
| 6569 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6570 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 6571 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6572 | wdev_lock(dev->ieee80211_ptr); |
| 6573 | err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, |
| 6574 | local_state_change); |
| 6575 | wdev_unlock(dev->ieee80211_ptr); |
| 6576 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6577 | } |
| 6578 | |
| 6579 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) |
| 6580 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6581 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6582 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6583 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6584 | int ie_len = 0, err; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6585 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6586 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6587 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6588 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6589 | return -EINVAL; |
| 6590 | |
| 6591 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6592 | return -EINVAL; |
| 6593 | |
| 6594 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 6595 | return -EINVAL; |
| 6596 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6597 | if (!rdev->ops->disassoc) |
| 6598 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6599 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6600 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6601 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6602 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6603 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6604 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6605 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6606 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 6607 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6608 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6609 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 6610 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6611 | |
| 6612 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6613 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6614 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6615 | } |
| 6616 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6617 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 6618 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6619 | wdev_lock(dev->ieee80211_ptr); |
| 6620 | err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, |
| 6621 | local_state_change); |
| 6622 | wdev_unlock(dev->ieee80211_ptr); |
| 6623 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6624 | } |
| 6625 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 6626 | static bool |
| 6627 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, |
| 6628 | int mcast_rate[IEEE80211_NUM_BANDS], |
| 6629 | int rateval) |
| 6630 | { |
| 6631 | struct wiphy *wiphy = &rdev->wiphy; |
| 6632 | bool found = false; |
| 6633 | int band, i; |
| 6634 | |
| 6635 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 6636 | struct ieee80211_supported_band *sband; |
| 6637 | |
| 6638 | sband = wiphy->bands[band]; |
| 6639 | if (!sband) |
| 6640 | continue; |
| 6641 | |
| 6642 | for (i = 0; i < sband->n_bitrates; i++) { |
| 6643 | if (sband->bitrates[i].bitrate == rateval) { |
| 6644 | mcast_rate[band] = i + 1; |
| 6645 | found = true; |
| 6646 | break; |
| 6647 | } |
| 6648 | } |
| 6649 | } |
| 6650 | |
| 6651 | return found; |
| 6652 | } |
| 6653 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6654 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
| 6655 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6656 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6657 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6658 | struct cfg80211_ibss_params ibss; |
| 6659 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6660 | struct cfg80211_cached_keys *connkeys = NULL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6661 | int err; |
| 6662 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 6663 | memset(&ibss, 0, sizeof(ibss)); |
| 6664 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6665 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6666 | return -EINVAL; |
| 6667 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6668 | if (!info->attrs[NL80211_ATTR_SSID] || |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6669 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 6670 | return -EINVAL; |
| 6671 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 6672 | ibss.beacon_interval = 100; |
| 6673 | |
| 6674 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 6675 | ibss.beacon_interval = |
| 6676 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 6677 | if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000) |
| 6678 | return -EINVAL; |
| 6679 | } |
| 6680 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6681 | if (!rdev->ops->join_ibss) |
| 6682 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6683 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6684 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 6685 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6686 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 6687 | wiphy = &rdev->wiphy; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6688 | |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 6689 | if (info->attrs[NL80211_ATTR_MAC]) { |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6690 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 6691 | |
| 6692 | if (!is_valid_ether_addr(ibss.bssid)) |
| 6693 | return -EINVAL; |
| 6694 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6695 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 6696 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 6697 | |
| 6698 | if (info->attrs[NL80211_ATTR_IE]) { |
| 6699 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6700 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 6701 | } |
| 6702 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6703 | err = nl80211_parse_chandef(rdev, info, &ibss.chandef); |
| 6704 | if (err) |
| 6705 | return err; |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 6706 | |
Ilan Peer | 174e0cd | 2014-02-23 09:13:01 +0200 | [diff] [blame] | 6707 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef, |
| 6708 | NL80211_IFTYPE_ADHOC)) |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 6709 | return -EINVAL; |
| 6710 | |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 6711 | switch (ibss.chandef.width) { |
Simon Wunderlich | bf37264 | 2013-07-08 16:55:58 +0200 | [diff] [blame] | 6712 | case NL80211_CHAN_WIDTH_5: |
| 6713 | case NL80211_CHAN_WIDTH_10: |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 6714 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 6715 | break; |
| 6716 | case NL80211_CHAN_WIDTH_20: |
| 6717 | case NL80211_CHAN_WIDTH_40: |
| 6718 | if (rdev->wiphy.features & NL80211_FEATURE_HT_IBSS) |
| 6719 | break; |
| 6720 | default: |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 6721 | return -EINVAL; |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 6722 | } |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 6723 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6724 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6725 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6726 | |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 6727 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 6728 | u8 *rates = |
| 6729 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 6730 | int n_rates = |
| 6731 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 6732 | struct ieee80211_supported_band *sband = |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6733 | wiphy->bands[ibss.chandef.chan->band]; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 6734 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 6735 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 6736 | &ibss.basic_rates); |
| 6737 | if (err) |
| 6738 | return err; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 6739 | } |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 6740 | |
Simon Wunderlich | 803768f | 2013-06-28 10:39:58 +0200 | [diff] [blame] | 6741 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 6742 | memcpy(&ibss.ht_capa_mask, |
| 6743 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 6744 | sizeof(ibss.ht_capa_mask)); |
| 6745 | |
| 6746 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
| 6747 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 6748 | return -EINVAL; |
| 6749 | memcpy(&ibss.ht_capa, |
| 6750 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 6751 | sizeof(ibss.ht_capa)); |
| 6752 | } |
| 6753 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 6754 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 6755 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, |
| 6756 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 6757 | return -EINVAL; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 6758 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6759 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6760 | bool no_ht = false; |
| 6761 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6762 | connkeys = nl80211_parse_connkeys(rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6763 | info->attrs[NL80211_ATTR_KEYS], |
| 6764 | &no_ht); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6765 | if (IS_ERR(connkeys)) |
| 6766 | return PTR_ERR(connkeys); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6767 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 6768 | if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) && |
| 6769 | no_ht) { |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6770 | kfree(connkeys); |
| 6771 | return -EINVAL; |
| 6772 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6773 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6774 | |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 6775 | ibss.control_port = |
| 6776 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]); |
| 6777 | |
Simon Wunderlich | 5336fa8 | 2013-10-07 18:41:05 +0200 | [diff] [blame] | 6778 | ibss.userspace_handles_dfs = |
| 6779 | nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]); |
| 6780 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6781 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6782 | if (err) |
| 6783 | kfree(connkeys); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6784 | return err; |
| 6785 | } |
| 6786 | |
| 6787 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) |
| 6788 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6789 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6790 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6791 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6792 | if (!rdev->ops->leave_ibss) |
| 6793 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6794 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6795 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 6796 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6797 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6798 | return cfg80211_leave_ibss(rdev, dev, false); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6799 | } |
| 6800 | |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 6801 | static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info) |
| 6802 | { |
| 6803 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6804 | struct net_device *dev = info->user_ptr[1]; |
| 6805 | int mcast_rate[IEEE80211_NUM_BANDS]; |
| 6806 | u32 nla_rate; |
| 6807 | int err; |
| 6808 | |
| 6809 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
| 6810 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 6811 | return -EOPNOTSUPP; |
| 6812 | |
| 6813 | if (!rdev->ops->set_mcast_rate) |
| 6814 | return -EOPNOTSUPP; |
| 6815 | |
| 6816 | memset(mcast_rate, 0, sizeof(mcast_rate)); |
| 6817 | |
| 6818 | if (!info->attrs[NL80211_ATTR_MCAST_RATE]) |
| 6819 | return -EINVAL; |
| 6820 | |
| 6821 | nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]); |
| 6822 | if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate)) |
| 6823 | return -EINVAL; |
| 6824 | |
| 6825 | err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate); |
| 6826 | |
| 6827 | return err; |
| 6828 | } |
| 6829 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 6830 | static struct sk_buff * |
| 6831 | __cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev, |
| 6832 | int approxlen, u32 portid, u32 seq, |
| 6833 | enum nl80211_commands cmd, |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 6834 | enum nl80211_attrs attr, |
| 6835 | const struct nl80211_vendor_cmd_info *info, |
| 6836 | gfp_t gfp) |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 6837 | { |
| 6838 | struct sk_buff *skb; |
| 6839 | void *hdr; |
| 6840 | struct nlattr *data; |
| 6841 | |
| 6842 | skb = nlmsg_new(approxlen + 100, gfp); |
| 6843 | if (!skb) |
| 6844 | return NULL; |
| 6845 | |
| 6846 | hdr = nl80211hdr_put(skb, portid, seq, 0, cmd); |
| 6847 | if (!hdr) { |
| 6848 | kfree_skb(skb); |
| 6849 | return NULL; |
| 6850 | } |
| 6851 | |
| 6852 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 6853 | goto nla_put_failure; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 6854 | |
| 6855 | if (info) { |
| 6856 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID, |
| 6857 | info->vendor_id)) |
| 6858 | goto nla_put_failure; |
| 6859 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD, |
| 6860 | info->subcmd)) |
| 6861 | goto nla_put_failure; |
| 6862 | } |
| 6863 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 6864 | data = nla_nest_start(skb, attr); |
| 6865 | |
| 6866 | ((void **)skb->cb)[0] = rdev; |
| 6867 | ((void **)skb->cb)[1] = hdr; |
| 6868 | ((void **)skb->cb)[2] = data; |
| 6869 | |
| 6870 | return skb; |
| 6871 | |
| 6872 | nla_put_failure: |
| 6873 | kfree_skb(skb); |
| 6874 | return NULL; |
| 6875 | } |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 6876 | |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 6877 | struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy, |
| 6878 | enum nl80211_commands cmd, |
| 6879 | enum nl80211_attrs attr, |
| 6880 | int vendor_event_idx, |
| 6881 | int approxlen, gfp_t gfp) |
| 6882 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 6883 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 6884 | const struct nl80211_vendor_cmd_info *info; |
| 6885 | |
| 6886 | switch (cmd) { |
| 6887 | case NL80211_CMD_TESTMODE: |
| 6888 | if (WARN_ON(vendor_event_idx != -1)) |
| 6889 | return NULL; |
| 6890 | info = NULL; |
| 6891 | break; |
| 6892 | case NL80211_CMD_VENDOR: |
| 6893 | if (WARN_ON(vendor_event_idx < 0 || |
| 6894 | vendor_event_idx >= wiphy->n_vendor_events)) |
| 6895 | return NULL; |
| 6896 | info = &wiphy->vendor_events[vendor_event_idx]; |
| 6897 | break; |
| 6898 | default: |
| 6899 | WARN_ON(1); |
| 6900 | return NULL; |
| 6901 | } |
| 6902 | |
| 6903 | return __cfg80211_alloc_vendor_skb(rdev, approxlen, 0, 0, |
| 6904 | cmd, attr, info, gfp); |
| 6905 | } |
| 6906 | EXPORT_SYMBOL(__cfg80211_alloc_event_skb); |
| 6907 | |
| 6908 | void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp) |
| 6909 | { |
| 6910 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 6911 | void *hdr = ((void **)skb->cb)[1]; |
| 6912 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 6913 | enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE; |
| 6914 | |
| 6915 | nla_nest_end(skb, data); |
| 6916 | genlmsg_end(skb, hdr); |
| 6917 | |
| 6918 | if (data->nla_type == NL80211_ATTR_VENDOR_DATA) |
| 6919 | mcgrp = NL80211_MCGRP_VENDOR; |
| 6920 | |
| 6921 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0, |
| 6922 | mcgrp, gfp); |
| 6923 | } |
| 6924 | EXPORT_SYMBOL(__cfg80211_send_event_skb); |
| 6925 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6926 | #ifdef CONFIG_NL80211_TESTMODE |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6927 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
| 6928 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6929 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 6930 | struct wireless_dev *wdev = |
| 6931 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6932 | int err; |
| 6933 | |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 6934 | if (!rdev->ops->testmode_cmd) |
| 6935 | return -EOPNOTSUPP; |
| 6936 | |
| 6937 | if (IS_ERR(wdev)) { |
| 6938 | err = PTR_ERR(wdev); |
| 6939 | if (err != -EINVAL) |
| 6940 | return err; |
| 6941 | wdev = NULL; |
| 6942 | } else if (wdev->wiphy != &rdev->wiphy) { |
| 6943 | return -EINVAL; |
| 6944 | } |
| 6945 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6946 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
| 6947 | return -EINVAL; |
| 6948 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 6949 | rdev->cur_cmd_info = info; |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 6950 | err = rdev_testmode_cmd(rdev, wdev, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6951 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
| 6952 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 6953 | rdev->cur_cmd_info = NULL; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6954 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6955 | return err; |
| 6956 | } |
| 6957 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6958 | static int nl80211_testmode_dump(struct sk_buff *skb, |
| 6959 | struct netlink_callback *cb) |
| 6960 | { |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6961 | struct cfg80211_registered_device *rdev; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6962 | int err; |
| 6963 | long phy_idx; |
| 6964 | void *data = NULL; |
| 6965 | int data_len = 0; |
| 6966 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6967 | rtnl_lock(); |
| 6968 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6969 | if (cb->args[0]) { |
| 6970 | /* |
| 6971 | * 0 is a valid index, but not valid for args[0], |
| 6972 | * so we need to offset by 1. |
| 6973 | */ |
| 6974 | phy_idx = cb->args[0] - 1; |
| 6975 | } else { |
| 6976 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 6977 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 6978 | nl80211_policy); |
| 6979 | if (err) |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6980 | goto out_err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6981 | |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 6982 | rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), |
| 6983 | nl80211_fam.attrbuf); |
| 6984 | if (IS_ERR(rdev)) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6985 | err = PTR_ERR(rdev); |
| 6986 | goto out_err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6987 | } |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 6988 | phy_idx = rdev->wiphy_idx; |
| 6989 | rdev = NULL; |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 6990 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6991 | if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]) |
| 6992 | cb->args[1] = |
| 6993 | (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]; |
| 6994 | } |
| 6995 | |
| 6996 | if (cb->args[1]) { |
| 6997 | data = nla_data((void *)cb->args[1]); |
| 6998 | data_len = nla_len((void *)cb->args[1]); |
| 6999 | } |
| 7000 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 7001 | rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
| 7002 | if (!rdev) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 7003 | err = -ENOENT; |
| 7004 | goto out_err; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7005 | } |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7006 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 7007 | if (!rdev->ops->testmode_dump) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7008 | err = -EOPNOTSUPP; |
| 7009 | goto out_err; |
| 7010 | } |
| 7011 | |
| 7012 | while (1) { |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7013 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7014 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 7015 | NL80211_CMD_TESTMODE); |
| 7016 | struct nlattr *tmdata; |
| 7017 | |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 7018 | if (!hdr) |
| 7019 | break; |
| 7020 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7021 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7022 | genlmsg_cancel(skb, hdr); |
| 7023 | break; |
| 7024 | } |
| 7025 | |
| 7026 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 7027 | if (!tmdata) { |
| 7028 | genlmsg_cancel(skb, hdr); |
| 7029 | break; |
| 7030 | } |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7031 | err = rdev_testmode_dump(rdev, skb, cb, data, data_len); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7032 | nla_nest_end(skb, tmdata); |
| 7033 | |
| 7034 | if (err == -ENOBUFS || err == -ENOENT) { |
| 7035 | genlmsg_cancel(skb, hdr); |
| 7036 | break; |
| 7037 | } else if (err) { |
| 7038 | genlmsg_cancel(skb, hdr); |
| 7039 | goto out_err; |
| 7040 | } |
| 7041 | |
| 7042 | genlmsg_end(skb, hdr); |
| 7043 | } |
| 7044 | |
| 7045 | err = skb->len; |
| 7046 | /* see above */ |
| 7047 | cb->args[0] = phy_idx + 1; |
| 7048 | out_err: |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 7049 | rtnl_unlock(); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7050 | return err; |
| 7051 | } |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7052 | #endif |
| 7053 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7054 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
| 7055 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7056 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7057 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7058 | struct cfg80211_connect_params connect; |
| 7059 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7060 | struct cfg80211_cached_keys *connkeys = NULL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7061 | int err; |
| 7062 | |
| 7063 | memset(&connect, 0, sizeof(connect)); |
| 7064 | |
| 7065 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 7066 | return -EINVAL; |
| 7067 | |
| 7068 | if (!info->attrs[NL80211_ATTR_SSID] || |
| 7069 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 7070 | return -EINVAL; |
| 7071 | |
| 7072 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 7073 | connect.auth_type = |
| 7074 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 7075 | if (!nl80211_valid_auth_type(rdev, connect.auth_type, |
| 7076 | NL80211_CMD_CONNECT)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7077 | return -EINVAL; |
| 7078 | } else |
| 7079 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 7080 | |
| 7081 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; |
| 7082 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 7083 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 7084 | NL80211_MAX_NR_CIPHER_SUITES); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7085 | if (err) |
| 7086 | return err; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7087 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7088 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7089 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7090 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7091 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 7092 | wiphy = &rdev->wiphy; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7093 | |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 7094 | connect.bg_scan_period = -1; |
| 7095 | if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] && |
| 7096 | (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) { |
| 7097 | connect.bg_scan_period = |
| 7098 | nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]); |
| 7099 | } |
| 7100 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7101 | if (info->attrs[NL80211_ATTR_MAC]) |
| 7102 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 7103 | else if (info->attrs[NL80211_ATTR_MAC_HINT]) |
| 7104 | connect.bssid_hint = |
| 7105 | nla_data(info->attrs[NL80211_ATTR_MAC_HINT]); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7106 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 7107 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 7108 | |
| 7109 | if (info->attrs[NL80211_ATTR_IE]) { |
| 7110 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 7111 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 7112 | } |
| 7113 | |
Jouni Malinen | cee00a9 | 2013-01-15 17:15:57 +0200 | [diff] [blame] | 7114 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
| 7115 | connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
| 7116 | if (connect.mfp != NL80211_MFP_REQUIRED && |
| 7117 | connect.mfp != NL80211_MFP_NO) |
| 7118 | return -EINVAL; |
| 7119 | } else { |
| 7120 | connect.mfp = NL80211_MFP_NO; |
| 7121 | } |
| 7122 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7123 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 7124 | connect.channel = nl80211_get_valid_chan( |
| 7125 | wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 7126 | if (!connect.channel) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7127 | return -EINVAL; |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 7128 | } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) { |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 7129 | connect.channel_hint = nl80211_get_valid_chan( |
| 7130 | wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]); |
| 7131 | if (!connect.channel_hint) |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 7132 | return -EINVAL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7133 | } |
| 7134 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7135 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
| 7136 | connkeys = nl80211_parse_connkeys(rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 7137 | info->attrs[NL80211_ATTR_KEYS], NULL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7138 | if (IS_ERR(connkeys)) |
| 7139 | return PTR_ERR(connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7140 | } |
| 7141 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 7142 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
| 7143 | connect.flags |= ASSOC_REQ_DISABLE_HT; |
| 7144 | |
| 7145 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 7146 | memcpy(&connect.ht_capa_mask, |
| 7147 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 7148 | sizeof(connect.ht_capa_mask)); |
| 7149 | |
| 7150 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 7151 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) { |
| 7152 | kfree(connkeys); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 7153 | return -EINVAL; |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 7154 | } |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 7155 | memcpy(&connect.ht_capa, |
| 7156 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 7157 | sizeof(connect.ht_capa)); |
| 7158 | } |
| 7159 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 7160 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
| 7161 | connect.flags |= ASSOC_REQ_DISABLE_VHT; |
| 7162 | |
| 7163 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
| 7164 | memcpy(&connect.vht_capa_mask, |
| 7165 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), |
| 7166 | sizeof(connect.vht_capa_mask)); |
| 7167 | |
| 7168 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { |
| 7169 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) { |
| 7170 | kfree(connkeys); |
| 7171 | return -EINVAL; |
| 7172 | } |
| 7173 | memcpy(&connect.vht_capa, |
| 7174 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), |
| 7175 | sizeof(connect.vht_capa)); |
| 7176 | } |
| 7177 | |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7178 | wdev_lock(dev->ieee80211_ptr); |
| 7179 | err = cfg80211_connect(rdev, dev, &connect, connkeys, NULL); |
| 7180 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7181 | if (err) |
| 7182 | kfree(connkeys); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7183 | return err; |
| 7184 | } |
| 7185 | |
| 7186 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) |
| 7187 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7188 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7189 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7190 | u16 reason; |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7191 | int ret; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7192 | |
| 7193 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 7194 | reason = WLAN_REASON_DEAUTH_LEAVING; |
| 7195 | else |
| 7196 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 7197 | |
| 7198 | if (reason == 0) |
| 7199 | return -EINVAL; |
| 7200 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7201 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7202 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7203 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7204 | |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7205 | wdev_lock(dev->ieee80211_ptr); |
| 7206 | ret = cfg80211_disconnect(rdev, dev, reason, true); |
| 7207 | wdev_unlock(dev->ieee80211_ptr); |
| 7208 | return ret; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7209 | } |
| 7210 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7211 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
| 7212 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7213 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7214 | struct net *net; |
| 7215 | int err; |
| 7216 | u32 pid; |
| 7217 | |
| 7218 | if (!info->attrs[NL80211_ATTR_PID]) |
| 7219 | return -EINVAL; |
| 7220 | |
| 7221 | pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); |
| 7222 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7223 | net = get_net_ns_by_pid(pid); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7224 | if (IS_ERR(net)) |
| 7225 | return PTR_ERR(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7226 | |
| 7227 | err = 0; |
| 7228 | |
| 7229 | /* check if anything to do */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7230 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
| 7231 | err = cfg80211_switch_netns(rdev, net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7232 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7233 | put_net(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7234 | return err; |
| 7235 | } |
| 7236 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7237 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 7238 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7239 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7240 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
| 7241 | struct cfg80211_pmksa *pmksa) = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7242 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7243 | struct cfg80211_pmksa pmksa; |
| 7244 | |
| 7245 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); |
| 7246 | |
| 7247 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 7248 | return -EINVAL; |
| 7249 | |
| 7250 | if (!info->attrs[NL80211_ATTR_PMKID]) |
| 7251 | return -EINVAL; |
| 7252 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7253 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
| 7254 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 7255 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7256 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7257 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7258 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7259 | |
| 7260 | switch (info->genlhdr->cmd) { |
| 7261 | case NL80211_CMD_SET_PMKSA: |
| 7262 | rdev_ops = rdev->ops->set_pmksa; |
| 7263 | break; |
| 7264 | case NL80211_CMD_DEL_PMKSA: |
| 7265 | rdev_ops = rdev->ops->del_pmksa; |
| 7266 | break; |
| 7267 | default: |
| 7268 | WARN_ON(1); |
| 7269 | break; |
| 7270 | } |
| 7271 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7272 | if (!rdev_ops) |
| 7273 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7274 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7275 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7276 | } |
| 7277 | |
| 7278 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 7279 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7280 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7281 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7282 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7283 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7284 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7285 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7286 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7287 | if (!rdev->ops->flush_pmksa) |
| 7288 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7289 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7290 | return rdev_flush_pmksa(rdev, dev); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7291 | } |
| 7292 | |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7293 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) |
| 7294 | { |
| 7295 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7296 | struct net_device *dev = info->user_ptr[1]; |
| 7297 | u8 action_code, dialog_token; |
Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 7298 | u32 peer_capability = 0; |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7299 | u16 status_code; |
| 7300 | u8 *peer; |
| 7301 | |
| 7302 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 7303 | !rdev->ops->tdls_mgmt) |
| 7304 | return -EOPNOTSUPP; |
| 7305 | |
| 7306 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || |
| 7307 | !info->attrs[NL80211_ATTR_STATUS_CODE] || |
| 7308 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || |
| 7309 | !info->attrs[NL80211_ATTR_IE] || |
| 7310 | !info->attrs[NL80211_ATTR_MAC]) |
| 7311 | return -EINVAL; |
| 7312 | |
| 7313 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 7314 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); |
| 7315 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); |
| 7316 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); |
Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 7317 | if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]) |
| 7318 | peer_capability = |
| 7319 | nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7320 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7321 | return rdev_tdls_mgmt(rdev, dev, peer, action_code, |
Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 7322 | dialog_token, status_code, peer_capability, |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7323 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 7324 | nla_len(info->attrs[NL80211_ATTR_IE])); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7325 | } |
| 7326 | |
| 7327 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) |
| 7328 | { |
| 7329 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7330 | struct net_device *dev = info->user_ptr[1]; |
| 7331 | enum nl80211_tdls_operation operation; |
| 7332 | u8 *peer; |
| 7333 | |
| 7334 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 7335 | !rdev->ops->tdls_oper) |
| 7336 | return -EOPNOTSUPP; |
| 7337 | |
| 7338 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || |
| 7339 | !info->attrs[NL80211_ATTR_MAC]) |
| 7340 | return -EINVAL; |
| 7341 | |
| 7342 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); |
| 7343 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 7344 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7345 | return rdev_tdls_oper(rdev, dev, peer, operation); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7346 | } |
| 7347 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7348 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
| 7349 | struct genl_info *info) |
| 7350 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7351 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7352 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7353 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7354 | struct sk_buff *msg; |
| 7355 | void *hdr; |
| 7356 | u64 cookie; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7357 | u32 duration; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7358 | int err; |
| 7359 | |
| 7360 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 7361 | !info->attrs[NL80211_ATTR_DURATION]) |
| 7362 | return -EINVAL; |
| 7363 | |
| 7364 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
| 7365 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 7366 | if (!rdev->ops->remain_on_channel || |
| 7367 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7368 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7369 | |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 7370 | /* |
| 7371 | * We should be on that channel for at least a minimum amount of |
| 7372 | * time (10ms) but no longer than the driver supports. |
| 7373 | */ |
| 7374 | if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 7375 | duration > rdev->wiphy.max_remain_on_channel_duration) |
| 7376 | return -EINVAL; |
| 7377 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7378 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 7379 | if (err) |
| 7380 | return err; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7381 | |
| 7382 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7383 | if (!msg) |
| 7384 | return -ENOMEM; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7385 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7386 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7387 | NL80211_CMD_REMAIN_ON_CHANNEL); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 7388 | if (!hdr) { |
| 7389 | err = -ENOBUFS; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7390 | goto free_msg; |
| 7391 | } |
| 7392 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7393 | err = rdev_remain_on_channel(rdev, wdev, chandef.chan, |
| 7394 | duration, &cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7395 | |
| 7396 | if (err) |
| 7397 | goto free_msg; |
| 7398 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7399 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 7400 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7401 | |
| 7402 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7403 | |
| 7404 | return genlmsg_reply(msg, info); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7405 | |
| 7406 | nla_put_failure: |
| 7407 | err = -ENOBUFS; |
| 7408 | free_msg: |
| 7409 | nlmsg_free(msg); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7410 | return err; |
| 7411 | } |
| 7412 | |
| 7413 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, |
| 7414 | struct genl_info *info) |
| 7415 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7416 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7417 | struct wireless_dev *wdev = info->user_ptr[1]; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7418 | u64 cookie; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7419 | |
| 7420 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 7421 | return -EINVAL; |
| 7422 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7423 | if (!rdev->ops->cancel_remain_on_channel) |
| 7424 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7425 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7426 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 7427 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7428 | return rdev_cancel_remain_on_channel(rdev, wdev, cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7429 | } |
| 7430 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7431 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
| 7432 | u8 *rates, u8 rates_len) |
| 7433 | { |
| 7434 | u8 i; |
| 7435 | u32 mask = 0; |
| 7436 | |
| 7437 | for (i = 0; i < rates_len; i++) { |
| 7438 | int rate = (rates[i] & 0x7f) * 5; |
| 7439 | int ridx; |
| 7440 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { |
| 7441 | struct ieee80211_rate *srate = |
| 7442 | &sband->bitrates[ridx]; |
| 7443 | if (rate == srate->bitrate) { |
| 7444 | mask |= 1 << ridx; |
| 7445 | break; |
| 7446 | } |
| 7447 | } |
| 7448 | if (ridx == sband->n_bitrates) |
| 7449 | return 0; /* rate not found */ |
| 7450 | } |
| 7451 | |
| 7452 | return mask; |
| 7453 | } |
| 7454 | |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7455 | static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, |
| 7456 | u8 *rates, u8 rates_len, |
| 7457 | u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) |
| 7458 | { |
| 7459 | u8 i; |
| 7460 | |
| 7461 | memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); |
| 7462 | |
| 7463 | for (i = 0; i < rates_len; i++) { |
| 7464 | int ridx, rbit; |
| 7465 | |
| 7466 | ridx = rates[i] / 8; |
| 7467 | rbit = BIT(rates[i] % 8); |
| 7468 | |
| 7469 | /* check validity */ |
Dan Carpenter | 910570b5 | 2012-02-01 10:42:11 +0300 | [diff] [blame] | 7470 | if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7471 | return false; |
| 7472 | |
| 7473 | /* check availability */ |
| 7474 | if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) |
| 7475 | mcs[ridx] |= rbit; |
| 7476 | else |
| 7477 | return false; |
| 7478 | } |
| 7479 | |
| 7480 | return true; |
| 7481 | } |
| 7482 | |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 7483 | static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map) |
| 7484 | { |
| 7485 | u16 mcs_mask = 0; |
| 7486 | |
| 7487 | switch (vht_mcs_map) { |
| 7488 | case IEEE80211_VHT_MCS_NOT_SUPPORTED: |
| 7489 | break; |
| 7490 | case IEEE80211_VHT_MCS_SUPPORT_0_7: |
| 7491 | mcs_mask = 0x00FF; |
| 7492 | break; |
| 7493 | case IEEE80211_VHT_MCS_SUPPORT_0_8: |
| 7494 | mcs_mask = 0x01FF; |
| 7495 | break; |
| 7496 | case IEEE80211_VHT_MCS_SUPPORT_0_9: |
| 7497 | mcs_mask = 0x03FF; |
| 7498 | break; |
| 7499 | default: |
| 7500 | break; |
| 7501 | } |
| 7502 | |
| 7503 | return mcs_mask; |
| 7504 | } |
| 7505 | |
| 7506 | static void vht_build_mcs_mask(u16 vht_mcs_map, |
| 7507 | u16 vht_mcs_mask[NL80211_VHT_NSS_MAX]) |
| 7508 | { |
| 7509 | u8 nss; |
| 7510 | |
| 7511 | for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) { |
| 7512 | vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03); |
| 7513 | vht_mcs_map >>= 2; |
| 7514 | } |
| 7515 | } |
| 7516 | |
| 7517 | static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband, |
| 7518 | struct nl80211_txrate_vht *txrate, |
| 7519 | u16 mcs[NL80211_VHT_NSS_MAX]) |
| 7520 | { |
| 7521 | u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); |
| 7522 | u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {}; |
| 7523 | u8 i; |
| 7524 | |
| 7525 | if (!sband->vht_cap.vht_supported) |
| 7526 | return false; |
| 7527 | |
| 7528 | memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX); |
| 7529 | |
| 7530 | /* Build vht_mcs_mask from VHT capabilities */ |
| 7531 | vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask); |
| 7532 | |
| 7533 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) { |
| 7534 | if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i]) |
| 7535 | mcs[i] = txrate->mcs[i]; |
| 7536 | else |
| 7537 | return false; |
| 7538 | } |
| 7539 | |
| 7540 | return true; |
| 7541 | } |
| 7542 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 7543 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7544 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
| 7545 | .len = NL80211_MAX_SUPP_RATES }, |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 7546 | [NL80211_TXRATE_HT] = { .type = NLA_BINARY, |
| 7547 | .len = NL80211_MAX_SUPP_HT_RATES }, |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 7548 | [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)}, |
Janusz Dziedzic | 0b9323f | 2014-01-08 08:46:02 +0100 | [diff] [blame] | 7549 | [NL80211_TXRATE_GI] = { .type = NLA_U8 }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7550 | }; |
| 7551 | |
| 7552 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, |
| 7553 | struct genl_info *info) |
| 7554 | { |
| 7555 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7556 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7557 | struct cfg80211_bitrate_mask mask; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7558 | int rem, i; |
| 7559 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7560 | struct nlattr *tx_rates; |
| 7561 | struct ieee80211_supported_band *sband; |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 7562 | u16 vht_tx_mcs_map; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7563 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7564 | if (!rdev->ops->set_bitrate_mask) |
| 7565 | return -EOPNOTSUPP; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7566 | |
| 7567 | memset(&mask, 0, sizeof(mask)); |
| 7568 | /* Default to all rates enabled */ |
| 7569 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) { |
| 7570 | sband = rdev->wiphy.bands[i]; |
Janusz Dziedzic | 7869303 | 2013-12-03 09:50:44 +0100 | [diff] [blame] | 7571 | |
| 7572 | if (!sband) |
| 7573 | continue; |
| 7574 | |
| 7575 | mask.control[i].legacy = (1 << sband->n_bitrates) - 1; |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 7576 | memcpy(mask.control[i].ht_mcs, |
Janusz Dziedzic | 7869303 | 2013-12-03 09:50:44 +0100 | [diff] [blame] | 7577 | sband->ht_cap.mcs.rx_mask, |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 7578 | sizeof(mask.control[i].ht_mcs)); |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 7579 | |
| 7580 | if (!sband->vht_cap.vht_supported) |
| 7581 | continue; |
| 7582 | |
| 7583 | vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); |
| 7584 | 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] | 7585 | } |
| 7586 | |
Janusz Dziedzic | b9243ab | 2013-12-05 10:02:14 +0100 | [diff] [blame] | 7587 | /* if no rates are given set it back to the defaults */ |
| 7588 | if (!info->attrs[NL80211_ATTR_TX_RATES]) |
| 7589 | goto out; |
| 7590 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7591 | /* |
| 7592 | * The nested attribute uses enum nl80211_band as the index. This maps |
| 7593 | * directly to the enum ieee80211_band values used in cfg80211. |
| 7594 | */ |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7595 | 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] | 7596 | 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] | 7597 | enum ieee80211_band band = nla_type(tx_rates); |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 7598 | int err; |
| 7599 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7600 | if (band < 0 || band >= IEEE80211_NUM_BANDS) |
| 7601 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7602 | sband = rdev->wiphy.bands[band]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7603 | if (sband == NULL) |
| 7604 | return -EINVAL; |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 7605 | err = nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), |
| 7606 | nla_len(tx_rates), nl80211_txattr_policy); |
| 7607 | if (err) |
| 7608 | return err; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7609 | if (tb[NL80211_TXRATE_LEGACY]) { |
| 7610 | mask.control[band].legacy = rateset_to_mask( |
| 7611 | sband, |
| 7612 | nla_data(tb[NL80211_TXRATE_LEGACY]), |
| 7613 | nla_len(tb[NL80211_TXRATE_LEGACY])); |
Bala Shanmugam | 218d2e2 | 2012-04-20 19:12:58 +0530 | [diff] [blame] | 7614 | if ((mask.control[band].legacy == 0) && |
| 7615 | nla_len(tb[NL80211_TXRATE_LEGACY])) |
| 7616 | return -EINVAL; |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7617 | } |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 7618 | if (tb[NL80211_TXRATE_HT]) { |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7619 | if (!ht_rateset_to_mask( |
| 7620 | sband, |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 7621 | nla_data(tb[NL80211_TXRATE_HT]), |
| 7622 | nla_len(tb[NL80211_TXRATE_HT]), |
| 7623 | mask.control[band].ht_mcs)) |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7624 | return -EINVAL; |
| 7625 | } |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 7626 | if (tb[NL80211_TXRATE_VHT]) { |
| 7627 | if (!vht_set_mcs_mask( |
| 7628 | sband, |
| 7629 | nla_data(tb[NL80211_TXRATE_VHT]), |
| 7630 | mask.control[band].vht_mcs)) |
| 7631 | return -EINVAL; |
| 7632 | } |
Janusz Dziedzic | 0b9323f | 2014-01-08 08:46:02 +0100 | [diff] [blame] | 7633 | if (tb[NL80211_TXRATE_GI]) { |
| 7634 | mask.control[band].gi = |
| 7635 | nla_get_u8(tb[NL80211_TXRATE_GI]); |
| 7636 | if (mask.control[band].gi > NL80211_TXRATE_FORCE_LGI) |
| 7637 | return -EINVAL; |
| 7638 | } |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7639 | |
| 7640 | if (mask.control[band].legacy == 0) { |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 7641 | /* don't allow empty legacy rates if HT or VHT |
| 7642 | * are not even supported. |
| 7643 | */ |
| 7644 | if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported || |
| 7645 | rdev->wiphy.bands[band]->vht_cap.vht_supported)) |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7646 | return -EINVAL; |
| 7647 | |
| 7648 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 7649 | if (mask.control[band].ht_mcs[i]) |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 7650 | goto out; |
| 7651 | |
| 7652 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) |
| 7653 | if (mask.control[band].vht_mcs[i]) |
| 7654 | goto out; |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7655 | |
| 7656 | /* legacy and mcs rates may not be both empty */ |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 7657 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7658 | } |
| 7659 | } |
| 7660 | |
Janusz Dziedzic | b9243ab | 2013-12-05 10:02:14 +0100 | [diff] [blame] | 7661 | out: |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7662 | return rdev_set_bitrate_mask(rdev, dev, NULL, &mask); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7663 | } |
| 7664 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7665 | 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] | 7666 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7667 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7668 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7669 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7670 | |
| 7671 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) |
| 7672 | return -EINVAL; |
| 7673 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7674 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
| 7675 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7676 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7677 | switch (wdev->iftype) { |
| 7678 | case NL80211_IFTYPE_STATION: |
| 7679 | case NL80211_IFTYPE_ADHOC: |
| 7680 | case NL80211_IFTYPE_P2P_CLIENT: |
| 7681 | case NL80211_IFTYPE_AP: |
| 7682 | case NL80211_IFTYPE_AP_VLAN: |
| 7683 | case NL80211_IFTYPE_MESH_POINT: |
| 7684 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7685 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7686 | break; |
| 7687 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7688 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7689 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7690 | |
| 7691 | /* not much point in registering if we can't reply */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7692 | if (!rdev->ops->mgmt_tx) |
| 7693 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7694 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7695 | return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7696 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
| 7697 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7698 | } |
| 7699 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7700 | 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] | 7701 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7702 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7703 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7704 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7705 | int err; |
Johannes Berg | d64d373 | 2011-11-10 09:44:46 +0100 | [diff] [blame] | 7706 | void *hdr = NULL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7707 | u64 cookie; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7708 | struct sk_buff *msg = NULL; |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7709 | struct cfg80211_mgmt_tx_params params = { |
| 7710 | .dont_wait_for_ack = |
| 7711 | info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK], |
| 7712 | }; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7713 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7714 | if (!info->attrs[NL80211_ATTR_FRAME]) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7715 | return -EINVAL; |
| 7716 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7717 | if (!rdev->ops->mgmt_tx) |
| 7718 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7719 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7720 | switch (wdev->iftype) { |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 7721 | case NL80211_IFTYPE_P2P_DEVICE: |
| 7722 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 7723 | return -EINVAL; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7724 | case NL80211_IFTYPE_STATION: |
| 7725 | case NL80211_IFTYPE_ADHOC: |
| 7726 | case NL80211_IFTYPE_P2P_CLIENT: |
| 7727 | case NL80211_IFTYPE_AP: |
| 7728 | case NL80211_IFTYPE_AP_VLAN: |
| 7729 | case NL80211_IFTYPE_MESH_POINT: |
| 7730 | case NL80211_IFTYPE_P2P_GO: |
| 7731 | break; |
| 7732 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7733 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7734 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7735 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7736 | if (info->attrs[NL80211_ATTR_DURATION]) { |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 7737 | if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7738 | return -EINVAL; |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7739 | params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 7740 | |
| 7741 | /* |
| 7742 | * We should wait on the channel for at least a minimum amount |
| 7743 | * of time (10ms) but no longer than the driver supports. |
| 7744 | */ |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7745 | if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 7746 | params.wait > rdev->wiphy.max_remain_on_channel_duration) |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 7747 | return -EINVAL; |
| 7748 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7749 | } |
| 7750 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7751 | params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7752 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7753 | if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 7754 | return -EINVAL; |
| 7755 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7756 | 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] | 7757 | |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 7758 | /* get the channel if any has been specified, otherwise pass NULL to |
| 7759 | * the driver. The latter will use the current one |
| 7760 | */ |
| 7761 | chandef.chan = NULL; |
| 7762 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 7763 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 7764 | if (err) |
| 7765 | return err; |
| 7766 | } |
| 7767 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7768 | if (!chandef.chan && params.offchan) |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 7769 | return -EINVAL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7770 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7771 | if (!params.dont_wait_for_ack) { |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7772 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 7773 | if (!msg) |
| 7774 | return -ENOMEM; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7775 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7776 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7777 | NL80211_CMD_FRAME); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 7778 | if (!hdr) { |
| 7779 | err = -ENOBUFS; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7780 | goto free_msg; |
| 7781 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7782 | } |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7783 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7784 | params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]); |
| 7785 | params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]); |
| 7786 | params.chan = chandef.chan; |
| 7787 | err = cfg80211_mlme_mgmt_tx(rdev, wdev, ¶ms, &cookie); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7788 | if (err) |
| 7789 | goto free_msg; |
| 7790 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7791 | if (msg) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7792 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 7793 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7794 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7795 | genlmsg_end(msg, hdr); |
| 7796 | return genlmsg_reply(msg, info); |
| 7797 | } |
| 7798 | |
| 7799 | return 0; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7800 | |
| 7801 | nla_put_failure: |
| 7802 | err = -ENOBUFS; |
| 7803 | free_msg: |
| 7804 | nlmsg_free(msg); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7805 | return err; |
| 7806 | } |
| 7807 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7808 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
| 7809 | { |
| 7810 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7811 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7812 | u64 cookie; |
| 7813 | |
| 7814 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 7815 | return -EINVAL; |
| 7816 | |
| 7817 | if (!rdev->ops->mgmt_tx_cancel_wait) |
| 7818 | return -EOPNOTSUPP; |
| 7819 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7820 | switch (wdev->iftype) { |
| 7821 | case NL80211_IFTYPE_STATION: |
| 7822 | case NL80211_IFTYPE_ADHOC: |
| 7823 | case NL80211_IFTYPE_P2P_CLIENT: |
| 7824 | case NL80211_IFTYPE_AP: |
| 7825 | case NL80211_IFTYPE_AP_VLAN: |
| 7826 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7827 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7828 | break; |
| 7829 | default: |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7830 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7831 | } |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7832 | |
| 7833 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 7834 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7835 | return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie); |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7836 | } |
| 7837 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7838 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
| 7839 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7840 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7841 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7842 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7843 | u8 ps_state; |
| 7844 | bool state; |
| 7845 | int err; |
| 7846 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7847 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
| 7848 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7849 | |
| 7850 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); |
| 7851 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7852 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
| 7853 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7854 | |
| 7855 | wdev = dev->ieee80211_ptr; |
| 7856 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7857 | if (!rdev->ops->set_power_mgmt) |
| 7858 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7859 | |
| 7860 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; |
| 7861 | |
| 7862 | if (state == wdev->ps) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7863 | return 0; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7864 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7865 | err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7866 | if (!err) |
| 7867 | wdev->ps = state; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7868 | return err; |
| 7869 | } |
| 7870 | |
| 7871 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) |
| 7872 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7873 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7874 | enum nl80211_ps_state ps_state; |
| 7875 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7876 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7877 | struct sk_buff *msg; |
| 7878 | void *hdr; |
| 7879 | int err; |
| 7880 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7881 | wdev = dev->ieee80211_ptr; |
| 7882 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7883 | if (!rdev->ops->set_power_mgmt) |
| 7884 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7885 | |
| 7886 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7887 | if (!msg) |
| 7888 | return -ENOMEM; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7889 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7890 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7891 | NL80211_CMD_GET_POWER_SAVE); |
| 7892 | if (!hdr) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7893 | err = -ENOBUFS; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7894 | goto free_msg; |
| 7895 | } |
| 7896 | |
| 7897 | if (wdev->ps) |
| 7898 | ps_state = NL80211_PS_ENABLED; |
| 7899 | else |
| 7900 | ps_state = NL80211_PS_DISABLED; |
| 7901 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7902 | if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) |
| 7903 | goto nla_put_failure; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7904 | |
| 7905 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7906 | return genlmsg_reply(msg, info); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7907 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7908 | nla_put_failure: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7909 | err = -ENOBUFS; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7910 | free_msg: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7911 | nlmsg_free(msg); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7912 | return err; |
| 7913 | } |
| 7914 | |
Johannes Berg | 94e860f | 2014-01-20 23:58:15 +0100 | [diff] [blame] | 7915 | static const struct nla_policy |
| 7916 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = { |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7917 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, |
| 7918 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, |
| 7919 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7920 | [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 }, |
| 7921 | [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 }, |
| 7922 | [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7923 | }; |
| 7924 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7925 | static int nl80211_set_cqm_txe(struct genl_info *info, |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 7926 | u32 rate, u32 pkts, u32 intvl) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7927 | { |
| 7928 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7929 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 7930 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7931 | |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 7932 | if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7933 | return -EINVAL; |
| 7934 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7935 | if (!rdev->ops->set_cqm_txe_config) |
| 7936 | return -EOPNOTSUPP; |
| 7937 | |
| 7938 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
| 7939 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7940 | return -EOPNOTSUPP; |
| 7941 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7942 | return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7943 | } |
| 7944 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7945 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
| 7946 | s32 threshold, u32 hysteresis) |
| 7947 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7948 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7949 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 7950 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7951 | |
| 7952 | if (threshold > 0) |
| 7953 | return -EINVAL; |
| 7954 | |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 7955 | /* disabling - hysteresis should also be zero then */ |
| 7956 | if (threshold == 0) |
| 7957 | hysteresis = 0; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7958 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7959 | if (!rdev->ops->set_cqm_rssi_config) |
| 7960 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7961 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7962 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7963 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7964 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7965 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7966 | return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7967 | } |
| 7968 | |
| 7969 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) |
| 7970 | { |
| 7971 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; |
| 7972 | struct nlattr *cqm; |
| 7973 | int err; |
| 7974 | |
| 7975 | cqm = info->attrs[NL80211_ATTR_CQM]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 7976 | if (!cqm) |
| 7977 | return -EINVAL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7978 | |
| 7979 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, |
| 7980 | nl80211_attr_cqm_policy); |
| 7981 | if (err) |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 7982 | return err; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7983 | |
| 7984 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && |
| 7985 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 7986 | s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
| 7987 | u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7988 | |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 7989 | return nl80211_set_cqm_rssi(info, threshold, hysteresis); |
| 7990 | } |
| 7991 | |
| 7992 | if (attrs[NL80211_ATTR_CQM_TXE_RATE] && |
| 7993 | attrs[NL80211_ATTR_CQM_TXE_PKTS] && |
| 7994 | attrs[NL80211_ATTR_CQM_TXE_INTVL]) { |
| 7995 | u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]); |
| 7996 | u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]); |
| 7997 | u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]); |
| 7998 | |
| 7999 | return nl80211_set_cqm_txe(info, rate, pkts, intvl); |
| 8000 | } |
| 8001 | |
| 8002 | return -EINVAL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8003 | } |
| 8004 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8005 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
| 8006 | { |
| 8007 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8008 | struct net_device *dev = info->user_ptr[1]; |
| 8009 | struct mesh_config cfg; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 8010 | struct mesh_setup setup; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8011 | int err; |
| 8012 | |
| 8013 | /* start with default */ |
| 8014 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 8015 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8016 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 8017 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8018 | /* and parse parameters if given */ |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 8019 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8020 | if (err) |
| 8021 | return err; |
| 8022 | } |
| 8023 | |
| 8024 | if (!info->attrs[NL80211_ATTR_MESH_ID] || |
| 8025 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) |
| 8026 | return -EINVAL; |
| 8027 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 8028 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
| 8029 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 8030 | |
Chun-Yeow Yeoh | 4bb6234 | 2011-11-24 17:15:20 -0800 | [diff] [blame] | 8031 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 8032 | !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, |
| 8033 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 8034 | return -EINVAL; |
| 8035 | |
Marco Porsch | 9bdbf04 | 2013-01-07 16:04:51 +0100 | [diff] [blame] | 8036 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 8037 | setup.beacon_interval = |
| 8038 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 8039 | if (setup.beacon_interval < 10 || |
| 8040 | setup.beacon_interval > 10000) |
| 8041 | return -EINVAL; |
| 8042 | } |
| 8043 | |
| 8044 | if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) { |
| 8045 | setup.dtim_period = |
| 8046 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 8047 | if (setup.dtim_period < 1 || setup.dtim_period > 100) |
| 8048 | return -EINVAL; |
| 8049 | } |
| 8050 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 8051 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
| 8052 | /* parse additional setup parameters if given */ |
| 8053 | err = nl80211_parse_mesh_setup(info, &setup); |
| 8054 | if (err) |
| 8055 | return err; |
| 8056 | } |
| 8057 | |
Thomas Pedersen | d37bb18 | 2013-03-04 13:06:13 -0800 | [diff] [blame] | 8058 | if (setup.user_mpm) |
| 8059 | cfg.auto_open_plinks = false; |
| 8060 | |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 8061 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 8062 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
| 8063 | if (err) |
| 8064 | return err; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 8065 | } else { |
| 8066 | /* cfg80211_join_mesh() will sort it out */ |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 8067 | setup.chandef.chan = NULL; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 8068 | } |
| 8069 | |
Ashok Nagarajan | ffb3cf3 | 2013-06-03 10:33:36 -0700 | [diff] [blame] | 8070 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 8071 | u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 8072 | int n_rates = |
| 8073 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 8074 | struct ieee80211_supported_band *sband; |
| 8075 | |
| 8076 | if (!setup.chandef.chan) |
| 8077 | return -EINVAL; |
| 8078 | |
| 8079 | sband = rdev->wiphy.bands[setup.chandef.chan->band]; |
| 8080 | |
| 8081 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 8082 | &setup.basic_rates); |
| 8083 | if (err) |
| 8084 | return err; |
| 8085 | } |
| 8086 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 8087 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8088 | } |
| 8089 | |
| 8090 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) |
| 8091 | { |
| 8092 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8093 | struct net_device *dev = info->user_ptr[1]; |
| 8094 | |
| 8095 | return cfg80211_leave_mesh(rdev, dev); |
| 8096 | } |
| 8097 | |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 8098 | #ifdef CONFIG_PM |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8099 | static int nl80211_send_wowlan_patterns(struct sk_buff *msg, |
| 8100 | struct cfg80211_registered_device *rdev) |
| 8101 | { |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8102 | struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config; |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8103 | struct nlattr *nl_pats, *nl_pat; |
| 8104 | int i, pat_len; |
| 8105 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8106 | if (!wowlan->n_patterns) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8107 | return 0; |
| 8108 | |
| 8109 | nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN); |
| 8110 | if (!nl_pats) |
| 8111 | return -ENOBUFS; |
| 8112 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8113 | for (i = 0; i < wowlan->n_patterns; i++) { |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8114 | nl_pat = nla_nest_start(msg, i + 1); |
| 8115 | if (!nl_pat) |
| 8116 | return -ENOBUFS; |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8117 | pat_len = wowlan->patterns[i].pattern_len; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8118 | 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] | 8119 | wowlan->patterns[i].mask) || |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8120 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
| 8121 | wowlan->patterns[i].pattern) || |
| 8122 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8123 | wowlan->patterns[i].pkt_offset)) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8124 | return -ENOBUFS; |
| 8125 | nla_nest_end(msg, nl_pat); |
| 8126 | } |
| 8127 | nla_nest_end(msg, nl_pats); |
| 8128 | |
| 8129 | return 0; |
| 8130 | } |
| 8131 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8132 | static int nl80211_send_wowlan_tcp(struct sk_buff *msg, |
| 8133 | struct cfg80211_wowlan_tcp *tcp) |
| 8134 | { |
| 8135 | struct nlattr *nl_tcp; |
| 8136 | |
| 8137 | if (!tcp) |
| 8138 | return 0; |
| 8139 | |
| 8140 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); |
| 8141 | if (!nl_tcp) |
| 8142 | return -ENOBUFS; |
| 8143 | |
| 8144 | if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) || |
| 8145 | nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) || |
| 8146 | nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) || |
| 8147 | nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) || |
| 8148 | nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) || |
| 8149 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 8150 | tcp->payload_len, tcp->payload) || |
| 8151 | nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, |
| 8152 | tcp->data_interval) || |
| 8153 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, |
| 8154 | tcp->wake_len, tcp->wake_data) || |
| 8155 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK, |
| 8156 | DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask)) |
| 8157 | return -ENOBUFS; |
| 8158 | |
| 8159 | if (tcp->payload_seq.len && |
| 8160 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ, |
| 8161 | sizeof(tcp->payload_seq), &tcp->payload_seq)) |
| 8162 | return -ENOBUFS; |
| 8163 | |
| 8164 | if (tcp->payload_tok.len && |
| 8165 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, |
| 8166 | sizeof(tcp->payload_tok) + tcp->tokens_size, |
| 8167 | &tcp->payload_tok)) |
| 8168 | return -ENOBUFS; |
| 8169 | |
Johannes Berg | e248ad3 | 2013-05-16 10:24:28 +0200 | [diff] [blame] | 8170 | nla_nest_end(msg, nl_tcp); |
| 8171 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8172 | return 0; |
| 8173 | } |
| 8174 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8175 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 8176 | { |
| 8177 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8178 | struct sk_buff *msg; |
| 8179 | void *hdr; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8180 | u32 size = NLMSG_DEFAULT_SIZE; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8181 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8182 | if (!rdev->wiphy.wowlan) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8183 | return -EOPNOTSUPP; |
| 8184 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8185 | if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) { |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8186 | /* adjust size to have room for all the data */ |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8187 | size += rdev->wiphy.wowlan_config->tcp->tokens_size + |
| 8188 | rdev->wiphy.wowlan_config->tcp->payload_len + |
| 8189 | rdev->wiphy.wowlan_config->tcp->wake_len + |
| 8190 | rdev->wiphy.wowlan_config->tcp->wake_len / 8; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8191 | } |
| 8192 | |
| 8193 | msg = nlmsg_new(size, GFP_KERNEL); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8194 | if (!msg) |
| 8195 | return -ENOMEM; |
| 8196 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8197 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8198 | NL80211_CMD_GET_WOWLAN); |
| 8199 | if (!hdr) |
| 8200 | goto nla_put_failure; |
| 8201 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8202 | if (rdev->wiphy.wowlan_config) { |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8203 | struct nlattr *nl_wowlan; |
| 8204 | |
| 8205 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
| 8206 | if (!nl_wowlan) |
| 8207 | goto nla_put_failure; |
| 8208 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8209 | if ((rdev->wiphy.wowlan_config->any && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8210 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8211 | (rdev->wiphy.wowlan_config->disconnect && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8212 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8213 | (rdev->wiphy.wowlan_config->magic_pkt && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8214 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8215 | (rdev->wiphy.wowlan_config->gtk_rekey_failure && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8216 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8217 | (rdev->wiphy.wowlan_config->eap_identity_req && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8218 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8219 | (rdev->wiphy.wowlan_config->four_way_handshake && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8220 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8221 | (rdev->wiphy.wowlan_config->rfkill_release && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8222 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 8223 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8224 | |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8225 | if (nl80211_send_wowlan_patterns(msg, rdev)) |
| 8226 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8227 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8228 | if (nl80211_send_wowlan_tcp(msg, |
| 8229 | rdev->wiphy.wowlan_config->tcp)) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8230 | goto nla_put_failure; |
| 8231 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8232 | nla_nest_end(msg, nl_wowlan); |
| 8233 | } |
| 8234 | |
| 8235 | genlmsg_end(msg, hdr); |
| 8236 | return genlmsg_reply(msg, info); |
| 8237 | |
| 8238 | nla_put_failure: |
| 8239 | nlmsg_free(msg); |
| 8240 | return -ENOBUFS; |
| 8241 | } |
| 8242 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8243 | static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev, |
| 8244 | struct nlattr *attr, |
| 8245 | struct cfg80211_wowlan *trig) |
| 8246 | { |
| 8247 | struct nlattr *tb[NUM_NL80211_WOWLAN_TCP]; |
| 8248 | struct cfg80211_wowlan_tcp *cfg; |
| 8249 | struct nl80211_wowlan_tcp_data_token *tok = NULL; |
| 8250 | struct nl80211_wowlan_tcp_data_seq *seq = NULL; |
| 8251 | u32 size; |
| 8252 | u32 data_size, wake_size, tokens_size = 0, wake_mask_size; |
| 8253 | int err, port; |
| 8254 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8255 | if (!rdev->wiphy.wowlan->tcp) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8256 | return -EINVAL; |
| 8257 | |
| 8258 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP, |
| 8259 | nla_data(attr), nla_len(attr), |
| 8260 | nl80211_wowlan_tcp_policy); |
| 8261 | if (err) |
| 8262 | return err; |
| 8263 | |
| 8264 | if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] || |
| 8265 | !tb[NL80211_WOWLAN_TCP_DST_IPV4] || |
| 8266 | !tb[NL80211_WOWLAN_TCP_DST_MAC] || |
| 8267 | !tb[NL80211_WOWLAN_TCP_DST_PORT] || |
| 8268 | !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] || |
| 8269 | !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] || |
| 8270 | !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] || |
| 8271 | !tb[NL80211_WOWLAN_TCP_WAKE_MASK]) |
| 8272 | return -EINVAL; |
| 8273 | |
| 8274 | data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8275 | if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8276 | return -EINVAL; |
| 8277 | |
| 8278 | if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) > |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8279 | rdev->wiphy.wowlan->tcp->data_interval_max || |
Johannes Berg | 723d568 | 2013-02-26 13:56:40 +0100 | [diff] [blame] | 8280 | nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8281 | return -EINVAL; |
| 8282 | |
| 8283 | wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8284 | if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8285 | return -EINVAL; |
| 8286 | |
| 8287 | wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]); |
| 8288 | if (wake_mask_size != DIV_ROUND_UP(wake_size, 8)) |
| 8289 | return -EINVAL; |
| 8290 | |
| 8291 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) { |
| 8292 | u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 8293 | |
| 8294 | tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 8295 | tokens_size = tokln - sizeof(*tok); |
| 8296 | |
| 8297 | if (!tok->len || tokens_size % tok->len) |
| 8298 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8299 | if (!rdev->wiphy.wowlan->tcp->tok) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8300 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8301 | if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8302 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8303 | if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8304 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8305 | if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8306 | return -EINVAL; |
| 8307 | if (tok->offset + tok->len > data_size) |
| 8308 | return -EINVAL; |
| 8309 | } |
| 8310 | |
| 8311 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) { |
| 8312 | seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8313 | if (!rdev->wiphy.wowlan->tcp->seq) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8314 | return -EINVAL; |
| 8315 | if (seq->len == 0 || seq->len > 4) |
| 8316 | return -EINVAL; |
| 8317 | if (seq->len + seq->offset > data_size) |
| 8318 | return -EINVAL; |
| 8319 | } |
| 8320 | |
| 8321 | size = sizeof(*cfg); |
| 8322 | size += data_size; |
| 8323 | size += wake_size + wake_mask_size; |
| 8324 | size += tokens_size; |
| 8325 | |
| 8326 | cfg = kzalloc(size, GFP_KERNEL); |
| 8327 | if (!cfg) |
| 8328 | return -ENOMEM; |
| 8329 | cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]); |
| 8330 | cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]); |
| 8331 | memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]), |
| 8332 | ETH_ALEN); |
| 8333 | if (tb[NL80211_WOWLAN_TCP_SRC_PORT]) |
| 8334 | port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]); |
| 8335 | else |
| 8336 | port = 0; |
| 8337 | #ifdef CONFIG_INET |
| 8338 | /* allocate a socket and port for it and use it */ |
| 8339 | err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM, |
| 8340 | IPPROTO_TCP, &cfg->sock, 1); |
| 8341 | if (err) { |
| 8342 | kfree(cfg); |
| 8343 | return err; |
| 8344 | } |
| 8345 | if (inet_csk_get_port(cfg->sock->sk, port)) { |
| 8346 | sock_release(cfg->sock); |
| 8347 | kfree(cfg); |
| 8348 | return -EADDRINUSE; |
| 8349 | } |
| 8350 | cfg->src_port = inet_sk(cfg->sock->sk)->inet_num; |
| 8351 | #else |
| 8352 | if (!port) { |
| 8353 | kfree(cfg); |
| 8354 | return -EINVAL; |
| 8355 | } |
| 8356 | cfg->src_port = port; |
| 8357 | #endif |
| 8358 | |
| 8359 | cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]); |
| 8360 | cfg->payload_len = data_size; |
| 8361 | cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size; |
| 8362 | memcpy((void *)cfg->payload, |
| 8363 | nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]), |
| 8364 | data_size); |
| 8365 | if (seq) |
| 8366 | cfg->payload_seq = *seq; |
| 8367 | cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]); |
| 8368 | cfg->wake_len = wake_size; |
| 8369 | cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size; |
| 8370 | memcpy((void *)cfg->wake_data, |
| 8371 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]), |
| 8372 | wake_size); |
| 8373 | cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size + |
| 8374 | data_size + wake_size; |
| 8375 | memcpy((void *)cfg->wake_mask, |
| 8376 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]), |
| 8377 | wake_mask_size); |
| 8378 | if (tok) { |
| 8379 | cfg->tokens_size = tokens_size; |
| 8380 | memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size); |
| 8381 | } |
| 8382 | |
| 8383 | trig->tcp = cfg; |
| 8384 | |
| 8385 | return 0; |
| 8386 | } |
| 8387 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8388 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 8389 | { |
| 8390 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8391 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8392 | struct cfg80211_wowlan new_triggers = {}; |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8393 | struct cfg80211_wowlan *ntrig; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8394 | const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8395 | int err, i; |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8396 | bool prev_enabled = rdev->wiphy.wowlan_config; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8397 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8398 | if (!wowlan) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8399 | return -EOPNOTSUPP; |
| 8400 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8401 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) { |
| 8402 | cfg80211_rdev_free_wowlan(rdev); |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8403 | rdev->wiphy.wowlan_config = NULL; |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8404 | goto set_wakeup; |
| 8405 | } |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8406 | |
| 8407 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG, |
| 8408 | nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 8409 | nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 8410 | nl80211_wowlan_policy); |
| 8411 | if (err) |
| 8412 | return err; |
| 8413 | |
| 8414 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { |
| 8415 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) |
| 8416 | return -EINVAL; |
| 8417 | new_triggers.any = true; |
| 8418 | } |
| 8419 | |
| 8420 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { |
| 8421 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) |
| 8422 | return -EINVAL; |
| 8423 | new_triggers.disconnect = true; |
| 8424 | } |
| 8425 | |
| 8426 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { |
| 8427 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) |
| 8428 | return -EINVAL; |
| 8429 | new_triggers.magic_pkt = true; |
| 8430 | } |
| 8431 | |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 8432 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
| 8433 | return -EINVAL; |
| 8434 | |
| 8435 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { |
| 8436 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) |
| 8437 | return -EINVAL; |
| 8438 | new_triggers.gtk_rekey_failure = true; |
| 8439 | } |
| 8440 | |
| 8441 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { |
| 8442 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) |
| 8443 | return -EINVAL; |
| 8444 | new_triggers.eap_identity_req = true; |
| 8445 | } |
| 8446 | |
| 8447 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { |
| 8448 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) |
| 8449 | return -EINVAL; |
| 8450 | new_triggers.four_way_handshake = true; |
| 8451 | } |
| 8452 | |
| 8453 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { |
| 8454 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) |
| 8455 | return -EINVAL; |
| 8456 | new_triggers.rfkill_release = true; |
| 8457 | } |
| 8458 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8459 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
| 8460 | struct nlattr *pat; |
| 8461 | int n_patterns = 0; |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8462 | int rem, pat_len, mask_len, pkt_offset; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8463 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8464 | |
| 8465 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 8466 | rem) |
| 8467 | n_patterns++; |
| 8468 | if (n_patterns > wowlan->n_patterns) |
| 8469 | return -EINVAL; |
| 8470 | |
| 8471 | new_triggers.patterns = kcalloc(n_patterns, |
| 8472 | sizeof(new_triggers.patterns[0]), |
| 8473 | GFP_KERNEL); |
| 8474 | if (!new_triggers.patterns) |
| 8475 | return -ENOMEM; |
| 8476 | |
| 8477 | new_triggers.n_patterns = n_patterns; |
| 8478 | i = 0; |
| 8479 | |
| 8480 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 8481 | rem) { |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8482 | nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat), |
| 8483 | nla_len(pat), NULL); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8484 | err = -EINVAL; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8485 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
| 8486 | !pat_tb[NL80211_PKTPAT_PATTERN]) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8487 | goto error; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8488 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8489 | mask_len = DIV_ROUND_UP(pat_len, 8); |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8490 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8491 | goto error; |
| 8492 | if (pat_len > wowlan->pattern_max_len || |
| 8493 | pat_len < wowlan->pattern_min_len) |
| 8494 | goto error; |
| 8495 | |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8496 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8497 | pkt_offset = 0; |
| 8498 | else |
| 8499 | pkt_offset = nla_get_u32( |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8500 | pat_tb[NL80211_PKTPAT_OFFSET]); |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8501 | if (pkt_offset > wowlan->max_pkt_offset) |
| 8502 | goto error; |
| 8503 | new_triggers.patterns[i].pkt_offset = pkt_offset; |
| 8504 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8505 | new_triggers.patterns[i].mask = |
| 8506 | kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 8507 | if (!new_triggers.patterns[i].mask) { |
| 8508 | err = -ENOMEM; |
| 8509 | goto error; |
| 8510 | } |
| 8511 | new_triggers.patterns[i].pattern = |
| 8512 | new_triggers.patterns[i].mask + mask_len; |
| 8513 | memcpy(new_triggers.patterns[i].mask, |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8514 | nla_data(pat_tb[NL80211_PKTPAT_MASK]), |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8515 | mask_len); |
| 8516 | new_triggers.patterns[i].pattern_len = pat_len; |
| 8517 | memcpy(new_triggers.patterns[i].pattern, |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8518 | nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8519 | pat_len); |
| 8520 | i++; |
| 8521 | } |
| 8522 | } |
| 8523 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8524 | if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) { |
| 8525 | err = nl80211_parse_wowlan_tcp( |
| 8526 | rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION], |
| 8527 | &new_triggers); |
| 8528 | if (err) |
| 8529 | goto error; |
| 8530 | } |
| 8531 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8532 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL); |
| 8533 | if (!ntrig) { |
| 8534 | err = -ENOMEM; |
| 8535 | goto error; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8536 | } |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8537 | cfg80211_rdev_free_wowlan(rdev); |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8538 | rdev->wiphy.wowlan_config = ntrig; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8539 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8540 | set_wakeup: |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8541 | if (rdev->ops->set_wakeup && |
| 8542 | prev_enabled != !!rdev->wiphy.wowlan_config) |
| 8543 | rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config); |
Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame] | 8544 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8545 | return 0; |
| 8546 | error: |
| 8547 | for (i = 0; i < new_triggers.n_patterns; i++) |
| 8548 | kfree(new_triggers.patterns[i].mask); |
| 8549 | kfree(new_triggers.patterns); |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8550 | if (new_triggers.tcp && new_triggers.tcp->sock) |
| 8551 | sock_release(new_triggers.tcp->sock); |
| 8552 | kfree(new_triggers.tcp); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8553 | return err; |
| 8554 | } |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 8555 | #endif |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8556 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 8557 | static int nl80211_send_coalesce_rules(struct sk_buff *msg, |
| 8558 | struct cfg80211_registered_device *rdev) |
| 8559 | { |
| 8560 | struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules; |
| 8561 | int i, j, pat_len; |
| 8562 | struct cfg80211_coalesce_rules *rule; |
| 8563 | |
| 8564 | if (!rdev->coalesce->n_rules) |
| 8565 | return 0; |
| 8566 | |
| 8567 | nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE); |
| 8568 | if (!nl_rules) |
| 8569 | return -ENOBUFS; |
| 8570 | |
| 8571 | for (i = 0; i < rdev->coalesce->n_rules; i++) { |
| 8572 | nl_rule = nla_nest_start(msg, i + 1); |
| 8573 | if (!nl_rule) |
| 8574 | return -ENOBUFS; |
| 8575 | |
| 8576 | rule = &rdev->coalesce->rules[i]; |
| 8577 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY, |
| 8578 | rule->delay)) |
| 8579 | return -ENOBUFS; |
| 8580 | |
| 8581 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION, |
| 8582 | rule->condition)) |
| 8583 | return -ENOBUFS; |
| 8584 | |
| 8585 | nl_pats = nla_nest_start(msg, |
| 8586 | NL80211_ATTR_COALESCE_RULE_PKT_PATTERN); |
| 8587 | if (!nl_pats) |
| 8588 | return -ENOBUFS; |
| 8589 | |
| 8590 | for (j = 0; j < rule->n_patterns; j++) { |
| 8591 | nl_pat = nla_nest_start(msg, j + 1); |
| 8592 | if (!nl_pat) |
| 8593 | return -ENOBUFS; |
| 8594 | pat_len = rule->patterns[j].pattern_len; |
| 8595 | if (nla_put(msg, NL80211_PKTPAT_MASK, |
| 8596 | DIV_ROUND_UP(pat_len, 8), |
| 8597 | rule->patterns[j].mask) || |
| 8598 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
| 8599 | rule->patterns[j].pattern) || |
| 8600 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, |
| 8601 | rule->patterns[j].pkt_offset)) |
| 8602 | return -ENOBUFS; |
| 8603 | nla_nest_end(msg, nl_pat); |
| 8604 | } |
| 8605 | nla_nest_end(msg, nl_pats); |
| 8606 | nla_nest_end(msg, nl_rule); |
| 8607 | } |
| 8608 | nla_nest_end(msg, nl_rules); |
| 8609 | |
| 8610 | return 0; |
| 8611 | } |
| 8612 | |
| 8613 | static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info) |
| 8614 | { |
| 8615 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8616 | struct sk_buff *msg; |
| 8617 | void *hdr; |
| 8618 | |
| 8619 | if (!rdev->wiphy.coalesce) |
| 8620 | return -EOPNOTSUPP; |
| 8621 | |
| 8622 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 8623 | if (!msg) |
| 8624 | return -ENOMEM; |
| 8625 | |
| 8626 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 8627 | NL80211_CMD_GET_COALESCE); |
| 8628 | if (!hdr) |
| 8629 | goto nla_put_failure; |
| 8630 | |
| 8631 | if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev)) |
| 8632 | goto nla_put_failure; |
| 8633 | |
| 8634 | genlmsg_end(msg, hdr); |
| 8635 | return genlmsg_reply(msg, info); |
| 8636 | |
| 8637 | nla_put_failure: |
| 8638 | nlmsg_free(msg); |
| 8639 | return -ENOBUFS; |
| 8640 | } |
| 8641 | |
| 8642 | void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev) |
| 8643 | { |
| 8644 | struct cfg80211_coalesce *coalesce = rdev->coalesce; |
| 8645 | int i, j; |
| 8646 | struct cfg80211_coalesce_rules *rule; |
| 8647 | |
| 8648 | if (!coalesce) |
| 8649 | return; |
| 8650 | |
| 8651 | for (i = 0; i < coalesce->n_rules; i++) { |
| 8652 | rule = &coalesce->rules[i]; |
| 8653 | for (j = 0; j < rule->n_patterns; j++) |
| 8654 | kfree(rule->patterns[j].mask); |
| 8655 | kfree(rule->patterns); |
| 8656 | } |
| 8657 | kfree(coalesce->rules); |
| 8658 | kfree(coalesce); |
| 8659 | rdev->coalesce = NULL; |
| 8660 | } |
| 8661 | |
| 8662 | static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev, |
| 8663 | struct nlattr *rule, |
| 8664 | struct cfg80211_coalesce_rules *new_rule) |
| 8665 | { |
| 8666 | int err, i; |
| 8667 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; |
| 8668 | struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat; |
| 8669 | int rem, pat_len, mask_len, pkt_offset, n_patterns = 0; |
| 8670 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
| 8671 | |
| 8672 | err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule), |
| 8673 | nla_len(rule), nl80211_coalesce_policy); |
| 8674 | if (err) |
| 8675 | return err; |
| 8676 | |
| 8677 | if (tb[NL80211_ATTR_COALESCE_RULE_DELAY]) |
| 8678 | new_rule->delay = |
| 8679 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]); |
| 8680 | if (new_rule->delay > coalesce->max_delay) |
| 8681 | return -EINVAL; |
| 8682 | |
| 8683 | if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION]) |
| 8684 | new_rule->condition = |
| 8685 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]); |
| 8686 | if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH && |
| 8687 | new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH) |
| 8688 | return -EINVAL; |
| 8689 | |
| 8690 | if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN]) |
| 8691 | return -EINVAL; |
| 8692 | |
| 8693 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], |
| 8694 | rem) |
| 8695 | n_patterns++; |
| 8696 | if (n_patterns > coalesce->n_patterns) |
| 8697 | return -EINVAL; |
| 8698 | |
| 8699 | new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]), |
| 8700 | GFP_KERNEL); |
| 8701 | if (!new_rule->patterns) |
| 8702 | return -ENOMEM; |
| 8703 | |
| 8704 | new_rule->n_patterns = n_patterns; |
| 8705 | i = 0; |
| 8706 | |
| 8707 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], |
| 8708 | rem) { |
| 8709 | nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat), |
| 8710 | nla_len(pat), NULL); |
| 8711 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
| 8712 | !pat_tb[NL80211_PKTPAT_PATTERN]) |
| 8713 | return -EINVAL; |
| 8714 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
| 8715 | mask_len = DIV_ROUND_UP(pat_len, 8); |
| 8716 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
| 8717 | return -EINVAL; |
| 8718 | if (pat_len > coalesce->pattern_max_len || |
| 8719 | pat_len < coalesce->pattern_min_len) |
| 8720 | return -EINVAL; |
| 8721 | |
| 8722 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
| 8723 | pkt_offset = 0; |
| 8724 | else |
| 8725 | pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]); |
| 8726 | if (pkt_offset > coalesce->max_pkt_offset) |
| 8727 | return -EINVAL; |
| 8728 | new_rule->patterns[i].pkt_offset = pkt_offset; |
| 8729 | |
| 8730 | new_rule->patterns[i].mask = |
| 8731 | kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 8732 | if (!new_rule->patterns[i].mask) |
| 8733 | return -ENOMEM; |
| 8734 | new_rule->patterns[i].pattern = |
| 8735 | new_rule->patterns[i].mask + mask_len; |
| 8736 | memcpy(new_rule->patterns[i].mask, |
| 8737 | nla_data(pat_tb[NL80211_PKTPAT_MASK]), mask_len); |
| 8738 | new_rule->patterns[i].pattern_len = pat_len; |
| 8739 | memcpy(new_rule->patterns[i].pattern, |
| 8740 | nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), pat_len); |
| 8741 | i++; |
| 8742 | } |
| 8743 | |
| 8744 | return 0; |
| 8745 | } |
| 8746 | |
| 8747 | static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info) |
| 8748 | { |
| 8749 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8750 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; |
| 8751 | struct cfg80211_coalesce new_coalesce = {}; |
| 8752 | struct cfg80211_coalesce *n_coalesce; |
| 8753 | int err, rem_rule, n_rules = 0, i, j; |
| 8754 | struct nlattr *rule; |
| 8755 | struct cfg80211_coalesce_rules *tmp_rule; |
| 8756 | |
| 8757 | if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce) |
| 8758 | return -EOPNOTSUPP; |
| 8759 | |
| 8760 | if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) { |
| 8761 | cfg80211_rdev_free_coalesce(rdev); |
| 8762 | rdev->ops->set_coalesce(&rdev->wiphy, NULL); |
| 8763 | return 0; |
| 8764 | } |
| 8765 | |
| 8766 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], |
| 8767 | rem_rule) |
| 8768 | n_rules++; |
| 8769 | if (n_rules > coalesce->n_rules) |
| 8770 | return -EINVAL; |
| 8771 | |
| 8772 | new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]), |
| 8773 | GFP_KERNEL); |
| 8774 | if (!new_coalesce.rules) |
| 8775 | return -ENOMEM; |
| 8776 | |
| 8777 | new_coalesce.n_rules = n_rules; |
| 8778 | i = 0; |
| 8779 | |
| 8780 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], |
| 8781 | rem_rule) { |
| 8782 | err = nl80211_parse_coalesce_rule(rdev, rule, |
| 8783 | &new_coalesce.rules[i]); |
| 8784 | if (err) |
| 8785 | goto error; |
| 8786 | |
| 8787 | i++; |
| 8788 | } |
| 8789 | |
| 8790 | err = rdev->ops->set_coalesce(&rdev->wiphy, &new_coalesce); |
| 8791 | if (err) |
| 8792 | goto error; |
| 8793 | |
| 8794 | n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL); |
| 8795 | if (!n_coalesce) { |
| 8796 | err = -ENOMEM; |
| 8797 | goto error; |
| 8798 | } |
| 8799 | cfg80211_rdev_free_coalesce(rdev); |
| 8800 | rdev->coalesce = n_coalesce; |
| 8801 | |
| 8802 | return 0; |
| 8803 | error: |
| 8804 | for (i = 0; i < new_coalesce.n_rules; i++) { |
| 8805 | tmp_rule = &new_coalesce.rules[i]; |
| 8806 | for (j = 0; j < tmp_rule->n_patterns; j++) |
| 8807 | kfree(tmp_rule->patterns[j].mask); |
| 8808 | kfree(tmp_rule->patterns); |
| 8809 | } |
| 8810 | kfree(new_coalesce.rules); |
| 8811 | |
| 8812 | return err; |
| 8813 | } |
| 8814 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 8815 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
| 8816 | { |
| 8817 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8818 | struct net_device *dev = info->user_ptr[1]; |
| 8819 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 8820 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; |
| 8821 | struct cfg80211_gtk_rekey_data rekey_data; |
| 8822 | int err; |
| 8823 | |
| 8824 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) |
| 8825 | return -EINVAL; |
| 8826 | |
| 8827 | err = nla_parse(tb, MAX_NL80211_REKEY_DATA, |
| 8828 | nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 8829 | nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 8830 | nl80211_rekey_policy); |
| 8831 | if (err) |
| 8832 | return err; |
| 8833 | |
| 8834 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) |
| 8835 | return -ERANGE; |
| 8836 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) |
| 8837 | return -ERANGE; |
| 8838 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) |
| 8839 | return -ERANGE; |
| 8840 | |
| 8841 | memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]), |
| 8842 | NL80211_KEK_LEN); |
| 8843 | memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]), |
| 8844 | NL80211_KCK_LEN); |
| 8845 | memcpy(rekey_data.replay_ctr, |
| 8846 | nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]), |
| 8847 | NL80211_REPLAY_CTR_LEN); |
| 8848 | |
| 8849 | wdev_lock(wdev); |
| 8850 | if (!wdev->current_bss) { |
| 8851 | err = -ENOTCONN; |
| 8852 | goto out; |
| 8853 | } |
| 8854 | |
| 8855 | if (!rdev->ops->set_rekey_data) { |
| 8856 | err = -EOPNOTSUPP; |
| 8857 | goto out; |
| 8858 | } |
| 8859 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8860 | err = rdev_set_rekey_data(rdev, dev, &rekey_data); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 8861 | out: |
| 8862 | wdev_unlock(wdev); |
| 8863 | return err; |
| 8864 | } |
| 8865 | |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8866 | static int nl80211_register_unexpected_frame(struct sk_buff *skb, |
| 8867 | struct genl_info *info) |
| 8868 | { |
| 8869 | struct net_device *dev = info->user_ptr[1]; |
| 8870 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 8871 | |
| 8872 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 8873 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 8874 | return -EINVAL; |
| 8875 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8876 | if (wdev->ap_unexpected_nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8877 | return -EBUSY; |
| 8878 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8879 | wdev->ap_unexpected_nlportid = info->snd_portid; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8880 | return 0; |
| 8881 | } |
| 8882 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8883 | static int nl80211_probe_client(struct sk_buff *skb, |
| 8884 | struct genl_info *info) |
| 8885 | { |
| 8886 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8887 | struct net_device *dev = info->user_ptr[1]; |
| 8888 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 8889 | struct sk_buff *msg; |
| 8890 | void *hdr; |
| 8891 | const u8 *addr; |
| 8892 | u64 cookie; |
| 8893 | int err; |
| 8894 | |
| 8895 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 8896 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 8897 | return -EOPNOTSUPP; |
| 8898 | |
| 8899 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 8900 | return -EINVAL; |
| 8901 | |
| 8902 | if (!rdev->ops->probe_client) |
| 8903 | return -EOPNOTSUPP; |
| 8904 | |
| 8905 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 8906 | if (!msg) |
| 8907 | return -ENOMEM; |
| 8908 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8909 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8910 | NL80211_CMD_PROBE_CLIENT); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 8911 | if (!hdr) { |
| 8912 | err = -ENOBUFS; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8913 | goto free_msg; |
| 8914 | } |
| 8915 | |
| 8916 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 8917 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8918 | err = rdev_probe_client(rdev, dev, addr, &cookie); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8919 | if (err) |
| 8920 | goto free_msg; |
| 8921 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8922 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 8923 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8924 | |
| 8925 | genlmsg_end(msg, hdr); |
| 8926 | |
| 8927 | return genlmsg_reply(msg, info); |
| 8928 | |
| 8929 | nla_put_failure: |
| 8930 | err = -ENOBUFS; |
| 8931 | free_msg: |
| 8932 | nlmsg_free(msg); |
| 8933 | return err; |
| 8934 | } |
| 8935 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8936 | static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) |
| 8937 | { |
| 8938 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 8939 | struct cfg80211_beacon_registration *reg, *nreg; |
| 8940 | int rv; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8941 | |
| 8942 | if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) |
| 8943 | return -EOPNOTSUPP; |
| 8944 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 8945 | nreg = kzalloc(sizeof(*nreg), GFP_KERNEL); |
| 8946 | if (!nreg) |
| 8947 | return -ENOMEM; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8948 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 8949 | /* First, check if already registered. */ |
| 8950 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 8951 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 8952 | if (reg->nlportid == info->snd_portid) { |
| 8953 | rv = -EALREADY; |
| 8954 | goto out_err; |
| 8955 | } |
| 8956 | } |
| 8957 | /* Add it to the list */ |
| 8958 | nreg->nlportid = info->snd_portid; |
| 8959 | list_add(&nreg->list, &rdev->beacon_registrations); |
| 8960 | |
| 8961 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8962 | |
| 8963 | return 0; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 8964 | out_err: |
| 8965 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 8966 | kfree(nreg); |
| 8967 | return rv; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8968 | } |
| 8969 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8970 | static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 8971 | { |
| 8972 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8973 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 8974 | int err; |
| 8975 | |
| 8976 | if (!rdev->ops->start_p2p_device) |
| 8977 | return -EOPNOTSUPP; |
| 8978 | |
| 8979 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 8980 | return -EOPNOTSUPP; |
| 8981 | |
| 8982 | if (wdev->p2p_started) |
| 8983 | return 0; |
| 8984 | |
Luciano Coelho | b6a5501 | 2014-02-27 11:07:21 +0200 | [diff] [blame] | 8985 | if (rfkill_blocked(rdev->rfkill)) |
| 8986 | return -ERFKILL; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8987 | |
Johannes Berg | eeb126e | 2012-10-23 15:16:50 +0200 | [diff] [blame] | 8988 | err = rdev_start_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8989 | if (err) |
| 8990 | return err; |
| 8991 | |
| 8992 | wdev->p2p_started = true; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8993 | rdev->opencount++; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8994 | |
| 8995 | return 0; |
| 8996 | } |
| 8997 | |
| 8998 | static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 8999 | { |
| 9000 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9001 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 9002 | |
| 9003 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 9004 | return -EOPNOTSUPP; |
| 9005 | |
| 9006 | if (!rdev->ops->stop_p2p_device) |
| 9007 | return -EOPNOTSUPP; |
| 9008 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 9009 | cfg80211_stop_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9010 | |
| 9011 | return 0; |
| 9012 | } |
| 9013 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 9014 | static int nl80211_get_protocol_features(struct sk_buff *skb, |
| 9015 | struct genl_info *info) |
| 9016 | { |
| 9017 | void *hdr; |
| 9018 | struct sk_buff *msg; |
| 9019 | |
| 9020 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 9021 | if (!msg) |
| 9022 | return -ENOMEM; |
| 9023 | |
| 9024 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 9025 | NL80211_CMD_GET_PROTOCOL_FEATURES); |
| 9026 | if (!hdr) |
| 9027 | goto nla_put_failure; |
| 9028 | |
| 9029 | if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES, |
| 9030 | NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)) |
| 9031 | goto nla_put_failure; |
| 9032 | |
| 9033 | genlmsg_end(msg, hdr); |
| 9034 | return genlmsg_reply(msg, info); |
| 9035 | |
| 9036 | nla_put_failure: |
| 9037 | kfree_skb(msg); |
| 9038 | return -ENOBUFS; |
| 9039 | } |
| 9040 | |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 9041 | static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info) |
| 9042 | { |
| 9043 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9044 | struct cfg80211_update_ft_ies_params ft_params; |
| 9045 | struct net_device *dev = info->user_ptr[1]; |
| 9046 | |
| 9047 | if (!rdev->ops->update_ft_ies) |
| 9048 | return -EOPNOTSUPP; |
| 9049 | |
| 9050 | if (!info->attrs[NL80211_ATTR_MDID] || |
| 9051 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 9052 | return -EINVAL; |
| 9053 | |
| 9054 | memset(&ft_params, 0, sizeof(ft_params)); |
| 9055 | ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]); |
| 9056 | ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 9057 | ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 9058 | |
| 9059 | return rdev_update_ft_ies(rdev, dev, &ft_params); |
| 9060 | } |
| 9061 | |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 9062 | static int nl80211_crit_protocol_start(struct sk_buff *skb, |
| 9063 | struct genl_info *info) |
| 9064 | { |
| 9065 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9066 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 9067 | enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC; |
| 9068 | u16 duration; |
| 9069 | int ret; |
| 9070 | |
| 9071 | if (!rdev->ops->crit_proto_start) |
| 9072 | return -EOPNOTSUPP; |
| 9073 | |
| 9074 | if (WARN_ON(!rdev->ops->crit_proto_stop)) |
| 9075 | return -EINVAL; |
| 9076 | |
| 9077 | if (rdev->crit_proto_nlportid) |
| 9078 | return -EBUSY; |
| 9079 | |
| 9080 | /* determine protocol if provided */ |
| 9081 | if (info->attrs[NL80211_ATTR_CRIT_PROT_ID]) |
| 9082 | proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]); |
| 9083 | |
| 9084 | if (proto >= NUM_NL80211_CRIT_PROTO) |
| 9085 | return -EINVAL; |
| 9086 | |
| 9087 | /* timeout must be provided */ |
| 9088 | if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]) |
| 9089 | return -EINVAL; |
| 9090 | |
| 9091 | duration = |
| 9092 | nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]); |
| 9093 | |
| 9094 | if (duration > NL80211_CRIT_PROTO_MAX_DURATION) |
| 9095 | return -ERANGE; |
| 9096 | |
| 9097 | ret = rdev_crit_proto_start(rdev, wdev, proto, duration); |
| 9098 | if (!ret) |
| 9099 | rdev->crit_proto_nlportid = info->snd_portid; |
| 9100 | |
| 9101 | return ret; |
| 9102 | } |
| 9103 | |
| 9104 | static int nl80211_crit_protocol_stop(struct sk_buff *skb, |
| 9105 | struct genl_info *info) |
| 9106 | { |
| 9107 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9108 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 9109 | |
| 9110 | if (!rdev->ops->crit_proto_stop) |
| 9111 | return -EOPNOTSUPP; |
| 9112 | |
| 9113 | if (rdev->crit_proto_nlportid) { |
| 9114 | rdev->crit_proto_nlportid = 0; |
| 9115 | rdev_crit_proto_stop(rdev, wdev); |
| 9116 | } |
| 9117 | return 0; |
| 9118 | } |
| 9119 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 9120 | static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info) |
| 9121 | { |
| 9122 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9123 | struct wireless_dev *wdev = |
| 9124 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); |
| 9125 | int i, err; |
| 9126 | u32 vid, subcmd; |
| 9127 | |
| 9128 | if (!rdev->wiphy.vendor_commands) |
| 9129 | return -EOPNOTSUPP; |
| 9130 | |
| 9131 | if (IS_ERR(wdev)) { |
| 9132 | err = PTR_ERR(wdev); |
| 9133 | if (err != -EINVAL) |
| 9134 | return err; |
| 9135 | wdev = NULL; |
| 9136 | } else if (wdev->wiphy != &rdev->wiphy) { |
| 9137 | return -EINVAL; |
| 9138 | } |
| 9139 | |
| 9140 | if (!info->attrs[NL80211_ATTR_VENDOR_ID] || |
| 9141 | !info->attrs[NL80211_ATTR_VENDOR_SUBCMD]) |
| 9142 | return -EINVAL; |
| 9143 | |
| 9144 | vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]); |
| 9145 | subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]); |
| 9146 | for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { |
| 9147 | const struct wiphy_vendor_command *vcmd; |
| 9148 | void *data = NULL; |
| 9149 | int len = 0; |
| 9150 | |
| 9151 | vcmd = &rdev->wiphy.vendor_commands[i]; |
| 9152 | |
| 9153 | if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd) |
| 9154 | continue; |
| 9155 | |
| 9156 | if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV | |
| 9157 | WIPHY_VENDOR_CMD_NEED_NETDEV)) { |
| 9158 | if (!wdev) |
| 9159 | return -EINVAL; |
| 9160 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV && |
| 9161 | !wdev->netdev) |
| 9162 | return -EINVAL; |
| 9163 | |
| 9164 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) { |
| 9165 | if (wdev->netdev && |
| 9166 | !netif_running(wdev->netdev)) |
| 9167 | return -ENETDOWN; |
| 9168 | if (!wdev->netdev && !wdev->p2p_started) |
| 9169 | return -ENETDOWN; |
| 9170 | } |
| 9171 | } else { |
| 9172 | wdev = NULL; |
| 9173 | } |
| 9174 | |
| 9175 | if (info->attrs[NL80211_ATTR_VENDOR_DATA]) { |
| 9176 | data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]); |
| 9177 | len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]); |
| 9178 | } |
| 9179 | |
| 9180 | rdev->cur_cmd_info = info; |
| 9181 | err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev, |
| 9182 | data, len); |
| 9183 | rdev->cur_cmd_info = NULL; |
| 9184 | return err; |
| 9185 | } |
| 9186 | |
| 9187 | return -EOPNOTSUPP; |
| 9188 | } |
| 9189 | |
| 9190 | struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy, |
| 9191 | enum nl80211_commands cmd, |
| 9192 | enum nl80211_attrs attr, |
| 9193 | int approxlen) |
| 9194 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 9195 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 9196 | |
| 9197 | if (WARN_ON(!rdev->cur_cmd_info)) |
| 9198 | return NULL; |
| 9199 | |
| 9200 | return __cfg80211_alloc_vendor_skb(rdev, approxlen, |
| 9201 | rdev->cur_cmd_info->snd_portid, |
| 9202 | rdev->cur_cmd_info->snd_seq, |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 9203 | cmd, attr, NULL, GFP_KERNEL); |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 9204 | } |
| 9205 | EXPORT_SYMBOL(__cfg80211_alloc_reply_skb); |
| 9206 | |
| 9207 | int cfg80211_vendor_cmd_reply(struct sk_buff *skb) |
| 9208 | { |
| 9209 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 9210 | void *hdr = ((void **)skb->cb)[1]; |
| 9211 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 9212 | |
| 9213 | if (WARN_ON(!rdev->cur_cmd_info)) { |
| 9214 | kfree_skb(skb); |
| 9215 | return -EINVAL; |
| 9216 | } |
| 9217 | |
| 9218 | nla_nest_end(skb, data); |
| 9219 | genlmsg_end(skb, hdr); |
| 9220 | return genlmsg_reply(skb, rdev->cur_cmd_info); |
| 9221 | } |
| 9222 | EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply); |
| 9223 | |
| 9224 | |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 9225 | static int nl80211_set_qos_map(struct sk_buff *skb, |
| 9226 | struct genl_info *info) |
| 9227 | { |
| 9228 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9229 | struct cfg80211_qos_map *qos_map = NULL; |
| 9230 | struct net_device *dev = info->user_ptr[1]; |
| 9231 | u8 *pos, len, num_des, des_len, des; |
| 9232 | int ret; |
| 9233 | |
| 9234 | if (!rdev->ops->set_qos_map) |
| 9235 | return -EOPNOTSUPP; |
| 9236 | |
| 9237 | if (info->attrs[NL80211_ATTR_QOS_MAP]) { |
| 9238 | pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]); |
| 9239 | len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]); |
| 9240 | |
| 9241 | if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN || |
| 9242 | len > IEEE80211_QOS_MAP_LEN_MAX) |
| 9243 | return -EINVAL; |
| 9244 | |
| 9245 | qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL); |
| 9246 | if (!qos_map) |
| 9247 | return -ENOMEM; |
| 9248 | |
| 9249 | num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1; |
| 9250 | if (num_des) { |
| 9251 | des_len = num_des * |
| 9252 | sizeof(struct cfg80211_dscp_exception); |
| 9253 | memcpy(qos_map->dscp_exception, pos, des_len); |
| 9254 | qos_map->num_des = num_des; |
| 9255 | for (des = 0; des < num_des; des++) { |
| 9256 | if (qos_map->dscp_exception[des].up > 7) { |
| 9257 | kfree(qos_map); |
| 9258 | return -EINVAL; |
| 9259 | } |
| 9260 | } |
| 9261 | pos += des_len; |
| 9262 | } |
| 9263 | memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN); |
| 9264 | } |
| 9265 | |
| 9266 | wdev_lock(dev->ieee80211_ptr); |
| 9267 | ret = nl80211_key_allowed(dev->ieee80211_ptr); |
| 9268 | if (!ret) |
| 9269 | ret = rdev_set_qos_map(rdev, dev, qos_map); |
| 9270 | wdev_unlock(dev->ieee80211_ptr); |
| 9271 | |
| 9272 | kfree(qos_map); |
| 9273 | return ret; |
| 9274 | } |
| 9275 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9276 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
| 9277 | #define NL80211_FLAG_NEED_NETDEV 0x02 |
| 9278 | #define NL80211_FLAG_NEED_RTNL 0x04 |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9279 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
| 9280 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ |
| 9281 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 9282 | #define NL80211_FLAG_NEED_WDEV 0x10 |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9283 | /* 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] | 9284 | #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\ |
| 9285 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9286 | |
Johannes Berg | f84f771 | 2013-11-14 17:14:45 +0100 | [diff] [blame] | 9287 | 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] | 9288 | struct genl_info *info) |
| 9289 | { |
| 9290 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 9291 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9292 | struct net_device *dev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9293 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
| 9294 | |
| 9295 | if (rtnl) |
| 9296 | rtnl_lock(); |
| 9297 | |
| 9298 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 9299 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9300 | if (IS_ERR(rdev)) { |
| 9301 | if (rtnl) |
| 9302 | rtnl_unlock(); |
| 9303 | return PTR_ERR(rdev); |
| 9304 | } |
| 9305 | info->user_ptr[0] = rdev; |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 9306 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV || |
| 9307 | ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 9308 | ASSERT_RTNL(); |
| 9309 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 9310 | wdev = __cfg80211_wdev_from_attrs(genl_info_net(info), |
| 9311 | info->attrs); |
| 9312 | if (IS_ERR(wdev)) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9313 | if (rtnl) |
| 9314 | rtnl_unlock(); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 9315 | return PTR_ERR(wdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9316 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 9317 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 9318 | dev = wdev->netdev; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 9319 | rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 9320 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 9321 | if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
| 9322 | if (!dev) { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 9323 | if (rtnl) |
| 9324 | rtnl_unlock(); |
| 9325 | return -EINVAL; |
| 9326 | } |
| 9327 | |
| 9328 | info->user_ptr[1] = dev; |
| 9329 | } else { |
| 9330 | info->user_ptr[1] = wdev; |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9331 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 9332 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 9333 | if (dev) { |
| 9334 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && |
| 9335 | !netif_running(dev)) { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 9336 | if (rtnl) |
| 9337 | rtnl_unlock(); |
| 9338 | return -ENETDOWN; |
| 9339 | } |
| 9340 | |
| 9341 | dev_hold(dev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9342 | } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) { |
| 9343 | if (!wdev->p2p_started) { |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9344 | if (rtnl) |
| 9345 | rtnl_unlock(); |
| 9346 | return -ENETDOWN; |
| 9347 | } |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 9348 | } |
| 9349 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9350 | info->user_ptr[0] = rdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9351 | } |
| 9352 | |
| 9353 | return 0; |
| 9354 | } |
| 9355 | |
Johannes Berg | f84f771 | 2013-11-14 17:14:45 +0100 | [diff] [blame] | 9356 | 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] | 9357 | struct genl_info *info) |
| 9358 | { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 9359 | if (info->user_ptr[1]) { |
| 9360 | if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
| 9361 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 9362 | |
| 9363 | if (wdev->netdev) |
| 9364 | dev_put(wdev->netdev); |
| 9365 | } else { |
| 9366 | dev_put(info->user_ptr[1]); |
| 9367 | } |
| 9368 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9369 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
| 9370 | rtnl_unlock(); |
| 9371 | } |
| 9372 | |
Johannes Berg | 4534de8 | 2013-11-14 17:14:46 +0100 | [diff] [blame] | 9373 | static const struct genl_ops nl80211_ops[] = { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9374 | { |
| 9375 | .cmd = NL80211_CMD_GET_WIPHY, |
| 9376 | .doit = nl80211_get_wiphy, |
| 9377 | .dumpit = nl80211_dump_wiphy, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 9378 | .done = nl80211_dump_wiphy_done, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9379 | .policy = nl80211_policy, |
| 9380 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 9381 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9382 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9383 | }, |
| 9384 | { |
| 9385 | .cmd = NL80211_CMD_SET_WIPHY, |
| 9386 | .doit = nl80211_set_wiphy, |
| 9387 | .policy = nl80211_policy, |
| 9388 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9389 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9390 | }, |
| 9391 | { |
| 9392 | .cmd = NL80211_CMD_GET_INTERFACE, |
| 9393 | .doit = nl80211_get_interface, |
| 9394 | .dumpit = nl80211_dump_interface, |
| 9395 | .policy = nl80211_policy, |
| 9396 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 9397 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 9398 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9399 | }, |
| 9400 | { |
| 9401 | .cmd = NL80211_CMD_SET_INTERFACE, |
| 9402 | .doit = nl80211_set_interface, |
| 9403 | .policy = nl80211_policy, |
| 9404 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9405 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9406 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9407 | }, |
| 9408 | { |
| 9409 | .cmd = NL80211_CMD_NEW_INTERFACE, |
| 9410 | .doit = nl80211_new_interface, |
| 9411 | .policy = nl80211_policy, |
| 9412 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9413 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9414 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9415 | }, |
| 9416 | { |
| 9417 | .cmd = NL80211_CMD_DEL_INTERFACE, |
| 9418 | .doit = nl80211_del_interface, |
| 9419 | .policy = nl80211_policy, |
| 9420 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 9421 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9422 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9423 | }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 9424 | { |
| 9425 | .cmd = NL80211_CMD_GET_KEY, |
| 9426 | .doit = nl80211_get_key, |
| 9427 | .policy = nl80211_policy, |
| 9428 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9429 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9430 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 9431 | }, |
| 9432 | { |
| 9433 | .cmd = NL80211_CMD_SET_KEY, |
| 9434 | .doit = nl80211_set_key, |
| 9435 | .policy = nl80211_policy, |
| 9436 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9437 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9438 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 9439 | }, |
| 9440 | { |
| 9441 | .cmd = NL80211_CMD_NEW_KEY, |
| 9442 | .doit = nl80211_new_key, |
| 9443 | .policy = nl80211_policy, |
| 9444 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9445 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9446 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 9447 | }, |
| 9448 | { |
| 9449 | .cmd = NL80211_CMD_DEL_KEY, |
| 9450 | .doit = nl80211_del_key, |
| 9451 | .policy = nl80211_policy, |
| 9452 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9453 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9454 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 9455 | }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 9456 | { |
| 9457 | .cmd = NL80211_CMD_SET_BEACON, |
| 9458 | .policy = nl80211_policy, |
| 9459 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 9460 | .doit = nl80211_set_beacon, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9461 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9462 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 9463 | }, |
| 9464 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 9465 | .cmd = NL80211_CMD_START_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 9466 | .policy = nl80211_policy, |
| 9467 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 9468 | .doit = nl80211_start_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9469 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9470 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 9471 | }, |
| 9472 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 9473 | .cmd = NL80211_CMD_STOP_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 9474 | .policy = nl80211_policy, |
| 9475 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 9476 | .doit = nl80211_stop_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9477 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9478 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 9479 | }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 9480 | { |
| 9481 | .cmd = NL80211_CMD_GET_STATION, |
| 9482 | .doit = nl80211_get_station, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9483 | .dumpit = nl80211_dump_station, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 9484 | .policy = nl80211_policy, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9485 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9486 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 9487 | }, |
| 9488 | { |
| 9489 | .cmd = NL80211_CMD_SET_STATION, |
| 9490 | .doit = nl80211_set_station, |
| 9491 | .policy = nl80211_policy, |
| 9492 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9493 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9494 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 9495 | }, |
| 9496 | { |
| 9497 | .cmd = NL80211_CMD_NEW_STATION, |
| 9498 | .doit = nl80211_new_station, |
| 9499 | .policy = nl80211_policy, |
| 9500 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9501 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9502 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 9503 | }, |
| 9504 | { |
| 9505 | .cmd = NL80211_CMD_DEL_STATION, |
| 9506 | .doit = nl80211_del_station, |
| 9507 | .policy = nl80211_policy, |
| 9508 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9509 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9510 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 9511 | }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9512 | { |
| 9513 | .cmd = NL80211_CMD_GET_MPATH, |
| 9514 | .doit = nl80211_get_mpath, |
| 9515 | .dumpit = nl80211_dump_mpath, |
| 9516 | .policy = nl80211_policy, |
| 9517 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9518 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9519 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9520 | }, |
| 9521 | { |
| 9522 | .cmd = NL80211_CMD_SET_MPATH, |
| 9523 | .doit = nl80211_set_mpath, |
| 9524 | .policy = nl80211_policy, |
| 9525 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9526 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9527 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9528 | }, |
| 9529 | { |
| 9530 | .cmd = NL80211_CMD_NEW_MPATH, |
| 9531 | .doit = nl80211_new_mpath, |
| 9532 | .policy = nl80211_policy, |
| 9533 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9534 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9535 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9536 | }, |
| 9537 | { |
| 9538 | .cmd = NL80211_CMD_DEL_MPATH, |
| 9539 | .doit = nl80211_del_mpath, |
| 9540 | .policy = nl80211_policy, |
| 9541 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9542 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9543 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9544 | }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 9545 | { |
| 9546 | .cmd = NL80211_CMD_SET_BSS, |
| 9547 | .doit = nl80211_set_bss, |
| 9548 | .policy = nl80211_policy, |
| 9549 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9550 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9551 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 9552 | }, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 9553 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 9554 | .cmd = NL80211_CMD_GET_REG, |
| 9555 | .doit = nl80211_get_reg, |
| 9556 | .policy = nl80211_policy, |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 9557 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 9558 | /* can be retrieved by unprivileged users */ |
| 9559 | }, |
| 9560 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 9561 | .cmd = NL80211_CMD_SET_REG, |
| 9562 | .doit = nl80211_set_reg, |
| 9563 | .policy = nl80211_policy, |
| 9564 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 9565 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 9566 | }, |
| 9567 | { |
| 9568 | .cmd = NL80211_CMD_REQ_SET_REG, |
| 9569 | .doit = nl80211_req_set_reg, |
| 9570 | .policy = nl80211_policy, |
| 9571 | .flags = GENL_ADMIN_PERM, |
| 9572 | }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 9573 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 9574 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
| 9575 | .doit = nl80211_get_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 9576 | .policy = nl80211_policy, |
| 9577 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9578 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9579 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 9580 | }, |
| 9581 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 9582 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
| 9583 | .doit = nl80211_update_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 9584 | .policy = nl80211_policy, |
| 9585 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 9586 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9587 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 9588 | }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 9589 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9590 | .cmd = NL80211_CMD_TRIGGER_SCAN, |
| 9591 | .doit = nl80211_trigger_scan, |
| 9592 | .policy = nl80211_policy, |
| 9593 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9594 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9595 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9596 | }, |
| 9597 | { |
| 9598 | .cmd = NL80211_CMD_GET_SCAN, |
| 9599 | .policy = nl80211_policy, |
| 9600 | .dumpit = nl80211_dump_scan, |
| 9601 | }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9602 | { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9603 | .cmd = NL80211_CMD_START_SCHED_SCAN, |
| 9604 | .doit = nl80211_start_sched_scan, |
| 9605 | .policy = nl80211_policy, |
| 9606 | .flags = GENL_ADMIN_PERM, |
| 9607 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9608 | NL80211_FLAG_NEED_RTNL, |
| 9609 | }, |
| 9610 | { |
| 9611 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, |
| 9612 | .doit = nl80211_stop_sched_scan, |
| 9613 | .policy = nl80211_policy, |
| 9614 | .flags = GENL_ADMIN_PERM, |
| 9615 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9616 | NL80211_FLAG_NEED_RTNL, |
| 9617 | }, |
| 9618 | { |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9619 | .cmd = NL80211_CMD_AUTHENTICATE, |
| 9620 | .doit = nl80211_authenticate, |
| 9621 | .policy = nl80211_policy, |
| 9622 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9623 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9624 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9625 | }, |
| 9626 | { |
| 9627 | .cmd = NL80211_CMD_ASSOCIATE, |
| 9628 | .doit = nl80211_associate, |
| 9629 | .policy = nl80211_policy, |
| 9630 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9631 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9632 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9633 | }, |
| 9634 | { |
| 9635 | .cmd = NL80211_CMD_DEAUTHENTICATE, |
| 9636 | .doit = nl80211_deauthenticate, |
| 9637 | .policy = nl80211_policy, |
| 9638 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9639 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9640 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9641 | }, |
| 9642 | { |
| 9643 | .cmd = NL80211_CMD_DISASSOCIATE, |
| 9644 | .doit = nl80211_disassociate, |
| 9645 | .policy = nl80211_policy, |
| 9646 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9647 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9648 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9649 | }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9650 | { |
| 9651 | .cmd = NL80211_CMD_JOIN_IBSS, |
| 9652 | .doit = nl80211_join_ibss, |
| 9653 | .policy = nl80211_policy, |
| 9654 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9655 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9656 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9657 | }, |
| 9658 | { |
| 9659 | .cmd = NL80211_CMD_LEAVE_IBSS, |
| 9660 | .doit = nl80211_leave_ibss, |
| 9661 | .policy = nl80211_policy, |
| 9662 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9663 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9664 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9665 | }, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 9666 | #ifdef CONFIG_NL80211_TESTMODE |
| 9667 | { |
| 9668 | .cmd = NL80211_CMD_TESTMODE, |
| 9669 | .doit = nl80211_testmode_do, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 9670 | .dumpit = nl80211_testmode_dump, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 9671 | .policy = nl80211_policy, |
| 9672 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9673 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9674 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 9675 | }, |
| 9676 | #endif |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9677 | { |
| 9678 | .cmd = NL80211_CMD_CONNECT, |
| 9679 | .doit = nl80211_connect, |
| 9680 | .policy = nl80211_policy, |
| 9681 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9682 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9683 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9684 | }, |
| 9685 | { |
| 9686 | .cmd = NL80211_CMD_DISCONNECT, |
| 9687 | .doit = nl80211_disconnect, |
| 9688 | .policy = nl80211_policy, |
| 9689 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9690 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9691 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9692 | }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9693 | { |
| 9694 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, |
| 9695 | .doit = nl80211_wiphy_netns, |
| 9696 | .policy = nl80211_policy, |
| 9697 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9698 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9699 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9700 | }, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 9701 | { |
| 9702 | .cmd = NL80211_CMD_GET_SURVEY, |
| 9703 | .policy = nl80211_policy, |
| 9704 | .dumpit = nl80211_dump_survey, |
| 9705 | }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9706 | { |
| 9707 | .cmd = NL80211_CMD_SET_PMKSA, |
| 9708 | .doit = nl80211_setdel_pmksa, |
| 9709 | .policy = nl80211_policy, |
| 9710 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9711 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9712 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9713 | }, |
| 9714 | { |
| 9715 | .cmd = NL80211_CMD_DEL_PMKSA, |
| 9716 | .doit = nl80211_setdel_pmksa, |
| 9717 | .policy = nl80211_policy, |
| 9718 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9719 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9720 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9721 | }, |
| 9722 | { |
| 9723 | .cmd = NL80211_CMD_FLUSH_PMKSA, |
| 9724 | .doit = nl80211_flush_pmksa, |
| 9725 | .policy = nl80211_policy, |
| 9726 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9727 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9728 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9729 | }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9730 | { |
| 9731 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, |
| 9732 | .doit = nl80211_remain_on_channel, |
| 9733 | .policy = nl80211_policy, |
| 9734 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9735 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9736 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9737 | }, |
| 9738 | { |
| 9739 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
| 9740 | .doit = nl80211_cancel_remain_on_channel, |
| 9741 | .policy = nl80211_policy, |
| 9742 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9743 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9744 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9745 | }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 9746 | { |
| 9747 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, |
| 9748 | .doit = nl80211_set_tx_bitrate_mask, |
| 9749 | .policy = nl80211_policy, |
| 9750 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9751 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9752 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 9753 | }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9754 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9755 | .cmd = NL80211_CMD_REGISTER_FRAME, |
| 9756 | .doit = nl80211_register_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9757 | .policy = nl80211_policy, |
| 9758 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9759 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9760 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9761 | }, |
| 9762 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9763 | .cmd = NL80211_CMD_FRAME, |
| 9764 | .doit = nl80211_tx_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9765 | .policy = nl80211_policy, |
| 9766 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9767 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9768 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9769 | }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9770 | { |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 9771 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, |
| 9772 | .doit = nl80211_tx_mgmt_cancel_wait, |
| 9773 | .policy = nl80211_policy, |
| 9774 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9775 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 9776 | NL80211_FLAG_NEED_RTNL, |
| 9777 | }, |
| 9778 | { |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9779 | .cmd = NL80211_CMD_SET_POWER_SAVE, |
| 9780 | .doit = nl80211_set_power_save, |
| 9781 | .policy = nl80211_policy, |
| 9782 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9783 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9784 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9785 | }, |
| 9786 | { |
| 9787 | .cmd = NL80211_CMD_GET_POWER_SAVE, |
| 9788 | .doit = nl80211_get_power_save, |
| 9789 | .policy = nl80211_policy, |
| 9790 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9791 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9792 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9793 | }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9794 | { |
| 9795 | .cmd = NL80211_CMD_SET_CQM, |
| 9796 | .doit = nl80211_set_cqm, |
| 9797 | .policy = nl80211_policy, |
| 9798 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9799 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9800 | NL80211_FLAG_NEED_RTNL, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9801 | }, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 9802 | { |
| 9803 | .cmd = NL80211_CMD_SET_CHANNEL, |
| 9804 | .doit = nl80211_set_channel, |
| 9805 | .policy = nl80211_policy, |
| 9806 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9807 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9808 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 9809 | }, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 9810 | { |
| 9811 | .cmd = NL80211_CMD_SET_WDS_PEER, |
| 9812 | .doit = nl80211_set_wds_peer, |
| 9813 | .policy = nl80211_policy, |
| 9814 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 9815 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9816 | NL80211_FLAG_NEED_RTNL, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 9817 | }, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 9818 | { |
| 9819 | .cmd = NL80211_CMD_JOIN_MESH, |
| 9820 | .doit = nl80211_join_mesh, |
| 9821 | .policy = nl80211_policy, |
| 9822 | .flags = GENL_ADMIN_PERM, |
| 9823 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9824 | NL80211_FLAG_NEED_RTNL, |
| 9825 | }, |
| 9826 | { |
| 9827 | .cmd = NL80211_CMD_LEAVE_MESH, |
| 9828 | .doit = nl80211_leave_mesh, |
| 9829 | .policy = nl80211_policy, |
| 9830 | .flags = GENL_ADMIN_PERM, |
| 9831 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9832 | NL80211_FLAG_NEED_RTNL, |
| 9833 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 9834 | #ifdef CONFIG_PM |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9835 | { |
| 9836 | .cmd = NL80211_CMD_GET_WOWLAN, |
| 9837 | .doit = nl80211_get_wowlan, |
| 9838 | .policy = nl80211_policy, |
| 9839 | /* can be retrieved by unprivileged users */ |
| 9840 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9841 | NL80211_FLAG_NEED_RTNL, |
| 9842 | }, |
| 9843 | { |
| 9844 | .cmd = NL80211_CMD_SET_WOWLAN, |
| 9845 | .doit = nl80211_set_wowlan, |
| 9846 | .policy = nl80211_policy, |
| 9847 | .flags = GENL_ADMIN_PERM, |
| 9848 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9849 | NL80211_FLAG_NEED_RTNL, |
| 9850 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 9851 | #endif |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 9852 | { |
| 9853 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, |
| 9854 | .doit = nl80211_set_rekey_data, |
| 9855 | .policy = nl80211_policy, |
| 9856 | .flags = GENL_ADMIN_PERM, |
| 9857 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9858 | NL80211_FLAG_NEED_RTNL, |
| 9859 | }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 9860 | { |
| 9861 | .cmd = NL80211_CMD_TDLS_MGMT, |
| 9862 | .doit = nl80211_tdls_mgmt, |
| 9863 | .policy = nl80211_policy, |
| 9864 | .flags = GENL_ADMIN_PERM, |
| 9865 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9866 | NL80211_FLAG_NEED_RTNL, |
| 9867 | }, |
| 9868 | { |
| 9869 | .cmd = NL80211_CMD_TDLS_OPER, |
| 9870 | .doit = nl80211_tdls_oper, |
| 9871 | .policy = nl80211_policy, |
| 9872 | .flags = GENL_ADMIN_PERM, |
| 9873 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9874 | NL80211_FLAG_NEED_RTNL, |
| 9875 | }, |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9876 | { |
| 9877 | .cmd = NL80211_CMD_UNEXPECTED_FRAME, |
| 9878 | .doit = nl80211_register_unexpected_frame, |
| 9879 | .policy = nl80211_policy, |
| 9880 | .flags = GENL_ADMIN_PERM, |
| 9881 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9882 | NL80211_FLAG_NEED_RTNL, |
| 9883 | }, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9884 | { |
| 9885 | .cmd = NL80211_CMD_PROBE_CLIENT, |
| 9886 | .doit = nl80211_probe_client, |
| 9887 | .policy = nl80211_policy, |
| 9888 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9889 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9890 | NL80211_FLAG_NEED_RTNL, |
| 9891 | }, |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9892 | { |
| 9893 | .cmd = NL80211_CMD_REGISTER_BEACONS, |
| 9894 | .doit = nl80211_register_beacons, |
| 9895 | .policy = nl80211_policy, |
| 9896 | .flags = GENL_ADMIN_PERM, |
| 9897 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9898 | NL80211_FLAG_NEED_RTNL, |
| 9899 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 9900 | { |
| 9901 | .cmd = NL80211_CMD_SET_NOACK_MAP, |
| 9902 | .doit = nl80211_set_noack_map, |
| 9903 | .policy = nl80211_policy, |
| 9904 | .flags = GENL_ADMIN_PERM, |
| 9905 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9906 | NL80211_FLAG_NEED_RTNL, |
| 9907 | }, |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9908 | { |
| 9909 | .cmd = NL80211_CMD_START_P2P_DEVICE, |
| 9910 | .doit = nl80211_start_p2p_device, |
| 9911 | .policy = nl80211_policy, |
| 9912 | .flags = GENL_ADMIN_PERM, |
| 9913 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 9914 | NL80211_FLAG_NEED_RTNL, |
| 9915 | }, |
| 9916 | { |
| 9917 | .cmd = NL80211_CMD_STOP_P2P_DEVICE, |
| 9918 | .doit = nl80211_stop_p2p_device, |
| 9919 | .policy = nl80211_policy, |
| 9920 | .flags = GENL_ADMIN_PERM, |
| 9921 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 9922 | NL80211_FLAG_NEED_RTNL, |
| 9923 | }, |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 9924 | { |
| 9925 | .cmd = NL80211_CMD_SET_MCAST_RATE, |
| 9926 | .doit = nl80211_set_mcast_rate, |
| 9927 | .policy = nl80211_policy, |
| 9928 | .flags = GENL_ADMIN_PERM, |
| 9929 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9930 | NL80211_FLAG_NEED_RTNL, |
| 9931 | }, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 9932 | { |
| 9933 | .cmd = NL80211_CMD_SET_MAC_ACL, |
| 9934 | .doit = nl80211_set_mac_acl, |
| 9935 | .policy = nl80211_policy, |
| 9936 | .flags = GENL_ADMIN_PERM, |
| 9937 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9938 | NL80211_FLAG_NEED_RTNL, |
| 9939 | }, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 9940 | { |
| 9941 | .cmd = NL80211_CMD_RADAR_DETECT, |
| 9942 | .doit = nl80211_start_radar_detection, |
| 9943 | .policy = nl80211_policy, |
| 9944 | .flags = GENL_ADMIN_PERM, |
| 9945 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9946 | NL80211_FLAG_NEED_RTNL, |
| 9947 | }, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 9948 | { |
| 9949 | .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES, |
| 9950 | .doit = nl80211_get_protocol_features, |
| 9951 | .policy = nl80211_policy, |
| 9952 | }, |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 9953 | { |
| 9954 | .cmd = NL80211_CMD_UPDATE_FT_IES, |
| 9955 | .doit = nl80211_update_ft_ies, |
| 9956 | .policy = nl80211_policy, |
| 9957 | .flags = GENL_ADMIN_PERM, |
| 9958 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9959 | NL80211_FLAG_NEED_RTNL, |
| 9960 | }, |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 9961 | { |
| 9962 | .cmd = NL80211_CMD_CRIT_PROTOCOL_START, |
| 9963 | .doit = nl80211_crit_protocol_start, |
| 9964 | .policy = nl80211_policy, |
| 9965 | .flags = GENL_ADMIN_PERM, |
| 9966 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 9967 | NL80211_FLAG_NEED_RTNL, |
| 9968 | }, |
| 9969 | { |
| 9970 | .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP, |
| 9971 | .doit = nl80211_crit_protocol_stop, |
| 9972 | .policy = nl80211_policy, |
| 9973 | .flags = GENL_ADMIN_PERM, |
| 9974 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 9975 | NL80211_FLAG_NEED_RTNL, |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 9976 | }, |
| 9977 | { |
| 9978 | .cmd = NL80211_CMD_GET_COALESCE, |
| 9979 | .doit = nl80211_get_coalesce, |
| 9980 | .policy = nl80211_policy, |
| 9981 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9982 | NL80211_FLAG_NEED_RTNL, |
| 9983 | }, |
| 9984 | { |
| 9985 | .cmd = NL80211_CMD_SET_COALESCE, |
| 9986 | .doit = nl80211_set_coalesce, |
| 9987 | .policy = nl80211_policy, |
| 9988 | .flags = GENL_ADMIN_PERM, |
| 9989 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9990 | NL80211_FLAG_NEED_RTNL, |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 9991 | }, |
| 9992 | { |
| 9993 | .cmd = NL80211_CMD_CHANNEL_SWITCH, |
| 9994 | .doit = nl80211_channel_switch, |
| 9995 | .policy = nl80211_policy, |
| 9996 | .flags = GENL_ADMIN_PERM, |
| 9997 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9998 | NL80211_FLAG_NEED_RTNL, |
| 9999 | }, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 10000 | { |
| 10001 | .cmd = NL80211_CMD_VENDOR, |
| 10002 | .doit = nl80211_vendor_cmd, |
| 10003 | .policy = nl80211_policy, |
| 10004 | .flags = GENL_ADMIN_PERM, |
| 10005 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 10006 | NL80211_FLAG_NEED_RTNL, |
| 10007 | }, |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 10008 | { |
| 10009 | .cmd = NL80211_CMD_SET_QOS_MAP, |
| 10010 | .doit = nl80211_set_qos_map, |
| 10011 | .policy = nl80211_policy, |
| 10012 | .flags = GENL_ADMIN_PERM, |
| 10013 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10014 | NL80211_FLAG_NEED_RTNL, |
| 10015 | }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10016 | }; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10017 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10018 | /* notification functions */ |
| 10019 | |
| 10020 | void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev) |
| 10021 | { |
| 10022 | struct sk_buff *msg; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 10023 | struct nl80211_dump_wiphy_state state = {}; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10024 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 10025 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10026 | if (!msg) |
| 10027 | return; |
| 10028 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 10029 | if (nl80211_send_wiphy(rdev, msg, 0, 0, 0, &state) < 0) { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10030 | nlmsg_free(msg); |
| 10031 | return; |
| 10032 | } |
| 10033 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10034 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10035 | NL80211_MCGRP_CONFIG, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10036 | } |
| 10037 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 10038 | static int nl80211_add_scan_req(struct sk_buff *msg, |
| 10039 | struct cfg80211_registered_device *rdev) |
| 10040 | { |
| 10041 | struct cfg80211_scan_request *req = rdev->scan_req; |
| 10042 | struct nlattr *nest; |
| 10043 | int i; |
| 10044 | |
| 10045 | if (WARN_ON(!req)) |
| 10046 | return 0; |
| 10047 | |
| 10048 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); |
| 10049 | if (!nest) |
| 10050 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10051 | for (i = 0; i < req->n_ssids; i++) { |
| 10052 | if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) |
| 10053 | goto nla_put_failure; |
| 10054 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 10055 | nla_nest_end(msg, nest); |
| 10056 | |
| 10057 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 10058 | if (!nest) |
| 10059 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10060 | for (i = 0; i < req->n_channels; i++) { |
| 10061 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) |
| 10062 | goto nla_put_failure; |
| 10063 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 10064 | nla_nest_end(msg, nest); |
| 10065 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10066 | if (req->ie && |
| 10067 | nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie)) |
| 10068 | goto nla_put_failure; |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 10069 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 10070 | if (req->flags && |
| 10071 | nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags)) |
| 10072 | goto nla_put_failure; |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 10073 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 10074 | return 0; |
| 10075 | nla_put_failure: |
| 10076 | return -ENOBUFS; |
| 10077 | } |
| 10078 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 10079 | static int nl80211_send_scan_msg(struct sk_buff *msg, |
| 10080 | struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 10081 | struct wireless_dev *wdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10082 | u32 portid, u32 seq, int flags, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 10083 | u32 cmd) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10084 | { |
| 10085 | void *hdr; |
| 10086 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10087 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10088 | if (!hdr) |
| 10089 | return -1; |
| 10090 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10091 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 10092 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 10093 | wdev->netdev->ifindex)) || |
| 10094 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10095 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10096 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 10097 | /* ignore errors and send incomplete event anyway */ |
| 10098 | nl80211_add_scan_req(msg, rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10099 | |
| 10100 | return genlmsg_end(msg, hdr); |
| 10101 | |
| 10102 | nla_put_failure: |
| 10103 | genlmsg_cancel(msg, hdr); |
| 10104 | return -EMSGSIZE; |
| 10105 | } |
| 10106 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 10107 | static int |
| 10108 | nl80211_send_sched_scan_msg(struct sk_buff *msg, |
| 10109 | struct cfg80211_registered_device *rdev, |
| 10110 | struct net_device *netdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10111 | u32 portid, u32 seq, int flags, u32 cmd) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 10112 | { |
| 10113 | void *hdr; |
| 10114 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10115 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 10116 | if (!hdr) |
| 10117 | return -1; |
| 10118 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10119 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10120 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 10121 | goto nla_put_failure; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 10122 | |
| 10123 | return genlmsg_end(msg, hdr); |
| 10124 | |
| 10125 | nla_put_failure: |
| 10126 | genlmsg_cancel(msg, hdr); |
| 10127 | return -EMSGSIZE; |
| 10128 | } |
| 10129 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 10130 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 10131 | struct wireless_dev *wdev) |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 10132 | { |
| 10133 | struct sk_buff *msg; |
| 10134 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10135 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 10136 | if (!msg) |
| 10137 | return; |
| 10138 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 10139 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 10140 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
| 10141 | nlmsg_free(msg); |
| 10142 | return; |
| 10143 | } |
| 10144 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10145 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10146 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 10147 | } |
| 10148 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 10149 | struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev, |
| 10150 | struct wireless_dev *wdev, bool aborted) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10151 | { |
| 10152 | struct sk_buff *msg; |
| 10153 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 10154 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10155 | if (!msg) |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 10156 | return NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10157 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 10158 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 10159 | aborted ? NL80211_CMD_SCAN_ABORTED : |
| 10160 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10161 | nlmsg_free(msg); |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 10162 | return NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10163 | } |
| 10164 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 10165 | return msg; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10166 | } |
| 10167 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 10168 | void nl80211_send_scan_result(struct cfg80211_registered_device *rdev, |
| 10169 | struct sk_buff *msg) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10170 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10171 | if (!msg) |
| 10172 | return; |
| 10173 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10174 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10175 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10176 | } |
| 10177 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 10178 | void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev, |
| 10179 | struct net_device *netdev) |
| 10180 | { |
| 10181 | struct sk_buff *msg; |
| 10182 | |
| 10183 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 10184 | if (!msg) |
| 10185 | return; |
| 10186 | |
| 10187 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 10188 | NL80211_CMD_SCHED_SCAN_RESULTS) < 0) { |
| 10189 | nlmsg_free(msg); |
| 10190 | return; |
| 10191 | } |
| 10192 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10193 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10194 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 10195 | } |
| 10196 | |
| 10197 | void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev, |
| 10198 | struct net_device *netdev, u32 cmd) |
| 10199 | { |
| 10200 | struct sk_buff *msg; |
| 10201 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10202 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 10203 | if (!msg) |
| 10204 | return; |
| 10205 | |
| 10206 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) { |
| 10207 | nlmsg_free(msg); |
| 10208 | return; |
| 10209 | } |
| 10210 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10211 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10212 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 10213 | } |
| 10214 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 10215 | /* |
| 10216 | * This can happen on global regulatory changes or device specific settings |
| 10217 | * based on custom world regulatory domains. |
| 10218 | */ |
| 10219 | void nl80211_send_reg_change_event(struct regulatory_request *request) |
| 10220 | { |
| 10221 | struct sk_buff *msg; |
| 10222 | void *hdr; |
| 10223 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 10224 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 10225 | if (!msg) |
| 10226 | return; |
| 10227 | |
| 10228 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE); |
| 10229 | if (!hdr) { |
| 10230 | nlmsg_free(msg); |
| 10231 | return; |
| 10232 | } |
| 10233 | |
| 10234 | /* Userspace can always count this one always being set */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10235 | if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator)) |
| 10236 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 10237 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10238 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') { |
| 10239 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 10240 | NL80211_REGDOM_TYPE_WORLD)) |
| 10241 | goto nla_put_failure; |
| 10242 | } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') { |
| 10243 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 10244 | NL80211_REGDOM_TYPE_CUSTOM_WORLD)) |
| 10245 | goto nla_put_failure; |
| 10246 | } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || |
| 10247 | request->intersect) { |
| 10248 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 10249 | NL80211_REGDOM_TYPE_INTERSECTION)) |
| 10250 | goto nla_put_failure; |
| 10251 | } else { |
| 10252 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 10253 | NL80211_REGDOM_TYPE_COUNTRY) || |
| 10254 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, |
| 10255 | request->alpha2)) |
| 10256 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 10257 | } |
| 10258 | |
Johannes Berg | f417376 | 2012-12-03 18:23:37 +0100 | [diff] [blame] | 10259 | if (request->wiphy_idx != WIPHY_IDX_INVALID && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10260 | nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) |
| 10261 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 10262 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10263 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 10264 | |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 10265 | rcu_read_lock(); |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10266 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10267 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 10268 | rcu_read_unlock(); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 10269 | |
| 10270 | return; |
| 10271 | |
| 10272 | nla_put_failure: |
| 10273 | genlmsg_cancel(msg, hdr); |
| 10274 | nlmsg_free(msg); |
| 10275 | } |
| 10276 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10277 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
| 10278 | struct net_device *netdev, |
| 10279 | const u8 *buf, size_t len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10280 | enum nl80211_commands cmd, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10281 | { |
| 10282 | struct sk_buff *msg; |
| 10283 | void *hdr; |
| 10284 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10285 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10286 | if (!msg) |
| 10287 | return; |
| 10288 | |
| 10289 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 10290 | if (!hdr) { |
| 10291 | nlmsg_free(msg); |
| 10292 | return; |
| 10293 | } |
| 10294 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10295 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10296 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10297 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) |
| 10298 | goto nla_put_failure; |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10299 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10300 | genlmsg_end(msg, hdr); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10301 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10302 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10303 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10304 | return; |
| 10305 | |
| 10306 | nla_put_failure: |
| 10307 | genlmsg_cancel(msg, hdr); |
| 10308 | nlmsg_free(msg); |
| 10309 | } |
| 10310 | |
| 10311 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10312 | struct net_device *netdev, const u8 *buf, |
| 10313 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10314 | { |
| 10315 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10316 | NL80211_CMD_AUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10317 | } |
| 10318 | |
| 10319 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, |
| 10320 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10321 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10322 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10323 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 10324 | NL80211_CMD_ASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10325 | } |
| 10326 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 10327 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10328 | struct net_device *netdev, const u8 *buf, |
| 10329 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10330 | { |
| 10331 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10332 | NL80211_CMD_DEAUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10333 | } |
| 10334 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 10335 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
| 10336 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10337 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10338 | { |
| 10339 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10340 | NL80211_CMD_DISASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10341 | } |
| 10342 | |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 10343 | void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf, |
| 10344 | size_t len) |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 10345 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10346 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10347 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 10348 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 10349 | const struct ieee80211_mgmt *mgmt = (void *)buf; |
| 10350 | u32 cmd; |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 10351 | |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 10352 | if (WARN_ON(len < 2)) |
| 10353 | return; |
| 10354 | |
| 10355 | if (ieee80211_is_deauth(mgmt->frame_control)) |
| 10356 | cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE; |
| 10357 | else |
| 10358 | cmd = NL80211_CMD_UNPROT_DISASSOCIATE; |
| 10359 | |
| 10360 | trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len); |
| 10361 | nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC); |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 10362 | } |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 10363 | EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt); |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 10364 | |
Luis R. Rodriguez | 1b06bb4 | 2009-05-02 00:34:48 -0400 | [diff] [blame] | 10365 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
| 10366 | struct net_device *netdev, int cmd, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10367 | const u8 *addr, gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10368 | { |
| 10369 | struct sk_buff *msg; |
| 10370 | void *hdr; |
| 10371 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10372 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10373 | if (!msg) |
| 10374 | return; |
| 10375 | |
| 10376 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 10377 | if (!hdr) { |
| 10378 | nlmsg_free(msg); |
| 10379 | return; |
| 10380 | } |
| 10381 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10382 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10383 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10384 | nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || |
| 10385 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 10386 | goto nla_put_failure; |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10387 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10388 | genlmsg_end(msg, hdr); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10389 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10390 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10391 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10392 | return; |
| 10393 | |
| 10394 | nla_put_failure: |
| 10395 | genlmsg_cancel(msg, hdr); |
| 10396 | nlmsg_free(msg); |
| 10397 | } |
| 10398 | |
| 10399 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10400 | struct net_device *netdev, const u8 *addr, |
| 10401 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10402 | { |
| 10403 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10404 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10405 | } |
| 10406 | |
| 10407 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10408 | struct net_device *netdev, const u8 *addr, |
| 10409 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10410 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10411 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
| 10412 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10413 | } |
| 10414 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10415 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
| 10416 | struct net_device *netdev, const u8 *bssid, |
| 10417 | const u8 *req_ie, size_t req_ie_len, |
| 10418 | const u8 *resp_ie, size_t resp_ie_len, |
| 10419 | u16 status, gfp_t gfp) |
| 10420 | { |
| 10421 | struct sk_buff *msg; |
| 10422 | void *hdr; |
| 10423 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10424 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10425 | if (!msg) |
| 10426 | return; |
| 10427 | |
| 10428 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); |
| 10429 | if (!hdr) { |
| 10430 | nlmsg_free(msg); |
| 10431 | return; |
| 10432 | } |
| 10433 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10434 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10435 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10436 | (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) || |
| 10437 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) || |
| 10438 | (req_ie && |
| 10439 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 10440 | (resp_ie && |
| 10441 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 10442 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10443 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10444 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10445 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10446 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10447 | NL80211_MCGRP_MLME, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10448 | return; |
| 10449 | |
| 10450 | nla_put_failure: |
| 10451 | genlmsg_cancel(msg, hdr); |
| 10452 | nlmsg_free(msg); |
| 10453 | |
| 10454 | } |
| 10455 | |
| 10456 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, |
| 10457 | struct net_device *netdev, const u8 *bssid, |
| 10458 | const u8 *req_ie, size_t req_ie_len, |
| 10459 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) |
| 10460 | { |
| 10461 | struct sk_buff *msg; |
| 10462 | void *hdr; |
| 10463 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10464 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10465 | if (!msg) |
| 10466 | return; |
| 10467 | |
| 10468 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); |
| 10469 | if (!hdr) { |
| 10470 | nlmsg_free(msg); |
| 10471 | return; |
| 10472 | } |
| 10473 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10474 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10475 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10476 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) || |
| 10477 | (req_ie && |
| 10478 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 10479 | (resp_ie && |
| 10480 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 10481 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10482 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10483 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10484 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10485 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10486 | NL80211_MCGRP_MLME, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10487 | return; |
| 10488 | |
| 10489 | nla_put_failure: |
| 10490 | genlmsg_cancel(msg, hdr); |
| 10491 | nlmsg_free(msg); |
| 10492 | |
| 10493 | } |
| 10494 | |
| 10495 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, |
| 10496 | struct net_device *netdev, u16 reason, |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 10497 | const u8 *ie, size_t ie_len, bool from_ap) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10498 | { |
| 10499 | struct sk_buff *msg; |
| 10500 | void *hdr; |
| 10501 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10502 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10503 | if (!msg) |
| 10504 | return; |
| 10505 | |
| 10506 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); |
| 10507 | if (!hdr) { |
| 10508 | nlmsg_free(msg); |
| 10509 | return; |
| 10510 | } |
| 10511 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10512 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10513 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10514 | (from_ap && reason && |
| 10515 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) || |
| 10516 | (from_ap && |
| 10517 | nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) || |
| 10518 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) |
| 10519 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10520 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10521 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10522 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10523 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10524 | NL80211_MCGRP_MLME, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10525 | return; |
| 10526 | |
| 10527 | nla_put_failure: |
| 10528 | genlmsg_cancel(msg, hdr); |
| 10529 | nlmsg_free(msg); |
| 10530 | |
| 10531 | } |
| 10532 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10533 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
| 10534 | struct net_device *netdev, const u8 *bssid, |
| 10535 | gfp_t gfp) |
| 10536 | { |
| 10537 | struct sk_buff *msg; |
| 10538 | void *hdr; |
| 10539 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 10540 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10541 | if (!msg) |
| 10542 | return; |
| 10543 | |
| 10544 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); |
| 10545 | if (!hdr) { |
| 10546 | nlmsg_free(msg); |
| 10547 | return; |
| 10548 | } |
| 10549 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10550 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10551 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10552 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 10553 | goto nla_put_failure; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10554 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10555 | genlmsg_end(msg, hdr); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10556 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10557 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10558 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10559 | return; |
| 10560 | |
| 10561 | nla_put_failure: |
| 10562 | genlmsg_cancel(msg, hdr); |
| 10563 | nlmsg_free(msg); |
| 10564 | } |
| 10565 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10566 | void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr, |
| 10567 | const u8* ie, u8 ie_len, gfp_t gfp) |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10568 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10569 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 10570 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10571 | struct sk_buff *msg; |
| 10572 | void *hdr; |
| 10573 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10574 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT)) |
| 10575 | return; |
| 10576 | |
| 10577 | trace_cfg80211_notify_new_peer_candidate(dev, addr); |
| 10578 | |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10579 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 10580 | if (!msg) |
| 10581 | return; |
| 10582 | |
| 10583 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); |
| 10584 | if (!hdr) { |
| 10585 | nlmsg_free(msg); |
| 10586 | return; |
| 10587 | } |
| 10588 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10589 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10590 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 10591 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10592 | (ie_len && ie && |
| 10593 | nla_put(msg, NL80211_ATTR_IE, ie_len , ie))) |
| 10594 | goto nla_put_failure; |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10595 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10596 | genlmsg_end(msg, hdr); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10597 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10598 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10599 | NL80211_MCGRP_MLME, gfp); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10600 | return; |
| 10601 | |
| 10602 | nla_put_failure: |
| 10603 | genlmsg_cancel(msg, hdr); |
| 10604 | nlmsg_free(msg); |
| 10605 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10606 | EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10607 | |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 10608 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
| 10609 | struct net_device *netdev, const u8 *addr, |
| 10610 | enum nl80211_key_type key_type, int key_id, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10611 | const u8 *tsc, gfp_t gfp) |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 10612 | { |
| 10613 | struct sk_buff *msg; |
| 10614 | void *hdr; |
| 10615 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10616 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 10617 | if (!msg) |
| 10618 | return; |
| 10619 | |
| 10620 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); |
| 10621 | if (!hdr) { |
| 10622 | nlmsg_free(msg); |
| 10623 | return; |
| 10624 | } |
| 10625 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10626 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10627 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10628 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
| 10629 | nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) || |
| 10630 | (key_id != -1 && |
| 10631 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) || |
| 10632 | (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc))) |
| 10633 | goto nla_put_failure; |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 10634 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10635 | genlmsg_end(msg, hdr); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 10636 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10637 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10638 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 10639 | return; |
| 10640 | |
| 10641 | nla_put_failure: |
| 10642 | genlmsg_cancel(msg, hdr); |
| 10643 | nlmsg_free(msg); |
| 10644 | } |
| 10645 | |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10646 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
| 10647 | struct ieee80211_channel *channel_before, |
| 10648 | struct ieee80211_channel *channel_after) |
| 10649 | { |
| 10650 | struct sk_buff *msg; |
| 10651 | void *hdr; |
| 10652 | struct nlattr *nl_freq; |
| 10653 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 10654 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10655 | if (!msg) |
| 10656 | return; |
| 10657 | |
| 10658 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); |
| 10659 | if (!hdr) { |
| 10660 | nlmsg_free(msg); |
| 10661 | return; |
| 10662 | } |
| 10663 | |
| 10664 | /* |
| 10665 | * Since we are applying the beacon hint to a wiphy we know its |
| 10666 | * wiphy_idx is valid |
| 10667 | */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10668 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 10669 | goto nla_put_failure; |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10670 | |
| 10671 | /* Before */ |
| 10672 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); |
| 10673 | if (!nl_freq) |
| 10674 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 10675 | if (nl80211_msg_put_channel(msg, channel_before, false)) |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10676 | goto nla_put_failure; |
| 10677 | nla_nest_end(msg, nl_freq); |
| 10678 | |
| 10679 | /* After */ |
| 10680 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); |
| 10681 | if (!nl_freq) |
| 10682 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 10683 | if (nl80211_msg_put_channel(msg, channel_after, false)) |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10684 | goto nla_put_failure; |
| 10685 | nla_nest_end(msg, nl_freq); |
| 10686 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10687 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10688 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 10689 | rcu_read_lock(); |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10690 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10691 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 10692 | rcu_read_unlock(); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10693 | |
| 10694 | return; |
| 10695 | |
| 10696 | nla_put_failure: |
| 10697 | genlmsg_cancel(msg, hdr); |
| 10698 | nlmsg_free(msg); |
| 10699 | } |
| 10700 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10701 | static void nl80211_send_remain_on_chan_event( |
| 10702 | int cmd, struct cfg80211_registered_device *rdev, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10703 | struct wireless_dev *wdev, u64 cookie, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10704 | struct ieee80211_channel *chan, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10705 | unsigned int duration, gfp_t gfp) |
| 10706 | { |
| 10707 | struct sk_buff *msg; |
| 10708 | void *hdr; |
| 10709 | |
| 10710 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 10711 | if (!msg) |
| 10712 | return; |
| 10713 | |
| 10714 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 10715 | if (!hdr) { |
| 10716 | nlmsg_free(msg); |
| 10717 | return; |
| 10718 | } |
| 10719 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10720 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10721 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 10722 | wdev->netdev->ifindex)) || |
Johannes Berg | 00f5335 | 2012-07-17 11:53:12 +0200 | [diff] [blame] | 10723 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10724 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) || |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 10725 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 10726 | NL80211_CHAN_NO_HT) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10727 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 10728 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10729 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10730 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL && |
| 10731 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) |
| 10732 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10733 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10734 | genlmsg_end(msg, hdr); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10735 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10736 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10737 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10738 | return; |
| 10739 | |
| 10740 | nla_put_failure: |
| 10741 | genlmsg_cancel(msg, hdr); |
| 10742 | nlmsg_free(msg); |
| 10743 | } |
| 10744 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10745 | void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie, |
| 10746 | struct ieee80211_channel *chan, |
| 10747 | unsigned int duration, gfp_t gfp) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10748 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10749 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 10750 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10751 | |
| 10752 | trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10753 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10754 | rdev, wdev, cookie, chan, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 10755 | duration, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10756 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10757 | EXPORT_SYMBOL(cfg80211_ready_on_channel); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10758 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10759 | void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie, |
| 10760 | struct ieee80211_channel *chan, |
| 10761 | gfp_t gfp) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10762 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10763 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 10764 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10765 | |
| 10766 | trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10767 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 10768 | rdev, wdev, cookie, chan, 0, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10769 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10770 | EXPORT_SYMBOL(cfg80211_remain_on_channel_expired); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10771 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10772 | void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr, |
| 10773 | struct station_info *sinfo, gfp_t gfp) |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 10774 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10775 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 10776 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 10777 | struct sk_buff *msg; |
| 10778 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10779 | trace_cfg80211_new_sta(dev, mac_addr, sinfo); |
| 10780 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10781 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 10782 | if (!msg) |
| 10783 | return; |
| 10784 | |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 10785 | if (nl80211_send_station(msg, 0, 0, 0, |
| 10786 | rdev, dev, mac_addr, sinfo) < 0) { |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 10787 | nlmsg_free(msg); |
| 10788 | return; |
| 10789 | } |
| 10790 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10791 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10792 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 10793 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10794 | EXPORT_SYMBOL(cfg80211_new_sta); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 10795 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10796 | 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] | 10797 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10798 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 10799 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 10800 | struct sk_buff *msg; |
| 10801 | void *hdr; |
| 10802 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10803 | trace_cfg80211_del_sta(dev, mac_addr); |
| 10804 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10805 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 10806 | if (!msg) |
| 10807 | return; |
| 10808 | |
| 10809 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION); |
| 10810 | if (!hdr) { |
| 10811 | nlmsg_free(msg); |
| 10812 | return; |
| 10813 | } |
| 10814 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10815 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 10816 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 10817 | goto nla_put_failure; |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 10818 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10819 | genlmsg_end(msg, hdr); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 10820 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10821 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10822 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 10823 | return; |
| 10824 | |
| 10825 | nla_put_failure: |
| 10826 | genlmsg_cancel(msg, hdr); |
| 10827 | nlmsg_free(msg); |
| 10828 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10829 | EXPORT_SYMBOL(cfg80211_del_sta); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 10830 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10831 | void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr, |
| 10832 | enum nl80211_connect_failed_reason reason, |
| 10833 | gfp_t gfp) |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 10834 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10835 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 10836 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 10837 | struct sk_buff *msg; |
| 10838 | void *hdr; |
| 10839 | |
| 10840 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 10841 | if (!msg) |
| 10842 | return; |
| 10843 | |
| 10844 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED); |
| 10845 | if (!hdr) { |
| 10846 | nlmsg_free(msg); |
| 10847 | return; |
| 10848 | } |
| 10849 | |
| 10850 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 10851 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 10852 | nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason)) |
| 10853 | goto nla_put_failure; |
| 10854 | |
| 10855 | genlmsg_end(msg, hdr); |
| 10856 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10857 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10858 | NL80211_MCGRP_MLME, gfp); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 10859 | return; |
| 10860 | |
| 10861 | nla_put_failure: |
| 10862 | genlmsg_cancel(msg, hdr); |
| 10863 | nlmsg_free(msg); |
| 10864 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10865 | EXPORT_SYMBOL(cfg80211_conn_failed); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 10866 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 10867 | static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, |
| 10868 | const u8 *addr, gfp_t gfp) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10869 | { |
| 10870 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 10871 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10872 | struct sk_buff *msg; |
| 10873 | void *hdr; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10874 | u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10875 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10876 | if (!nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10877 | return false; |
| 10878 | |
| 10879 | msg = nlmsg_new(100, gfp); |
| 10880 | if (!msg) |
| 10881 | return true; |
| 10882 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 10883 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10884 | if (!hdr) { |
| 10885 | nlmsg_free(msg); |
| 10886 | return true; |
| 10887 | } |
| 10888 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10889 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10890 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 10891 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 10892 | goto nla_put_failure; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10893 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 10894 | genlmsg_end(msg, hdr); |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10895 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10896 | return true; |
| 10897 | |
| 10898 | nla_put_failure: |
| 10899 | genlmsg_cancel(msg, hdr); |
| 10900 | nlmsg_free(msg); |
| 10901 | return true; |
| 10902 | } |
| 10903 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10904 | bool cfg80211_rx_spurious_frame(struct net_device *dev, |
| 10905 | const u8 *addr, gfp_t gfp) |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 10906 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10907 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10908 | bool ret; |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 10909 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10910 | trace_cfg80211_rx_spurious_frame(dev, addr); |
| 10911 | |
| 10912 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 10913 | wdev->iftype != NL80211_IFTYPE_P2P_GO)) { |
| 10914 | trace_cfg80211_return_bool(false); |
| 10915 | return false; |
| 10916 | } |
| 10917 | ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, |
| 10918 | addr, gfp); |
| 10919 | trace_cfg80211_return_bool(ret); |
| 10920 | return ret; |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 10921 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10922 | EXPORT_SYMBOL(cfg80211_rx_spurious_frame); |
| 10923 | |
| 10924 | bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev, |
| 10925 | const u8 *addr, gfp_t gfp) |
| 10926 | { |
| 10927 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10928 | bool ret; |
| 10929 | |
| 10930 | trace_cfg80211_rx_unexpected_4addr_frame(dev, addr); |
| 10931 | |
| 10932 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 10933 | wdev->iftype != NL80211_IFTYPE_P2P_GO && |
| 10934 | wdev->iftype != NL80211_IFTYPE_AP_VLAN)) { |
| 10935 | trace_cfg80211_return_bool(false); |
| 10936 | return false; |
| 10937 | } |
| 10938 | ret = __nl80211_unexpected_frame(dev, |
| 10939 | NL80211_CMD_UNEXPECTED_4ADDR_FRAME, |
| 10940 | addr, gfp); |
| 10941 | trace_cfg80211_return_bool(ret); |
| 10942 | return ret; |
| 10943 | } |
| 10944 | EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame); |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 10945 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 10946 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10947 | struct wireless_dev *wdev, u32 nlportid, |
Johannes Berg | 804483e | 2012-03-05 22:18:41 +0100 | [diff] [blame] | 10948 | int freq, int sig_dbm, |
Vladimir Kondratiev | 19504cf | 2013-08-15 14:51:28 +0300 | [diff] [blame] | 10949 | const u8 *buf, size_t len, u32 flags, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10950 | { |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10951 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10952 | struct sk_buff *msg; |
| 10953 | void *hdr; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10954 | |
| 10955 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 10956 | if (!msg) |
| 10957 | return -ENOMEM; |
| 10958 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 10959 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10960 | if (!hdr) { |
| 10961 | nlmsg_free(msg); |
| 10962 | return -ENOMEM; |
| 10963 | } |
| 10964 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10965 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10966 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 10967 | netdev->ifindex)) || |
Ilan Peer | a838490 | 2013-05-08 16:35:55 +0300 | [diff] [blame] | 10968 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10969 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
| 10970 | (sig_dbm && |
| 10971 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
Vladimir Kondratiev | 19504cf | 2013-08-15 14:51:28 +0300 | [diff] [blame] | 10972 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
| 10973 | (flags && |
| 10974 | nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10975 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10976 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10977 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10978 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10979 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10980 | |
| 10981 | nla_put_failure: |
| 10982 | genlmsg_cancel(msg, hdr); |
| 10983 | nlmsg_free(msg); |
| 10984 | return -ENOBUFS; |
| 10985 | } |
| 10986 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10987 | void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie, |
| 10988 | const u8 *buf, size_t len, bool ack, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10989 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10990 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 10991 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10992 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10993 | struct sk_buff *msg; |
| 10994 | void *hdr; |
| 10995 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10996 | trace_cfg80211_mgmt_tx_status(wdev, cookie, ack); |
| 10997 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10998 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 10999 | if (!msg) |
| 11000 | return; |
| 11001 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 11002 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11003 | if (!hdr) { |
| 11004 | nlmsg_free(msg); |
| 11005 | return; |
| 11006 | } |
| 11007 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11008 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11009 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 11010 | netdev->ifindex)) || |
Ilan Peer | a838490 | 2013-05-08 16:35:55 +0300 | [diff] [blame] | 11011 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11012 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
| 11013 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || |
| 11014 | (ack && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 11015 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11016 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11017 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11018 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11019 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11020 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11021 | return; |
| 11022 | |
| 11023 | nla_put_failure: |
| 11024 | genlmsg_cancel(msg, hdr); |
| 11025 | nlmsg_free(msg); |
| 11026 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11027 | EXPORT_SYMBOL(cfg80211_mgmt_tx_status); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11028 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11029 | void cfg80211_cqm_rssi_notify(struct net_device *dev, |
| 11030 | enum nl80211_cqm_rssi_threshold_event rssi_event, |
| 11031 | gfp_t gfp) |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11032 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11033 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11034 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11035 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11036 | struct sk_buff *msg; |
| 11037 | struct nlattr *pinfoattr; |
| 11038 | void *hdr; |
| 11039 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11040 | trace_cfg80211_cqm_rssi_notify(dev, rssi_event); |
| 11041 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11042 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11043 | if (!msg) |
| 11044 | return; |
| 11045 | |
| 11046 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 11047 | if (!hdr) { |
| 11048 | nlmsg_free(msg); |
| 11049 | return; |
| 11050 | } |
| 11051 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11052 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11053 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11054 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11055 | |
| 11056 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 11057 | if (!pinfoattr) |
| 11058 | goto nla_put_failure; |
| 11059 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11060 | if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, |
| 11061 | rssi_event)) |
| 11062 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11063 | |
| 11064 | nla_nest_end(msg, pinfoattr); |
| 11065 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11066 | genlmsg_end(msg, hdr); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11067 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11068 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11069 | NL80211_MCGRP_MLME, gfp); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11070 | return; |
| 11071 | |
| 11072 | nla_put_failure: |
| 11073 | genlmsg_cancel(msg, hdr); |
| 11074 | nlmsg_free(msg); |
| 11075 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11076 | EXPORT_SYMBOL(cfg80211_cqm_rssi_notify); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11077 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11078 | static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
| 11079 | struct net_device *netdev, const u8 *bssid, |
| 11080 | const u8 *replay_ctr, gfp_t gfp) |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 11081 | { |
| 11082 | struct sk_buff *msg; |
| 11083 | struct nlattr *rekey_attr; |
| 11084 | void *hdr; |
| 11085 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11086 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 11087 | if (!msg) |
| 11088 | return; |
| 11089 | |
| 11090 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); |
| 11091 | if (!hdr) { |
| 11092 | nlmsg_free(msg); |
| 11093 | return; |
| 11094 | } |
| 11095 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11096 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11097 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 11098 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 11099 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 11100 | |
| 11101 | rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); |
| 11102 | if (!rekey_attr) |
| 11103 | goto nla_put_failure; |
| 11104 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11105 | if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
| 11106 | NL80211_REPLAY_CTR_LEN, replay_ctr)) |
| 11107 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 11108 | |
| 11109 | nla_nest_end(msg, rekey_attr); |
| 11110 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11111 | genlmsg_end(msg, hdr); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 11112 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11113 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11114 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 11115 | return; |
| 11116 | |
| 11117 | nla_put_failure: |
| 11118 | genlmsg_cancel(msg, hdr); |
| 11119 | nlmsg_free(msg); |
| 11120 | } |
| 11121 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11122 | void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid, |
| 11123 | const u8 *replay_ctr, gfp_t gfp) |
| 11124 | { |
| 11125 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11126 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11127 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11128 | |
| 11129 | trace_cfg80211_gtk_rekey_notify(dev, bssid); |
| 11130 | nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp); |
| 11131 | } |
| 11132 | EXPORT_SYMBOL(cfg80211_gtk_rekey_notify); |
| 11133 | |
| 11134 | static void |
| 11135 | nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, |
| 11136 | struct net_device *netdev, int index, |
| 11137 | const u8 *bssid, bool preauth, gfp_t gfp) |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 11138 | { |
| 11139 | struct sk_buff *msg; |
| 11140 | struct nlattr *attr; |
| 11141 | void *hdr; |
| 11142 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11143 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 11144 | if (!msg) |
| 11145 | return; |
| 11146 | |
| 11147 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); |
| 11148 | if (!hdr) { |
| 11149 | nlmsg_free(msg); |
| 11150 | return; |
| 11151 | } |
| 11152 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11153 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11154 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 11155 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 11156 | |
| 11157 | attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE); |
| 11158 | if (!attr) |
| 11159 | goto nla_put_failure; |
| 11160 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11161 | if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) || |
| 11162 | nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) || |
| 11163 | (preauth && |
| 11164 | nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH))) |
| 11165 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 11166 | |
| 11167 | nla_nest_end(msg, attr); |
| 11168 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11169 | genlmsg_end(msg, hdr); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 11170 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11171 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11172 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 11173 | return; |
| 11174 | |
| 11175 | nla_put_failure: |
| 11176 | genlmsg_cancel(msg, hdr); |
| 11177 | nlmsg_free(msg); |
| 11178 | } |
| 11179 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11180 | void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index, |
| 11181 | const u8 *bssid, bool preauth, gfp_t gfp) |
| 11182 | { |
| 11183 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11184 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11185 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11186 | |
| 11187 | trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth); |
| 11188 | nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp); |
| 11189 | } |
| 11190 | EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify); |
| 11191 | |
| 11192 | static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev, |
| 11193 | struct net_device *netdev, |
| 11194 | struct cfg80211_chan_def *chandef, |
| 11195 | gfp_t gfp) |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 11196 | { |
| 11197 | struct sk_buff *msg; |
| 11198 | void *hdr; |
| 11199 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11200 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 11201 | if (!msg) |
| 11202 | return; |
| 11203 | |
| 11204 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY); |
| 11205 | if (!hdr) { |
| 11206 | nlmsg_free(msg); |
| 11207 | return; |
| 11208 | } |
| 11209 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 11210 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 11211 | goto nla_put_failure; |
| 11212 | |
| 11213 | if (nl80211_send_chandef(msg, chandef)) |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 11214 | goto nla_put_failure; |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 11215 | |
| 11216 | genlmsg_end(msg, hdr); |
| 11217 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11218 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11219 | NL80211_MCGRP_MLME, gfp); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 11220 | return; |
| 11221 | |
| 11222 | nla_put_failure: |
| 11223 | genlmsg_cancel(msg, hdr); |
| 11224 | nlmsg_free(msg); |
| 11225 | } |
| 11226 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11227 | void cfg80211_ch_switch_notify(struct net_device *dev, |
| 11228 | struct cfg80211_chan_def *chandef) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 11229 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11230 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11231 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11232 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11233 | |
Simon Wunderlich | e487eae | 2013-11-21 18:19:51 +0100 | [diff] [blame] | 11234 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11235 | |
Simon Wunderlich | e487eae | 2013-11-21 18:19:51 +0100 | [diff] [blame] | 11236 | trace_cfg80211_ch_switch_notify(dev, chandef); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11237 | |
| 11238 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 11239 | wdev->iftype != NL80211_IFTYPE_P2P_GO && |
Chun-Yeow Yeoh | b8456a1 | 2013-10-17 15:55:02 -0700 | [diff] [blame] | 11240 | wdev->iftype != NL80211_IFTYPE_ADHOC && |
| 11241 | wdev->iftype != NL80211_IFTYPE_MESH_POINT)) |
Simon Wunderlich | e487eae | 2013-11-21 18:19:51 +0100 | [diff] [blame] | 11242 | return; |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11243 | |
Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 11244 | wdev->chandef = *chandef; |
Janusz Dziedzic | 96f55f1 | 2014-01-24 14:29:21 +0100 | [diff] [blame] | 11245 | wdev->preset_chandef = *chandef; |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11246 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11247 | } |
| 11248 | EXPORT_SYMBOL(cfg80211_ch_switch_notify); |
| 11249 | |
| 11250 | void cfg80211_cqm_txe_notify(struct net_device *dev, |
| 11251 | const u8 *peer, u32 num_packets, |
| 11252 | u32 rate, u32 intvl, gfp_t gfp) |
| 11253 | { |
| 11254 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11255 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11256 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 11257 | struct sk_buff *msg; |
| 11258 | struct nlattr *pinfoattr; |
| 11259 | void *hdr; |
| 11260 | |
| 11261 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 11262 | if (!msg) |
| 11263 | return; |
| 11264 | |
| 11265 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 11266 | if (!hdr) { |
| 11267 | nlmsg_free(msg); |
| 11268 | return; |
| 11269 | } |
| 11270 | |
| 11271 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11272 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 11273 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
| 11274 | goto nla_put_failure; |
| 11275 | |
| 11276 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 11277 | if (!pinfoattr) |
| 11278 | goto nla_put_failure; |
| 11279 | |
| 11280 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets)) |
| 11281 | goto nla_put_failure; |
| 11282 | |
| 11283 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate)) |
| 11284 | goto nla_put_failure; |
| 11285 | |
| 11286 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl)) |
| 11287 | goto nla_put_failure; |
| 11288 | |
| 11289 | nla_nest_end(msg, pinfoattr); |
| 11290 | |
| 11291 | genlmsg_end(msg, hdr); |
| 11292 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11293 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11294 | NL80211_MCGRP_MLME, gfp); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 11295 | return; |
| 11296 | |
| 11297 | nla_put_failure: |
| 11298 | genlmsg_cancel(msg, hdr); |
| 11299 | nlmsg_free(msg); |
| 11300 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11301 | EXPORT_SYMBOL(cfg80211_cqm_txe_notify); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 11302 | |
| 11303 | void |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 11304 | nl80211_radar_notify(struct cfg80211_registered_device *rdev, |
Janusz Dziedzic | d2859df | 2013-11-06 13:55:51 +0100 | [diff] [blame] | 11305 | const struct cfg80211_chan_def *chandef, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 11306 | enum nl80211_radar_event event, |
| 11307 | struct net_device *netdev, gfp_t gfp) |
| 11308 | { |
| 11309 | struct sk_buff *msg; |
| 11310 | void *hdr; |
| 11311 | |
| 11312 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 11313 | if (!msg) |
| 11314 | return; |
| 11315 | |
| 11316 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT); |
| 11317 | if (!hdr) { |
| 11318 | nlmsg_free(msg); |
| 11319 | return; |
| 11320 | } |
| 11321 | |
| 11322 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 11323 | goto nla_put_failure; |
| 11324 | |
| 11325 | /* NOP and radar events don't need a netdev parameter */ |
| 11326 | if (netdev) { |
| 11327 | struct wireless_dev *wdev = netdev->ieee80211_ptr; |
| 11328 | |
| 11329 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 11330 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 11331 | goto nla_put_failure; |
| 11332 | } |
| 11333 | |
| 11334 | if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event)) |
| 11335 | goto nla_put_failure; |
| 11336 | |
| 11337 | if (nl80211_send_chandef(msg, chandef)) |
| 11338 | goto nla_put_failure; |
| 11339 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 11340 | genlmsg_end(msg, hdr); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 11341 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11342 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11343 | NL80211_MCGRP_MLME, gfp); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 11344 | return; |
| 11345 | |
| 11346 | nla_put_failure: |
| 11347 | genlmsg_cancel(msg, hdr); |
| 11348 | nlmsg_free(msg); |
| 11349 | } |
| 11350 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11351 | void cfg80211_cqm_pktloss_notify(struct net_device *dev, |
| 11352 | const u8 *peer, u32 num_packets, gfp_t gfp) |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 11353 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11354 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11355 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11356 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 11357 | struct sk_buff *msg; |
| 11358 | struct nlattr *pinfoattr; |
| 11359 | void *hdr; |
| 11360 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11361 | trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets); |
| 11362 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11363 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 11364 | if (!msg) |
| 11365 | return; |
| 11366 | |
| 11367 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 11368 | if (!hdr) { |
| 11369 | nlmsg_free(msg); |
| 11370 | return; |
| 11371 | } |
| 11372 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11373 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11374 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11375 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
| 11376 | goto nla_put_failure; |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 11377 | |
| 11378 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 11379 | if (!pinfoattr) |
| 11380 | goto nla_put_failure; |
| 11381 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11382 | if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets)) |
| 11383 | goto nla_put_failure; |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 11384 | |
| 11385 | nla_nest_end(msg, pinfoattr); |
| 11386 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11387 | genlmsg_end(msg, hdr); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 11388 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11389 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11390 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 11391 | return; |
| 11392 | |
| 11393 | nla_put_failure: |
| 11394 | genlmsg_cancel(msg, hdr); |
| 11395 | nlmsg_free(msg); |
| 11396 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11397 | EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 11398 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11399 | void cfg80211_probe_status(struct net_device *dev, const u8 *addr, |
| 11400 | u64 cookie, bool acked, gfp_t gfp) |
| 11401 | { |
| 11402 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11403 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11404 | struct sk_buff *msg; |
| 11405 | void *hdr; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11406 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 11407 | trace_cfg80211_probe_status(dev, addr, cookie, acked); |
| 11408 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11409 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 11410 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11411 | if (!msg) |
| 11412 | return; |
| 11413 | |
| 11414 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); |
| 11415 | if (!hdr) { |
| 11416 | nlmsg_free(msg); |
| 11417 | return; |
| 11418 | } |
| 11419 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11420 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11421 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 11422 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 11423 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || |
| 11424 | (acked && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 11425 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11426 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 11427 | genlmsg_end(msg, hdr); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11428 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11429 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11430 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11431 | return; |
| 11432 | |
| 11433 | nla_put_failure: |
| 11434 | genlmsg_cancel(msg, hdr); |
| 11435 | nlmsg_free(msg); |
| 11436 | } |
| 11437 | EXPORT_SYMBOL(cfg80211_probe_status); |
| 11438 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11439 | void cfg80211_report_obss_beacon(struct wiphy *wiphy, |
| 11440 | const u8 *frame, size_t len, |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11441 | int freq, int sig_dbm) |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11442 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11443 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11444 | struct sk_buff *msg; |
| 11445 | void *hdr; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11446 | struct cfg80211_beacon_registration *reg; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11447 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 11448 | trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm); |
| 11449 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11450 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 11451 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 11452 | msg = nlmsg_new(len + 100, GFP_ATOMIC); |
| 11453 | if (!msg) { |
| 11454 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 11455 | return; |
| 11456 | } |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11457 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11458 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
| 11459 | if (!hdr) |
| 11460 | goto nla_put_failure; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11461 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11462 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11463 | (freq && |
| 11464 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || |
| 11465 | (sig_dbm && |
| 11466 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
| 11467 | nla_put(msg, NL80211_ATTR_FRAME, len, frame)) |
| 11468 | goto nla_put_failure; |
| 11469 | |
| 11470 | genlmsg_end(msg, hdr); |
| 11471 | |
| 11472 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11473 | } |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11474 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11475 | return; |
| 11476 | |
| 11477 | nla_put_failure: |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11478 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 11479 | if (hdr) |
| 11480 | genlmsg_cancel(msg, hdr); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11481 | nlmsg_free(msg); |
| 11482 | } |
| 11483 | EXPORT_SYMBOL(cfg80211_report_obss_beacon); |
| 11484 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 11485 | #ifdef CONFIG_PM |
| 11486 | void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev, |
| 11487 | struct cfg80211_wowlan_wakeup *wakeup, |
| 11488 | gfp_t gfp) |
| 11489 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11490 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 11491 | struct sk_buff *msg; |
| 11492 | void *hdr; |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 11493 | int size = 200; |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 11494 | |
| 11495 | trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup); |
| 11496 | |
| 11497 | if (wakeup) |
| 11498 | size += wakeup->packet_present_len; |
| 11499 | |
| 11500 | msg = nlmsg_new(size, gfp); |
| 11501 | if (!msg) |
| 11502 | return; |
| 11503 | |
| 11504 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN); |
| 11505 | if (!hdr) |
| 11506 | goto free_msg; |
| 11507 | |
| 11508 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11509 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 11510 | goto free_msg; |
| 11511 | |
| 11512 | if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 11513 | wdev->netdev->ifindex)) |
| 11514 | goto free_msg; |
| 11515 | |
| 11516 | if (wakeup) { |
| 11517 | struct nlattr *reasons; |
| 11518 | |
| 11519 | reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
Johannes Berg | 7fa322c | 2013-10-25 11:16:58 +0200 | [diff] [blame] | 11520 | if (!reasons) |
| 11521 | goto free_msg; |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 11522 | |
| 11523 | if (wakeup->disconnect && |
| 11524 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) |
| 11525 | goto free_msg; |
| 11526 | if (wakeup->magic_pkt && |
| 11527 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) |
| 11528 | goto free_msg; |
| 11529 | if (wakeup->gtk_rekey_failure && |
| 11530 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) |
| 11531 | goto free_msg; |
| 11532 | if (wakeup->eap_identity_req && |
| 11533 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) |
| 11534 | goto free_msg; |
| 11535 | if (wakeup->four_way_handshake && |
| 11536 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) |
| 11537 | goto free_msg; |
| 11538 | if (wakeup->rfkill_release && |
| 11539 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)) |
| 11540 | goto free_msg; |
| 11541 | |
| 11542 | if (wakeup->pattern_idx >= 0 && |
| 11543 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 11544 | wakeup->pattern_idx)) |
| 11545 | goto free_msg; |
| 11546 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 11547 | if (wakeup->tcp_match && |
| 11548 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH)) |
| 11549 | goto free_msg; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11550 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 11551 | if (wakeup->tcp_connlost && |
| 11552 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST)) |
| 11553 | goto free_msg; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11554 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 11555 | if (wakeup->tcp_nomoretokens && |
| 11556 | nla_put_flag(msg, |
| 11557 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS)) |
| 11558 | goto free_msg; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11559 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 11560 | if (wakeup->packet) { |
| 11561 | u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211; |
| 11562 | u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN; |
| 11563 | |
| 11564 | if (!wakeup->packet_80211) { |
| 11565 | pkt_attr = |
| 11566 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023; |
| 11567 | len_attr = |
| 11568 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN; |
| 11569 | } |
| 11570 | |
| 11571 | if (wakeup->packet_len && |
| 11572 | nla_put_u32(msg, len_attr, wakeup->packet_len)) |
| 11573 | goto free_msg; |
| 11574 | |
| 11575 | if (nla_put(msg, pkt_attr, wakeup->packet_present_len, |
| 11576 | wakeup->packet)) |
| 11577 | goto free_msg; |
| 11578 | } |
| 11579 | |
| 11580 | nla_nest_end(msg, reasons); |
| 11581 | } |
| 11582 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 11583 | genlmsg_end(msg, hdr); |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 11584 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11585 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11586 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 11587 | return; |
| 11588 | |
| 11589 | free_msg: |
| 11590 | nlmsg_free(msg); |
| 11591 | } |
| 11592 | EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup); |
| 11593 | #endif |
| 11594 | |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 11595 | void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer, |
| 11596 | enum nl80211_tdls_operation oper, |
| 11597 | u16 reason_code, gfp_t gfp) |
| 11598 | { |
| 11599 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11600 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 11601 | struct sk_buff *msg; |
| 11602 | void *hdr; |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 11603 | |
| 11604 | trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper, |
| 11605 | reason_code); |
| 11606 | |
| 11607 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 11608 | if (!msg) |
| 11609 | return; |
| 11610 | |
| 11611 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER); |
| 11612 | if (!hdr) { |
| 11613 | nlmsg_free(msg); |
| 11614 | return; |
| 11615 | } |
| 11616 | |
| 11617 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11618 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 11619 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) || |
| 11620 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) || |
| 11621 | (reason_code > 0 && |
| 11622 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) |
| 11623 | goto nla_put_failure; |
| 11624 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 11625 | genlmsg_end(msg, hdr); |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 11626 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11627 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11628 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 11629 | return; |
| 11630 | |
| 11631 | nla_put_failure: |
| 11632 | genlmsg_cancel(msg, hdr); |
| 11633 | nlmsg_free(msg); |
| 11634 | } |
| 11635 | EXPORT_SYMBOL(cfg80211_tdls_oper_request); |
| 11636 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11637 | static int nl80211_netlink_notify(struct notifier_block * nb, |
| 11638 | unsigned long state, |
| 11639 | void *_notify) |
| 11640 | { |
| 11641 | struct netlink_notify *notify = _notify; |
| 11642 | struct cfg80211_registered_device *rdev; |
| 11643 | struct wireless_dev *wdev; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11644 | struct cfg80211_beacon_registration *reg, *tmp; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11645 | |
| 11646 | if (state != NETLINK_URELEASE) |
| 11647 | return NOTIFY_DONE; |
| 11648 | |
| 11649 | rcu_read_lock(); |
| 11650 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11651 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 11652 | bool schedule_destroy_work = false; |
| 11653 | |
| 11654 | list_for_each_entry_rcu(wdev, &rdev->wdev_list, list) { |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11655 | cfg80211_mlme_unregister_socket(wdev, notify->portid); |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11656 | |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 11657 | if (wdev->owner_nlportid == notify->portid) |
| 11658 | schedule_destroy_work = true; |
| 11659 | } |
| 11660 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11661 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 11662 | list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations, |
| 11663 | list) { |
| 11664 | if (reg->nlportid == notify->portid) { |
| 11665 | list_del(®->list); |
| 11666 | kfree(reg); |
| 11667 | break; |
| 11668 | } |
| 11669 | } |
| 11670 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 11671 | |
| 11672 | if (schedule_destroy_work) { |
| 11673 | struct cfg80211_iface_destroy *destroy; |
| 11674 | |
| 11675 | destroy = kzalloc(sizeof(*destroy), GFP_ATOMIC); |
| 11676 | if (destroy) { |
| 11677 | destroy->nlportid = notify->portid; |
| 11678 | spin_lock(&rdev->destroy_list_lock); |
| 11679 | list_add(&destroy->list, &rdev->destroy_list); |
| 11680 | spin_unlock(&rdev->destroy_list_lock); |
| 11681 | schedule_work(&rdev->destroy_work); |
| 11682 | } |
| 11683 | } |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11684 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11685 | |
| 11686 | rcu_read_unlock(); |
| 11687 | |
Zhao, Gang | 6784c7d | 2014-04-21 12:53:04 +0800 | [diff] [blame] | 11688 | return NOTIFY_OK; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11689 | } |
| 11690 | |
| 11691 | static struct notifier_block nl80211_netlink_notifier = { |
| 11692 | .notifier_call = nl80211_netlink_notify, |
| 11693 | }; |
| 11694 | |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 11695 | void cfg80211_ft_event(struct net_device *netdev, |
| 11696 | struct cfg80211_ft_event_params *ft_event) |
| 11697 | { |
| 11698 | struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11699 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 11700 | struct sk_buff *msg; |
| 11701 | void *hdr; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 11702 | |
| 11703 | trace_cfg80211_ft_event(wiphy, netdev, ft_event); |
| 11704 | |
| 11705 | if (!ft_event->target_ap) |
| 11706 | return; |
| 11707 | |
| 11708 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 11709 | if (!msg) |
| 11710 | return; |
| 11711 | |
| 11712 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT); |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 11713 | if (!hdr) |
| 11714 | goto out; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 11715 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 11716 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11717 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 11718 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap)) |
| 11719 | goto out; |
| 11720 | |
| 11721 | if (ft_event->ies && |
| 11722 | nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies)) |
| 11723 | goto out; |
| 11724 | if (ft_event->ric_ies && |
| 11725 | nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len, |
| 11726 | ft_event->ric_ies)) |
| 11727 | goto out; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 11728 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 11729 | genlmsg_end(msg, hdr); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 11730 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11731 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11732 | NL80211_MCGRP_MLME, GFP_KERNEL); |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 11733 | return; |
| 11734 | out: |
| 11735 | nlmsg_free(msg); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 11736 | } |
| 11737 | EXPORT_SYMBOL(cfg80211_ft_event); |
| 11738 | |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 11739 | void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp) |
| 11740 | { |
| 11741 | struct cfg80211_registered_device *rdev; |
| 11742 | struct sk_buff *msg; |
| 11743 | void *hdr; |
| 11744 | u32 nlportid; |
| 11745 | |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11746 | rdev = wiphy_to_rdev(wdev->wiphy); |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 11747 | if (!rdev->crit_proto_nlportid) |
| 11748 | return; |
| 11749 | |
| 11750 | nlportid = rdev->crit_proto_nlportid; |
| 11751 | rdev->crit_proto_nlportid = 0; |
| 11752 | |
| 11753 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 11754 | if (!msg) |
| 11755 | return; |
| 11756 | |
| 11757 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP); |
| 11758 | if (!hdr) |
| 11759 | goto nla_put_failure; |
| 11760 | |
| 11761 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11762 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 11763 | goto nla_put_failure; |
| 11764 | |
| 11765 | genlmsg_end(msg, hdr); |
| 11766 | |
| 11767 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
| 11768 | return; |
| 11769 | |
| 11770 | nla_put_failure: |
| 11771 | if (hdr) |
| 11772 | genlmsg_cancel(msg, hdr); |
| 11773 | nlmsg_free(msg); |
| 11774 | |
| 11775 | } |
| 11776 | EXPORT_SYMBOL(cfg80211_crit_proto_stopped); |
| 11777 | |
Johannes Berg | 348baf0 | 2014-01-24 14:06:29 +0100 | [diff] [blame] | 11778 | void nl80211_send_ap_stopped(struct wireless_dev *wdev) |
| 11779 | { |
| 11780 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11781 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 348baf0 | 2014-01-24 14:06:29 +0100 | [diff] [blame] | 11782 | struct sk_buff *msg; |
| 11783 | void *hdr; |
| 11784 | |
| 11785 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 11786 | if (!msg) |
| 11787 | return; |
| 11788 | |
| 11789 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP); |
| 11790 | if (!hdr) |
| 11791 | goto out; |
| 11792 | |
| 11793 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11794 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) || |
| 11795 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 11796 | goto out; |
| 11797 | |
| 11798 | genlmsg_end(msg, hdr); |
| 11799 | |
| 11800 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0, |
| 11801 | NL80211_MCGRP_MLME, GFP_KERNEL); |
| 11802 | return; |
| 11803 | out: |
| 11804 | nlmsg_free(msg); |
| 11805 | } |
| 11806 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11807 | /* initialisation/exit functions */ |
| 11808 | |
| 11809 | int nl80211_init(void) |
| 11810 | { |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 11811 | int err; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11812 | |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11813 | err = genl_register_family_with_ops_groups(&nl80211_fam, nl80211_ops, |
| 11814 | nl80211_mcgrps); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11815 | if (err) |
| 11816 | return err; |
| 11817 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11818 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
| 11819 | if (err) |
| 11820 | goto err_out; |
| 11821 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11822 | return 0; |
| 11823 | err_out: |
| 11824 | genl_unregister_family(&nl80211_fam); |
| 11825 | return err; |
| 11826 | } |
| 11827 | |
| 11828 | void nl80211_exit(void) |
| 11829 | { |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11830 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11831 | genl_unregister_family(&nl80211_fam); |
| 11832 | } |