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]); |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [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) |
| 171 | tmp = wiphy_to_dev( |
| 172 | netdev->ieee80211_ptr->wiphy); |
| 173 | else |
| 174 | tmp = NULL; |
| 175 | |
| 176 | dev_put(netdev); |
| 177 | |
| 178 | /* not wireless device -- return error */ |
| 179 | if (!tmp) |
| 180 | return ERR_PTR(-EINVAL); |
| 181 | |
| 182 | /* mismatch -- return error */ |
| 183 | if (rdev && tmp != rdev) |
| 184 | return ERR_PTR(-EINVAL); |
| 185 | |
| 186 | rdev = tmp; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 187 | } |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 188 | } |
| 189 | |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 190 | if (!rdev) |
| 191 | return ERR_PTR(-ENODEV); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 192 | |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 193 | if (netns != wiphy_net(&rdev->wiphy)) |
| 194 | return ERR_PTR(-ENODEV); |
| 195 | |
| 196 | return rdev; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | /* |
| 200 | * This function returns a pointer to the driver |
| 201 | * that the genl_info item that is passed refers to. |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 202 | * |
| 203 | * The result of this can be a PTR_ERR and hence must |
| 204 | * be checked with IS_ERR() for errors. |
| 205 | */ |
| 206 | static struct cfg80211_registered_device * |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 207 | cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info) |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 208 | { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 209 | return __cfg80211_rdev_from_attrs(netns, info->attrs); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 210 | } |
| 211 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 212 | /* policy for the attributes */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 213 | static const struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] = { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 214 | [NL80211_ATTR_WIPHY] = { .type = NLA_U32 }, |
| 215 | [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING, |
David S. Miller | 079e24e | 2009-05-26 21:15:00 -0700 | [diff] [blame] | 216 | .len = 20-1 }, |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 217 | [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED }, |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 218 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 219 | [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 }, |
Sujith | 094d05d | 2008-12-12 11:57:43 +0530 | [diff] [blame] | 220 | [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 221 | [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 }, |
| 222 | [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 }, |
| 223 | [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 }, |
| 224 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 225 | [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 }, |
| 226 | [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 }, |
| 227 | [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 }, |
| 228 | [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 }, |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 229 | [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 230 | |
| 231 | [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 }, |
| 232 | [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 }, |
| 233 | [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 234 | |
Eliad Peller | e007b85 | 2011-11-24 18:13:56 +0200 | [diff] [blame] | 235 | [NL80211_ATTR_MAC] = { .len = ETH_ALEN }, |
| 236 | [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 237 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 238 | [NL80211_ATTR_KEY] = { .type = NLA_NESTED, }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 239 | [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY, |
| 240 | .len = WLAN_MAX_KEY_LEN }, |
| 241 | [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 }, |
| 242 | [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 }, |
| 243 | [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG }, |
Jouni Malinen | 8196226 | 2011-11-02 23:36:31 +0200 | [diff] [blame] | 244 | [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 245 | [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 246 | |
| 247 | [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 }, |
| 248 | [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 }, |
| 249 | [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY, |
| 250 | .len = IEEE80211_MAX_DATA_LEN }, |
| 251 | [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY, |
| 252 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 253 | [NL80211_ATTR_STA_AID] = { .type = NLA_U16 }, |
| 254 | [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED }, |
| 255 | [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 }, |
| 256 | [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY, |
| 257 | .len = NL80211_MAX_SUPP_RATES }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 258 | [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 259 | [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 }, |
Johannes Berg | 0a9542e | 2008-10-15 11:54:04 +0200 | [diff] [blame] | 260 | [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 261 | [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 262 | .len = IEEE80211_MAX_MESH_ID_LEN }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 263 | [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 264 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 265 | [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 }, |
| 266 | [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED }, |
| 267 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 268 | [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 }, |
| 269 | [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 }, |
| 270 | [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 }, |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 271 | [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY, |
| 272 | .len = NL80211_MAX_SUPP_RATES }, |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 273 | [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 }, |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 274 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 275 | [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 276 | [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 277 | |
Johannes Berg | 6c73941 | 2011-11-03 09:27:01 +0100 | [diff] [blame] | 278 | [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 279 | |
| 280 | [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 }, |
| 281 | [NL80211_ATTR_IE] = { .type = NLA_BINARY, |
| 282 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 283 | [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED }, |
| 284 | [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 285 | |
| 286 | [NL80211_ATTR_SSID] = { .type = NLA_BINARY, |
| 287 | .len = IEEE80211_MAX_SSID_LEN }, |
| 288 | [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 }, |
| 289 | [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 290 | [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG }, |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 291 | [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG }, |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 292 | [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 }, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 293 | [NL80211_ATTR_STA_FLAGS2] = { |
| 294 | .len = sizeof(struct nl80211_sta_flag_update), |
| 295 | }, |
Jouni Malinen | 3f77316c | 2009-05-11 21:57:57 +0300 | [diff] [blame] | 296 | [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG }, |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 297 | [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 }, |
| 298 | [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG }, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 299 | [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG }, |
| 300 | [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 }, |
| 301 | [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 302 | [NL80211_ATTR_PID] = { .type = NLA_U32 }, |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 303 | [NL80211_ATTR_4ADDR] = { .type = NLA_U8 }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 304 | [NL80211_ATTR_PMKID] = { .type = NLA_BINARY, |
| 305 | .len = WLAN_PMKID_LEN }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 306 | [NL80211_ATTR_DURATION] = { .type = NLA_U32 }, |
| 307 | [NL80211_ATTR_COOKIE] = { .type = NLA_U64 }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 308 | [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 309 | [NL80211_ATTR_FRAME] = { .type = NLA_BINARY, |
| 310 | .len = IEEE80211_MAX_DATA_LEN }, |
| 311 | [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 312 | [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 313 | [NL80211_ATTR_CQM] = { .type = NLA_NESTED, }, |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 314 | [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG }, |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 315 | [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 }, |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 316 | [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 }, |
| 317 | [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 }, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 318 | [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 }, |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 319 | [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 }, |
| 320 | [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 }, |
Felix Fietkau | 885a46d | 2010-11-11 15:07:22 +0100 | [diff] [blame] | 321 | [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 }, |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 322 | [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 323 | [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 324 | [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED }, |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 325 | [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 }, |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 326 | [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 }, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 327 | [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED }, |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 328 | [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED }, |
Jouni Malinen | 32e9de8 | 2011-08-10 23:53:31 +0300 | [diff] [blame] | 329 | [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 }, |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 330 | [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY, |
| 331 | .len = IEEE80211_MAX_DATA_LEN }, |
| 332 | [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY, |
| 333 | .len = IEEE80211_MAX_DATA_LEN }, |
Vivek Natarajan | f4b34b5 | 2011-08-29 14:23:03 +0530 | [diff] [blame] | 334 | [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG }, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 335 | [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED }, |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 336 | [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 337 | [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 }, |
| 338 | [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 }, |
| 339 | [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 }, |
| 340 | [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG }, |
| 341 | [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG }, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 342 | [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG }, |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 343 | [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY, |
| 344 | .len = IEEE80211_MAX_DATA_LEN }, |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 345 | [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 }, |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 346 | [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG }, |
| 347 | [NL80211_ATTR_HT_CAPABILITY_MASK] = { |
| 348 | .len = NL80211_HT_CAPABILITY_LEN |
| 349 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 350 | [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 }, |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 351 | [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 }, |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 352 | [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 }, |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 353 | [NL80211_ATTR_WDEV] = { .type = NLA_U64 }, |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 354 | [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 }, |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 355 | [NL80211_ATTR_SAE_DATA] = { .type = NLA_BINARY, }, |
Mahesh Palivela | f461be3e | 2012-10-11 08:04:52 +0000 | [diff] [blame] | 356 | [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN }, |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 357 | [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 }, |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 358 | [NL80211_ATTR_P2P_CTWINDOW] = { .type = NLA_U8 }, |
| 359 | [NL80211_ATTR_P2P_OPPPS] = { .type = NLA_U8 }, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 360 | [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 }, |
| 361 | [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED }, |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 362 | [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 }, |
| 363 | [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, }, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 364 | [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, }, |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 365 | [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG }, |
| 366 | [NL80211_ATTR_VHT_CAPABILITY_MASK] = { |
| 367 | .len = NL80211_VHT_CAPABILITY_LEN, |
| 368 | }, |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 369 | [NL80211_ATTR_MDID] = { .type = NLA_U16 }, |
| 370 | [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY, |
| 371 | .len = IEEE80211_MAX_DATA_LEN }, |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 372 | [NL80211_ATTR_PEER_AID] = { .type = NLA_U16 }, |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 373 | [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 }, |
| 374 | [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG }, |
| 375 | [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED }, |
| 376 | [NL80211_ATTR_CSA_C_OFF_BEACON] = { .type = NLA_U16 }, |
| 377 | [NL80211_ATTR_CSA_C_OFF_PRESP] = { .type = NLA_U16 }, |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 378 | [NL80211_ATTR_STA_SUPPORTED_CHANNELS] = { .type = NLA_BINARY }, |
| 379 | [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES] = { .type = NLA_BINARY }, |
Simon Wunderlich | 5336fa8 | 2013-10-07 18:41:05 +0200 | [diff] [blame] | 380 | [NL80211_ATTR_HANDLE_DFS] = { .type = NLA_FLAG }, |
Marek Kwaczynski | 60f4a7b | 2013-12-03 10:04:59 +0100 | [diff] [blame] | 381 | [NL80211_ATTR_OPMODE_NOTIF] = { .type = NLA_U8 }, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 382 | [NL80211_ATTR_VENDOR_ID] = { .type = NLA_U32 }, |
| 383 | [NL80211_ATTR_VENDOR_SUBCMD] = { .type = NLA_U32 }, |
| 384 | [NL80211_ATTR_VENDOR_DATA] = { .type = NLA_BINARY }, |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 385 | [NL80211_ATTR_QOS_MAP] = { .type = NLA_BINARY, |
| 386 | .len = IEEE80211_QOS_MAP_LEN_MAX }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 387 | }; |
| 388 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 389 | /* policy for the key attributes */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 390 | static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 391 | [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 392 | [NL80211_KEY_IDX] = { .type = NLA_U8 }, |
| 393 | [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, |
Jouni Malinen | 8196226 | 2011-11-02 23:36:31 +0200 | [diff] [blame] | 394 | [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 395 | [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, |
| 396 | [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 397 | [NL80211_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 398 | [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
| 399 | }; |
| 400 | |
| 401 | /* policy for the key default flags */ |
| 402 | static const struct nla_policy |
| 403 | nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = { |
| 404 | [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG }, |
| 405 | [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 406 | }; |
| 407 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 408 | /* policy for WoWLAN attributes */ |
| 409 | static const struct nla_policy |
| 410 | nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = { |
| 411 | [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG }, |
| 412 | [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG }, |
| 413 | [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG }, |
| 414 | [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED }, |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 415 | [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG }, |
| 416 | [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG }, |
| 417 | [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG }, |
| 418 | [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG }, |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 419 | [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED }, |
| 420 | }; |
| 421 | |
| 422 | static const struct nla_policy |
| 423 | nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = { |
| 424 | [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 }, |
| 425 | [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 }, |
| 426 | [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN }, |
| 427 | [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 }, |
| 428 | [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 }, |
| 429 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 }, |
| 430 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = { |
| 431 | .len = sizeof(struct nl80211_wowlan_tcp_data_seq) |
| 432 | }, |
| 433 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = { |
| 434 | .len = sizeof(struct nl80211_wowlan_tcp_data_token) |
| 435 | }, |
| 436 | [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 }, |
| 437 | [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 }, |
| 438 | [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 439 | }; |
| 440 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 441 | /* policy for coalesce rule attributes */ |
| 442 | static const struct nla_policy |
| 443 | nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = { |
| 444 | [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 }, |
| 445 | [NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 }, |
| 446 | [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED }, |
| 447 | }; |
| 448 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 449 | /* policy for GTK rekey offload attributes */ |
| 450 | static const struct nla_policy |
| 451 | nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = { |
| 452 | [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN }, |
| 453 | [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN }, |
| 454 | [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN }, |
| 455 | }; |
| 456 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 457 | static const struct nla_policy |
| 458 | nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = { |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 459 | [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 460 | .len = IEEE80211_MAX_SSID_LEN }, |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 461 | [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 }, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 462 | }; |
| 463 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 464 | static int nl80211_prepare_wdev_dump(struct sk_buff *skb, |
| 465 | struct netlink_callback *cb, |
| 466 | struct cfg80211_registered_device **rdev, |
| 467 | struct wireless_dev **wdev) |
Holger Schurig | a043897 | 2009-11-11 11:30:02 +0100 | [diff] [blame] | 468 | { |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 469 | int err; |
| 470 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 471 | rtnl_lock(); |
| 472 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 473 | if (!cb->args[0]) { |
| 474 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 475 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 476 | nl80211_policy); |
| 477 | if (err) |
| 478 | goto out_unlock; |
| 479 | |
| 480 | *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk), |
| 481 | nl80211_fam.attrbuf); |
| 482 | if (IS_ERR(*wdev)) { |
| 483 | err = PTR_ERR(*wdev); |
| 484 | goto out_unlock; |
| 485 | } |
| 486 | *rdev = wiphy_to_dev((*wdev)->wiphy); |
Johannes Berg | c319d50 | 2013-07-30 22:34:28 +0200 | [diff] [blame] | 487 | /* 0 is the first index - add 1 to parse only once */ |
| 488 | cb->args[0] = (*rdev)->wiphy_idx + 1; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 489 | cb->args[1] = (*wdev)->identifier; |
| 490 | } else { |
Johannes Berg | c319d50 | 2013-07-30 22:34:28 +0200 | [diff] [blame] | 491 | /* subtract the 1 again here */ |
| 492 | struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1); |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 493 | struct wireless_dev *tmp; |
| 494 | |
| 495 | if (!wiphy) { |
| 496 | err = -ENODEV; |
| 497 | goto out_unlock; |
| 498 | } |
| 499 | *rdev = wiphy_to_dev(wiphy); |
| 500 | *wdev = NULL; |
| 501 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 502 | list_for_each_entry(tmp, &(*rdev)->wdev_list, list) { |
| 503 | if (tmp->identifier == cb->args[1]) { |
| 504 | *wdev = tmp; |
| 505 | break; |
| 506 | } |
| 507 | } |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 508 | |
| 509 | if (!*wdev) { |
| 510 | err = -ENODEV; |
| 511 | goto out_unlock; |
| 512 | } |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 513 | } |
| 514 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 515 | return 0; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 516 | out_unlock: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 517 | rtnl_unlock(); |
| 518 | return err; |
| 519 | } |
| 520 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 521 | static void nl80211_finish_wdev_dump(struct cfg80211_registered_device *rdev) |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 522 | { |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 523 | rtnl_unlock(); |
| 524 | } |
| 525 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 526 | /* IE validation */ |
| 527 | static bool is_valid_ie_attr(const struct nlattr *attr) |
| 528 | { |
| 529 | const u8 *pos; |
| 530 | int len; |
| 531 | |
| 532 | if (!attr) |
| 533 | return true; |
| 534 | |
| 535 | pos = nla_data(attr); |
| 536 | len = nla_len(attr); |
| 537 | |
| 538 | while (len) { |
| 539 | u8 elemlen; |
| 540 | |
| 541 | if (len < 2) |
| 542 | return false; |
| 543 | len -= 2; |
| 544 | |
| 545 | elemlen = pos[1]; |
| 546 | if (elemlen > len) |
| 547 | return false; |
| 548 | |
| 549 | len -= elemlen; |
| 550 | pos += 2 + elemlen; |
| 551 | } |
| 552 | |
| 553 | return true; |
| 554 | } |
| 555 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 556 | /* message building helper */ |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 557 | 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] | 558 | int flags, u8 cmd) |
| 559 | { |
| 560 | /* since there is no private header just add the generic one */ |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 561 | return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 562 | } |
| 563 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 564 | static int nl80211_msg_put_channel(struct sk_buff *msg, |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 565 | struct ieee80211_channel *chan, |
| 566 | bool large) |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 567 | { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 568 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
| 569 | chan->center_freq)) |
| 570 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 571 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 572 | if ((chan->flags & IEEE80211_CHAN_DISABLED) && |
| 573 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED)) |
| 574 | goto nla_put_failure; |
Luis R. Rodriguez | 8fe02e1 | 2013-10-21 19:22:25 +0200 | [diff] [blame] | 575 | if (chan->flags & IEEE80211_CHAN_NO_IR) { |
| 576 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR)) |
| 577 | goto nla_put_failure; |
| 578 | if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS)) |
| 579 | goto nla_put_failure; |
| 580 | } |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 581 | if (chan->flags & IEEE80211_CHAN_RADAR) { |
| 582 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR)) |
| 583 | goto nla_put_failure; |
| 584 | if (large) { |
| 585 | u32 time; |
| 586 | |
| 587 | time = elapsed_jiffies_msecs(chan->dfs_state_entered); |
| 588 | |
| 589 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE, |
| 590 | chan->dfs_state)) |
| 591 | goto nla_put_failure; |
| 592 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME, |
| 593 | time)) |
| 594 | goto nla_put_failure; |
| 595 | } |
| 596 | } |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 597 | |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 598 | if (large) { |
| 599 | if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) && |
| 600 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS)) |
| 601 | goto nla_put_failure; |
| 602 | if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) && |
| 603 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS)) |
| 604 | goto nla_put_failure; |
| 605 | if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) && |
| 606 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ)) |
| 607 | goto nla_put_failure; |
| 608 | if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) && |
| 609 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ)) |
| 610 | goto nla_put_failure; |
| 611 | } |
| 612 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 613 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
| 614 | DBM_TO_MBM(chan->max_power))) |
| 615 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 616 | |
| 617 | return 0; |
| 618 | |
| 619 | nla_put_failure: |
| 620 | return -ENOBUFS; |
| 621 | } |
| 622 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 623 | /* netlink command implementations */ |
| 624 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 625 | struct key_parse { |
| 626 | struct key_params p; |
| 627 | int idx; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 628 | int type; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 629 | bool def, defmgmt; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 630 | bool def_uni, def_multi; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 631 | }; |
| 632 | |
| 633 | static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k) |
| 634 | { |
| 635 | struct nlattr *tb[NL80211_KEY_MAX + 1]; |
| 636 | int err = nla_parse_nested(tb, NL80211_KEY_MAX, key, |
| 637 | nl80211_key_policy); |
| 638 | if (err) |
| 639 | return err; |
| 640 | |
| 641 | k->def = !!tb[NL80211_KEY_DEFAULT]; |
| 642 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; |
| 643 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 644 | if (k->def) { |
| 645 | k->def_uni = true; |
| 646 | k->def_multi = true; |
| 647 | } |
| 648 | if (k->defmgmt) |
| 649 | k->def_multi = true; |
| 650 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 651 | if (tb[NL80211_KEY_IDX]) |
| 652 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); |
| 653 | |
| 654 | if (tb[NL80211_KEY_DATA]) { |
| 655 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); |
| 656 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); |
| 657 | } |
| 658 | |
| 659 | if (tb[NL80211_KEY_SEQ]) { |
| 660 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); |
| 661 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); |
| 662 | } |
| 663 | |
| 664 | if (tb[NL80211_KEY_CIPHER]) |
| 665 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); |
| 666 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 667 | if (tb[NL80211_KEY_TYPE]) { |
| 668 | k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); |
| 669 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 670 | return -EINVAL; |
| 671 | } |
| 672 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 673 | if (tb[NL80211_KEY_DEFAULT_TYPES]) { |
| 674 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
Johannes Berg | 2da8f41 | 2012-01-20 13:52:37 +0100 | [diff] [blame] | 675 | err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 676 | tb[NL80211_KEY_DEFAULT_TYPES], |
| 677 | nl80211_key_default_policy); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 678 | if (err) |
| 679 | return err; |
| 680 | |
| 681 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 682 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 683 | } |
| 684 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 685 | return 0; |
| 686 | } |
| 687 | |
| 688 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) |
| 689 | { |
| 690 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { |
| 691 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 692 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 693 | } |
| 694 | |
| 695 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { |
| 696 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 697 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 698 | } |
| 699 | |
| 700 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 701 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 702 | |
| 703 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) |
| 704 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); |
| 705 | |
| 706 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; |
| 707 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; |
| 708 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 709 | if (k->def) { |
| 710 | k->def_uni = true; |
| 711 | k->def_multi = true; |
| 712 | } |
| 713 | if (k->defmgmt) |
| 714 | k->def_multi = true; |
| 715 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 716 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 717 | k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 718 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 719 | return -EINVAL; |
| 720 | } |
| 721 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 722 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { |
| 723 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
| 724 | int err = nla_parse_nested( |
| 725 | kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 726 | info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], |
| 727 | nl80211_key_default_policy); |
| 728 | if (err) |
| 729 | return err; |
| 730 | |
| 731 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 732 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 733 | } |
| 734 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 735 | return 0; |
| 736 | } |
| 737 | |
| 738 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) |
| 739 | { |
| 740 | int err; |
| 741 | |
| 742 | memset(k, 0, sizeof(*k)); |
| 743 | k->idx = -1; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 744 | k->type = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 745 | |
| 746 | if (info->attrs[NL80211_ATTR_KEY]) |
| 747 | err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k); |
| 748 | else |
| 749 | err = nl80211_parse_key_old(info, k); |
| 750 | |
| 751 | if (err) |
| 752 | return err; |
| 753 | |
| 754 | if (k->def && k->defmgmt) |
| 755 | return -EINVAL; |
| 756 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 757 | if (k->defmgmt) { |
| 758 | if (k->def_uni || !k->def_multi) |
| 759 | return -EINVAL; |
| 760 | } |
| 761 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 762 | if (k->idx != -1) { |
| 763 | if (k->defmgmt) { |
| 764 | if (k->idx < 4 || k->idx > 5) |
| 765 | return -EINVAL; |
| 766 | } else if (k->def) { |
| 767 | if (k->idx < 0 || k->idx > 3) |
| 768 | return -EINVAL; |
| 769 | } else { |
| 770 | if (k->idx < 0 || k->idx > 5) |
| 771 | return -EINVAL; |
| 772 | } |
| 773 | } |
| 774 | |
| 775 | return 0; |
| 776 | } |
| 777 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 778 | static struct cfg80211_cached_keys * |
| 779 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 780 | struct nlattr *keys, bool *no_ht) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 781 | { |
| 782 | struct key_parse parse; |
| 783 | struct nlattr *key; |
| 784 | struct cfg80211_cached_keys *result; |
| 785 | int rem, err, def = 0; |
| 786 | |
| 787 | result = kzalloc(sizeof(*result), GFP_KERNEL); |
| 788 | if (!result) |
| 789 | return ERR_PTR(-ENOMEM); |
| 790 | |
| 791 | result->def = -1; |
| 792 | result->defmgmt = -1; |
| 793 | |
| 794 | nla_for_each_nested(key, keys, rem) { |
| 795 | memset(&parse, 0, sizeof(parse)); |
| 796 | parse.idx = -1; |
| 797 | |
| 798 | err = nl80211_parse_key_new(key, &parse); |
| 799 | if (err) |
| 800 | goto error; |
| 801 | err = -EINVAL; |
| 802 | if (!parse.p.key) |
| 803 | goto error; |
| 804 | if (parse.idx < 0 || parse.idx > 4) |
| 805 | goto error; |
| 806 | if (parse.def) { |
| 807 | if (def) |
| 808 | goto error; |
| 809 | def = 1; |
| 810 | result->def = parse.idx; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 811 | if (!parse.def_uni || !parse.def_multi) |
| 812 | goto error; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 813 | } else if (parse.defmgmt) |
| 814 | goto error; |
| 815 | err = cfg80211_validate_key_settings(rdev, &parse.p, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 816 | parse.idx, false, NULL); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 817 | if (err) |
| 818 | goto error; |
| 819 | result->params[parse.idx].cipher = parse.p.cipher; |
| 820 | result->params[parse.idx].key_len = parse.p.key_len; |
| 821 | result->params[parse.idx].key = result->data[parse.idx]; |
| 822 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 823 | |
| 824 | if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 || |
| 825 | parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) { |
| 826 | if (no_ht) |
| 827 | *no_ht = true; |
| 828 | } |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 829 | } |
| 830 | |
| 831 | return result; |
| 832 | error: |
| 833 | kfree(result); |
| 834 | return ERR_PTR(err); |
| 835 | } |
| 836 | |
| 837 | static int nl80211_key_allowed(struct wireless_dev *wdev) |
| 838 | { |
| 839 | ASSERT_WDEV_LOCK(wdev); |
| 840 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 841 | switch (wdev->iftype) { |
| 842 | case NL80211_IFTYPE_AP: |
| 843 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 844 | case NL80211_IFTYPE_P2P_GO: |
Thomas Pedersen | ff973af | 2011-05-03 16:57:12 -0700 | [diff] [blame] | 845 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 846 | break; |
| 847 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 848 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 849 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 850 | if (!wdev->current_bss) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 851 | return -ENOLINK; |
| 852 | break; |
| 853 | default: |
| 854 | return -EINVAL; |
| 855 | } |
| 856 | |
| 857 | return 0; |
| 858 | } |
| 859 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 860 | static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) |
| 861 | { |
| 862 | struct nlattr *nl_modes = nla_nest_start(msg, attr); |
| 863 | int i; |
| 864 | |
| 865 | if (!nl_modes) |
| 866 | goto nla_put_failure; |
| 867 | |
| 868 | i = 0; |
| 869 | while (ifmodes) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 870 | if ((ifmodes & 1) && nla_put_flag(msg, i)) |
| 871 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 872 | ifmodes >>= 1; |
| 873 | i++; |
| 874 | } |
| 875 | |
| 876 | nla_nest_end(msg, nl_modes); |
| 877 | return 0; |
| 878 | |
| 879 | nla_put_failure: |
| 880 | return -ENOBUFS; |
| 881 | } |
| 882 | |
| 883 | static int nl80211_put_iface_combinations(struct wiphy *wiphy, |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 884 | struct sk_buff *msg, |
| 885 | bool large) |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 886 | { |
| 887 | struct nlattr *nl_combis; |
| 888 | int i, j; |
| 889 | |
| 890 | nl_combis = nla_nest_start(msg, |
| 891 | NL80211_ATTR_INTERFACE_COMBINATIONS); |
| 892 | if (!nl_combis) |
| 893 | goto nla_put_failure; |
| 894 | |
| 895 | for (i = 0; i < wiphy->n_iface_combinations; i++) { |
| 896 | const struct ieee80211_iface_combination *c; |
| 897 | struct nlattr *nl_combi, *nl_limits; |
| 898 | |
| 899 | c = &wiphy->iface_combinations[i]; |
| 900 | |
| 901 | nl_combi = nla_nest_start(msg, i + 1); |
| 902 | if (!nl_combi) |
| 903 | goto nla_put_failure; |
| 904 | |
| 905 | nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS); |
| 906 | if (!nl_limits) |
| 907 | goto nla_put_failure; |
| 908 | |
| 909 | for (j = 0; j < c->n_limits; j++) { |
| 910 | struct nlattr *nl_limit; |
| 911 | |
| 912 | nl_limit = nla_nest_start(msg, j + 1); |
| 913 | if (!nl_limit) |
| 914 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 915 | if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX, |
| 916 | c->limits[j].max)) |
| 917 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 918 | if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, |
| 919 | c->limits[j].types)) |
| 920 | goto nla_put_failure; |
| 921 | nla_nest_end(msg, nl_limit); |
| 922 | } |
| 923 | |
| 924 | nla_nest_end(msg, nl_limits); |
| 925 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 926 | if (c->beacon_int_infra_match && |
| 927 | nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH)) |
| 928 | goto nla_put_failure; |
| 929 | if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, |
| 930 | c->num_different_channels) || |
| 931 | nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM, |
| 932 | c->max_interfaces)) |
| 933 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 934 | if (large && |
| 935 | nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS, |
| 936 | c->radar_detect_widths)) |
| 937 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 938 | |
| 939 | nla_nest_end(msg, nl_combi); |
| 940 | } |
| 941 | |
| 942 | nla_nest_end(msg, nl_combis); |
| 943 | |
| 944 | return 0; |
| 945 | nla_put_failure: |
| 946 | return -ENOBUFS; |
| 947 | } |
| 948 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 949 | #ifdef CONFIG_PM |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 950 | static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev, |
| 951 | struct sk_buff *msg) |
| 952 | { |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 953 | const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp; |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 954 | struct nlattr *nl_tcp; |
| 955 | |
| 956 | if (!tcp) |
| 957 | return 0; |
| 958 | |
| 959 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); |
| 960 | if (!nl_tcp) |
| 961 | return -ENOBUFS; |
| 962 | |
| 963 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 964 | tcp->data_payload_max)) |
| 965 | return -ENOBUFS; |
| 966 | |
| 967 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 968 | tcp->data_payload_max)) |
| 969 | return -ENOBUFS; |
| 970 | |
| 971 | if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ)) |
| 972 | return -ENOBUFS; |
| 973 | |
| 974 | if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, |
| 975 | sizeof(*tcp->tok), tcp->tok)) |
| 976 | return -ENOBUFS; |
| 977 | |
| 978 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, |
| 979 | tcp->data_interval_max)) |
| 980 | return -ENOBUFS; |
| 981 | |
| 982 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, |
| 983 | tcp->wake_payload_max)) |
| 984 | return -ENOBUFS; |
| 985 | |
| 986 | nla_nest_end(msg, nl_tcp); |
| 987 | return 0; |
| 988 | } |
| 989 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 990 | static int nl80211_send_wowlan(struct sk_buff *msg, |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 991 | struct cfg80211_registered_device *dev, |
| 992 | bool large) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 993 | { |
| 994 | struct nlattr *nl_wowlan; |
| 995 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 996 | if (!dev->wiphy.wowlan) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 997 | return 0; |
| 998 | |
| 999 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); |
| 1000 | if (!nl_wowlan) |
| 1001 | return -ENOBUFS; |
| 1002 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 1003 | if (((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1004 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 1005 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1006 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 1007 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1008 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 1009 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1010 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) || |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 1011 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1012 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 1013 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1014 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 1015 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1016 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 1017 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1018 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 1019 | return -ENOBUFS; |
| 1020 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 1021 | if (dev->wiphy.wowlan->n_patterns) { |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 1022 | struct nl80211_pattern_support pat = { |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 1023 | .max_patterns = dev->wiphy.wowlan->n_patterns, |
| 1024 | .min_pattern_len = dev->wiphy.wowlan->pattern_min_len, |
| 1025 | .max_pattern_len = dev->wiphy.wowlan->pattern_max_len, |
| 1026 | .max_pkt_offset = dev->wiphy.wowlan->max_pkt_offset, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1027 | }; |
| 1028 | |
| 1029 | if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 1030 | sizeof(pat), &pat)) |
| 1031 | return -ENOBUFS; |
| 1032 | } |
| 1033 | |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1034 | if (large && nl80211_send_wowlan_tcp_caps(dev, msg)) |
| 1035 | return -ENOBUFS; |
| 1036 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1037 | nla_nest_end(msg, nl_wowlan); |
| 1038 | |
| 1039 | return 0; |
| 1040 | } |
| 1041 | #endif |
| 1042 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1043 | static int nl80211_send_coalesce(struct sk_buff *msg, |
| 1044 | struct cfg80211_registered_device *dev) |
| 1045 | { |
| 1046 | struct nl80211_coalesce_rule_support rule; |
| 1047 | |
| 1048 | if (!dev->wiphy.coalesce) |
| 1049 | return 0; |
| 1050 | |
| 1051 | rule.max_rules = dev->wiphy.coalesce->n_rules; |
| 1052 | rule.max_delay = dev->wiphy.coalesce->max_delay; |
| 1053 | rule.pat.max_patterns = dev->wiphy.coalesce->n_patterns; |
| 1054 | rule.pat.min_pattern_len = dev->wiphy.coalesce->pattern_min_len; |
| 1055 | rule.pat.max_pattern_len = dev->wiphy.coalesce->pattern_max_len; |
| 1056 | rule.pat.max_pkt_offset = dev->wiphy.coalesce->max_pkt_offset; |
| 1057 | |
| 1058 | if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule)) |
| 1059 | return -ENOBUFS; |
| 1060 | |
| 1061 | return 0; |
| 1062 | } |
| 1063 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1064 | static int nl80211_send_band_rateinfo(struct sk_buff *msg, |
| 1065 | struct ieee80211_supported_band *sband) |
| 1066 | { |
| 1067 | struct nlattr *nl_rates, *nl_rate; |
| 1068 | struct ieee80211_rate *rate; |
| 1069 | int i; |
| 1070 | |
| 1071 | /* add HT info */ |
| 1072 | if (sband->ht_cap.ht_supported && |
| 1073 | (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET, |
| 1074 | sizeof(sband->ht_cap.mcs), |
| 1075 | &sband->ht_cap.mcs) || |
| 1076 | nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA, |
| 1077 | sband->ht_cap.cap) || |
| 1078 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, |
| 1079 | sband->ht_cap.ampdu_factor) || |
| 1080 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, |
| 1081 | sband->ht_cap.ampdu_density))) |
| 1082 | return -ENOBUFS; |
| 1083 | |
| 1084 | /* add VHT info */ |
| 1085 | if (sband->vht_cap.vht_supported && |
| 1086 | (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET, |
| 1087 | sizeof(sband->vht_cap.vht_mcs), |
| 1088 | &sband->vht_cap.vht_mcs) || |
| 1089 | nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA, |
| 1090 | sband->vht_cap.cap))) |
| 1091 | return -ENOBUFS; |
| 1092 | |
| 1093 | /* add bitrates */ |
| 1094 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); |
| 1095 | if (!nl_rates) |
| 1096 | return -ENOBUFS; |
| 1097 | |
| 1098 | for (i = 0; i < sband->n_bitrates; i++) { |
| 1099 | nl_rate = nla_nest_start(msg, i); |
| 1100 | if (!nl_rate) |
| 1101 | return -ENOBUFS; |
| 1102 | |
| 1103 | rate = &sband->bitrates[i]; |
| 1104 | if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE, |
| 1105 | rate->bitrate)) |
| 1106 | return -ENOBUFS; |
| 1107 | if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) && |
| 1108 | nla_put_flag(msg, |
| 1109 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE)) |
| 1110 | return -ENOBUFS; |
| 1111 | |
| 1112 | nla_nest_end(msg, nl_rate); |
| 1113 | } |
| 1114 | |
| 1115 | nla_nest_end(msg, nl_rates); |
| 1116 | |
| 1117 | return 0; |
| 1118 | } |
| 1119 | |
| 1120 | static int |
| 1121 | nl80211_send_mgmt_stypes(struct sk_buff *msg, |
| 1122 | const struct ieee80211_txrx_stypes *mgmt_stypes) |
| 1123 | { |
| 1124 | u16 stypes; |
| 1125 | struct nlattr *nl_ftypes, *nl_ifs; |
| 1126 | enum nl80211_iftype ift; |
| 1127 | int i; |
| 1128 | |
| 1129 | if (!mgmt_stypes) |
| 1130 | return 0; |
| 1131 | |
| 1132 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES); |
| 1133 | if (!nl_ifs) |
| 1134 | return -ENOBUFS; |
| 1135 | |
| 1136 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 1137 | nl_ftypes = nla_nest_start(msg, ift); |
| 1138 | if (!nl_ftypes) |
| 1139 | return -ENOBUFS; |
| 1140 | i = 0; |
| 1141 | stypes = mgmt_stypes[ift].tx; |
| 1142 | while (stypes) { |
| 1143 | if ((stypes & 1) && |
| 1144 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1145 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1146 | return -ENOBUFS; |
| 1147 | stypes >>= 1; |
| 1148 | i++; |
| 1149 | } |
| 1150 | nla_nest_end(msg, nl_ftypes); |
| 1151 | } |
| 1152 | |
| 1153 | nla_nest_end(msg, nl_ifs); |
| 1154 | |
| 1155 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES); |
| 1156 | if (!nl_ifs) |
| 1157 | return -ENOBUFS; |
| 1158 | |
| 1159 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 1160 | nl_ftypes = nla_nest_start(msg, ift); |
| 1161 | if (!nl_ftypes) |
| 1162 | return -ENOBUFS; |
| 1163 | i = 0; |
| 1164 | stypes = mgmt_stypes[ift].rx; |
| 1165 | while (stypes) { |
| 1166 | if ((stypes & 1) && |
| 1167 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1168 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1169 | return -ENOBUFS; |
| 1170 | stypes >>= 1; |
| 1171 | i++; |
| 1172 | } |
| 1173 | nla_nest_end(msg, nl_ftypes); |
| 1174 | } |
| 1175 | nla_nest_end(msg, nl_ifs); |
| 1176 | |
| 1177 | return 0; |
| 1178 | } |
| 1179 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1180 | struct nl80211_dump_wiphy_state { |
| 1181 | s64 filter_wiphy; |
| 1182 | long start; |
| 1183 | long split_start, band_start, chan_start; |
| 1184 | bool split; |
| 1185 | }; |
| 1186 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1187 | static int nl80211_send_wiphy(struct cfg80211_registered_device *dev, |
| 1188 | struct sk_buff *msg, u32 portid, u32 seq, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1189 | int flags, struct nl80211_dump_wiphy_state *state) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1190 | { |
| 1191 | void *hdr; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1192 | struct nlattr *nl_bands, *nl_band; |
| 1193 | struct nlattr *nl_freqs, *nl_freq; |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1194 | struct nlattr *nl_cmds; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1195 | enum ieee80211_band band; |
| 1196 | struct ieee80211_channel *chan; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1197 | int i; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1198 | const struct ieee80211_txrx_stypes *mgmt_stypes = |
| 1199 | dev->wiphy.mgmt_stypes; |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1200 | u32 features; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1201 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 1202 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_WIPHY); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1203 | if (!hdr) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1204 | return -ENOBUFS; |
| 1205 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1206 | if (WARN_ON(!state)) |
| 1207 | return -EINVAL; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1208 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1209 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1210 | nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, |
| 1211 | wiphy_name(&dev->wiphy)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1212 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1213 | cfg80211_rdev_list_generation)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1214 | goto nla_put_failure; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1215 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1216 | switch (state->split_start) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1217 | case 0: |
| 1218 | if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, |
| 1219 | dev->wiphy.retry_short) || |
| 1220 | nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, |
| 1221 | dev->wiphy.retry_long) || |
| 1222 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, |
| 1223 | dev->wiphy.frag_threshold) || |
| 1224 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, |
| 1225 | dev->wiphy.rts_threshold) || |
| 1226 | nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, |
| 1227 | dev->wiphy.coverage_class) || |
| 1228 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, |
| 1229 | dev->wiphy.max_scan_ssids) || |
| 1230 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, |
| 1231 | dev->wiphy.max_sched_scan_ssids) || |
| 1232 | nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, |
| 1233 | dev->wiphy.max_scan_ie_len) || |
| 1234 | nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, |
| 1235 | dev->wiphy.max_sched_scan_ie_len) || |
| 1236 | nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS, |
| 1237 | dev->wiphy.max_match_sets)) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1238 | goto nla_put_failure; |
| 1239 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1240 | if ((dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) && |
| 1241 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN)) |
| 1242 | goto nla_put_failure; |
| 1243 | if ((dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) && |
| 1244 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH)) |
| 1245 | goto nla_put_failure; |
| 1246 | if ((dev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && |
| 1247 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD)) |
| 1248 | goto nla_put_failure; |
| 1249 | if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) && |
| 1250 | nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT)) |
| 1251 | goto nla_put_failure; |
| 1252 | if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) && |
| 1253 | nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT)) |
| 1254 | goto nla_put_failure; |
| 1255 | if ((dev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) && |
| 1256 | nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1257 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1258 | state->split_start++; |
| 1259 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1260 | break; |
| 1261 | case 1: |
| 1262 | if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES, |
| 1263 | sizeof(u32) * dev->wiphy.n_cipher_suites, |
| 1264 | dev->wiphy.cipher_suites)) |
Mahesh Palivela | bf0c111e | 2012-06-22 07:27:46 +0000 | [diff] [blame] | 1265 | goto nla_put_failure; |
| 1266 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1267 | if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, |
| 1268 | dev->wiphy.max_num_pmkids)) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1269 | goto nla_put_failure; |
| 1270 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1271 | if ((dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 1272 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE)) |
| 1273 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1274 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1275 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, |
| 1276 | dev->wiphy.available_antennas_tx) || |
| 1277 | nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, |
| 1278 | dev->wiphy.available_antennas_rx)) |
| 1279 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1280 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1281 | if ((dev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) && |
| 1282 | nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD, |
| 1283 | dev->wiphy.probe_resp_offload)) |
| 1284 | goto nla_put_failure; |
Jouni Malinen | e2f367f26 | 2008-11-21 19:01:30 +0200 | [diff] [blame] | 1285 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1286 | if ((dev->wiphy.available_antennas_tx || |
| 1287 | dev->wiphy.available_antennas_rx) && |
| 1288 | dev->ops->get_antenna) { |
| 1289 | u32 tx_ant = 0, rx_ant = 0; |
| 1290 | int res; |
| 1291 | res = rdev_get_antenna(dev, &tx_ant, &rx_ant); |
| 1292 | if (!res) { |
| 1293 | if (nla_put_u32(msg, |
| 1294 | NL80211_ATTR_WIPHY_ANTENNA_TX, |
| 1295 | tx_ant) || |
| 1296 | nla_put_u32(msg, |
| 1297 | NL80211_ATTR_WIPHY_ANTENNA_RX, |
| 1298 | rx_ant)) |
| 1299 | goto nla_put_failure; |
| 1300 | } |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1301 | } |
| 1302 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1303 | state->split_start++; |
| 1304 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1305 | break; |
| 1306 | case 2: |
| 1307 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, |
| 1308 | dev->wiphy.interface_modes)) |
| 1309 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1310 | state->split_start++; |
| 1311 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1312 | break; |
| 1313 | case 3: |
| 1314 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); |
| 1315 | if (!nl_bands) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1316 | goto nla_put_failure; |
| 1317 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1318 | for (band = state->band_start; |
| 1319 | band < IEEE80211_NUM_BANDS; band++) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1320 | struct ieee80211_supported_band *sband; |
| 1321 | |
| 1322 | sband = dev->wiphy.bands[band]; |
| 1323 | |
| 1324 | if (!sband) |
| 1325 | continue; |
| 1326 | |
| 1327 | nl_band = nla_nest_start(msg, band); |
| 1328 | if (!nl_band) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1329 | goto nla_put_failure; |
| 1330 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1331 | switch (state->chan_start) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1332 | case 0: |
| 1333 | if (nl80211_send_band_rateinfo(msg, sband)) |
| 1334 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1335 | state->chan_start++; |
| 1336 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1337 | break; |
| 1338 | default: |
| 1339 | /* add frequencies */ |
| 1340 | nl_freqs = nla_nest_start( |
| 1341 | msg, NL80211_BAND_ATTR_FREQS); |
| 1342 | if (!nl_freqs) |
| 1343 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1344 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1345 | for (i = state->chan_start - 1; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1346 | i < sband->n_channels; |
| 1347 | i++) { |
| 1348 | nl_freq = nla_nest_start(msg, i); |
| 1349 | if (!nl_freq) |
| 1350 | goto nla_put_failure; |
| 1351 | |
| 1352 | chan = &sband->channels[i]; |
| 1353 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1354 | if (nl80211_msg_put_channel( |
| 1355 | msg, chan, |
| 1356 | state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1357 | goto nla_put_failure; |
| 1358 | |
| 1359 | nla_nest_end(msg, nl_freq); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1360 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1361 | break; |
| 1362 | } |
| 1363 | if (i < sband->n_channels) |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1364 | state->chan_start = i + 2; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1365 | else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1366 | state->chan_start = 0; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1367 | nla_nest_end(msg, nl_freqs); |
| 1368 | } |
| 1369 | |
| 1370 | nla_nest_end(msg, nl_band); |
| 1371 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1372 | if (state->split) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1373 | /* start again here */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1374 | if (state->chan_start) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1375 | band--; |
| 1376 | break; |
| 1377 | } |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1378 | } |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1379 | nla_nest_end(msg, nl_bands); |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1380 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1381 | if (band < IEEE80211_NUM_BANDS) |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1382 | state->band_start = band + 1; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1383 | else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1384 | state->band_start = 0; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1385 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1386 | /* if bands & channels are done, continue outside */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1387 | if (state->band_start == 0 && state->chan_start == 0) |
| 1388 | state->split_start++; |
| 1389 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1390 | break; |
| 1391 | case 4: |
| 1392 | nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); |
| 1393 | if (!nl_cmds) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1394 | goto nla_put_failure; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1395 | |
| 1396 | i = 0; |
| 1397 | #define CMD(op, n) \ |
| 1398 | do { \ |
| 1399 | if (dev->ops->op) { \ |
| 1400 | i++; \ |
| 1401 | if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \ |
| 1402 | goto nla_put_failure; \ |
| 1403 | } \ |
| 1404 | } while (0) |
| 1405 | |
| 1406 | CMD(add_virtual_intf, NEW_INTERFACE); |
| 1407 | CMD(change_virtual_intf, SET_INTERFACE); |
| 1408 | CMD(add_key, NEW_KEY); |
| 1409 | CMD(start_ap, START_AP); |
| 1410 | CMD(add_station, NEW_STATION); |
| 1411 | CMD(add_mpath, NEW_MPATH); |
| 1412 | CMD(update_mesh_config, SET_MESH_CONFIG); |
| 1413 | CMD(change_bss, SET_BSS); |
| 1414 | CMD(auth, AUTHENTICATE); |
| 1415 | CMD(assoc, ASSOCIATE); |
| 1416 | CMD(deauth, DEAUTHENTICATE); |
| 1417 | CMD(disassoc, DISASSOCIATE); |
| 1418 | CMD(join_ibss, JOIN_IBSS); |
| 1419 | CMD(join_mesh, JOIN_MESH); |
| 1420 | CMD(set_pmksa, SET_PMKSA); |
| 1421 | CMD(del_pmksa, DEL_PMKSA); |
| 1422 | CMD(flush_pmksa, FLUSH_PMKSA); |
| 1423 | if (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) |
| 1424 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); |
| 1425 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); |
| 1426 | CMD(mgmt_tx, FRAME); |
| 1427 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); |
| 1428 | if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { |
| 1429 | i++; |
| 1430 | if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS)) |
| 1431 | goto nla_put_failure; |
| 1432 | } |
| 1433 | if (dev->ops->set_monitor_channel || dev->ops->start_ap || |
| 1434 | dev->ops->join_mesh) { |
| 1435 | i++; |
| 1436 | if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL)) |
| 1437 | goto nla_put_failure; |
| 1438 | } |
| 1439 | CMD(set_wds_peer, SET_WDS_PEER); |
| 1440 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) { |
| 1441 | CMD(tdls_mgmt, TDLS_MGMT); |
| 1442 | CMD(tdls_oper, TDLS_OPER); |
| 1443 | } |
| 1444 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) |
| 1445 | CMD(sched_scan_start, START_SCHED_SCAN); |
| 1446 | CMD(probe_client, PROBE_CLIENT); |
| 1447 | CMD(set_noack_map, SET_NOACK_MAP); |
| 1448 | if (dev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) { |
| 1449 | i++; |
| 1450 | if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS)) |
| 1451 | goto nla_put_failure; |
| 1452 | } |
| 1453 | CMD(start_p2p_device, START_P2P_DEVICE); |
| 1454 | CMD(set_mcast_rate, SET_MCAST_RATE); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1455 | if (state->split) { |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 1456 | CMD(crit_proto_start, CRIT_PROTOCOL_START); |
| 1457 | CMD(crit_proto_stop, CRIT_PROTOCOL_STOP); |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 1458 | if (dev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH) |
| 1459 | CMD(channel_switch, CHANNEL_SWITCH); |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 1460 | } |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 1461 | CMD(set_qos_map, SET_QOS_MAP); |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1462 | |
Kalle Valo | 4745fc0 | 2011-11-17 19:06:10 +0200 | [diff] [blame] | 1463 | #ifdef CONFIG_NL80211_TESTMODE |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1464 | CMD(testmode_cmd, TESTMODE); |
Kalle Valo | 4745fc0 | 2011-11-17 19:06:10 +0200 | [diff] [blame] | 1465 | #endif |
| 1466 | |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1467 | #undef CMD |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1468 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1469 | if (dev->ops->connect || dev->ops->auth) { |
| 1470 | i++; |
| 1471 | if (nla_put_u32(msg, i, NL80211_CMD_CONNECT)) |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1472 | goto nla_put_failure; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1473 | } |
| 1474 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1475 | if (dev->ops->disconnect || dev->ops->deauth) { |
| 1476 | i++; |
| 1477 | if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT)) |
| 1478 | goto nla_put_failure; |
| 1479 | } |
Johannes Berg | 74b70a4 | 2010-08-24 12:15:53 +0200 | [diff] [blame] | 1480 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1481 | nla_nest_end(msg, nl_cmds); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1482 | state->split_start++; |
| 1483 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1484 | break; |
| 1485 | case 5: |
| 1486 | if (dev->ops->remain_on_channel && |
| 1487 | (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) && |
| 1488 | nla_put_u32(msg, |
| 1489 | NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, |
| 1490 | dev->wiphy.max_remain_on_channel_duration)) |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1491 | goto nla_put_failure; |
| 1492 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1493 | if ((dev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) && |
| 1494 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) |
| 1495 | goto nla_put_failure; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1496 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1497 | if (nl80211_send_mgmt_stypes(msg, mgmt_stypes)) |
| 1498 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1499 | state->split_start++; |
| 1500 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1501 | break; |
| 1502 | case 6: |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 1503 | #ifdef CONFIG_PM |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1504 | if (nl80211_send_wowlan(msg, dev, state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1505 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1506 | state->split_start++; |
| 1507 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1508 | break; |
| 1509 | #else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1510 | state->split_start++; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1511 | #endif |
| 1512 | case 7: |
| 1513 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, |
| 1514 | dev->wiphy.software_iftypes)) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1515 | goto nla_put_failure; |
| 1516 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1517 | if (nl80211_put_iface_combinations(&dev->wiphy, msg, |
| 1518 | state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1519 | goto nla_put_failure; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1520 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1521 | state->split_start++; |
| 1522 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1523 | break; |
| 1524 | case 8: |
| 1525 | if ((dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) && |
| 1526 | nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME, |
| 1527 | dev->wiphy.ap_sme_capa)) |
| 1528 | goto nla_put_failure; |
| 1529 | |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1530 | features = dev->wiphy.features; |
| 1531 | /* |
| 1532 | * We can only add the per-channel limit information if the |
| 1533 | * dump is split, otherwise it makes it too big. Therefore |
| 1534 | * only advertise it in that case. |
| 1535 | */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1536 | if (state->split) |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1537 | features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS; |
| 1538 | if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1539 | goto nla_put_failure; |
| 1540 | |
| 1541 | if (dev->wiphy.ht_capa_mod_mask && |
| 1542 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, |
| 1543 | sizeof(*dev->wiphy.ht_capa_mod_mask), |
| 1544 | dev->wiphy.ht_capa_mod_mask)) |
| 1545 | goto nla_put_failure; |
| 1546 | |
| 1547 | if (dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME && |
| 1548 | dev->wiphy.max_acl_mac_addrs && |
| 1549 | nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX, |
| 1550 | dev->wiphy.max_acl_mac_addrs)) |
| 1551 | goto nla_put_failure; |
| 1552 | |
| 1553 | /* |
| 1554 | * Any information below this point is only available to |
| 1555 | * applications that can deal with it being split. This |
| 1556 | * helps ensure that newly added capabilities don't break |
| 1557 | * older tools by overrunning their buffers. |
| 1558 | * |
| 1559 | * We still increment split_start so that in the split |
| 1560 | * case we'll continue with more data in the next round, |
| 1561 | * but break unconditionally so unsplit data stops here. |
| 1562 | */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1563 | state->split_start++; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1564 | break; |
| 1565 | case 9: |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1566 | if (dev->wiphy.extended_capabilities && |
| 1567 | (nla_put(msg, NL80211_ATTR_EXT_CAPA, |
| 1568 | dev->wiphy.extended_capabilities_len, |
| 1569 | dev->wiphy.extended_capabilities) || |
| 1570 | nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, |
| 1571 | dev->wiphy.extended_capabilities_len, |
| 1572 | dev->wiphy.extended_capabilities_mask))) |
| 1573 | goto nla_put_failure; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1574 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 1575 | if (dev->wiphy.vht_capa_mod_mask && |
| 1576 | nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, |
| 1577 | sizeof(*dev->wiphy.vht_capa_mod_mask), |
| 1578 | dev->wiphy.vht_capa_mod_mask)) |
| 1579 | goto nla_put_failure; |
| 1580 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1581 | state->split_start++; |
| 1582 | break; |
| 1583 | case 10: |
| 1584 | if (nl80211_send_coalesce(msg, dev)) |
| 1585 | goto nla_put_failure; |
| 1586 | |
Felix Fietkau | 01e0daa | 2013-11-09 14:57:54 +0100 | [diff] [blame] | 1587 | if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) && |
| 1588 | (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) || |
| 1589 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ))) |
| 1590 | goto nla_put_failure; |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 1591 | state->split_start++; |
| 1592 | break; |
| 1593 | case 11: |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1594 | if (dev->wiphy.n_vendor_commands) { |
| 1595 | const struct nl80211_vendor_cmd_info *info; |
| 1596 | struct nlattr *nested; |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 1597 | |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1598 | nested = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); |
| 1599 | if (!nested) |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 1600 | goto nla_put_failure; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1601 | |
| 1602 | for (i = 0; i < dev->wiphy.n_vendor_commands; i++) { |
| 1603 | info = &dev->wiphy.vendor_commands[i].info; |
| 1604 | if (nla_put(msg, i + 1, sizeof(*info), info)) |
| 1605 | goto nla_put_failure; |
| 1606 | } |
| 1607 | nla_nest_end(msg, nested); |
| 1608 | } |
| 1609 | |
| 1610 | if (dev->wiphy.n_vendor_events) { |
| 1611 | const struct nl80211_vendor_cmd_info *info; |
| 1612 | struct nlattr *nested; |
| 1613 | |
| 1614 | nested = nla_nest_start(msg, |
| 1615 | NL80211_ATTR_VENDOR_EVENTS); |
| 1616 | if (!nested) |
| 1617 | goto nla_put_failure; |
| 1618 | |
| 1619 | for (i = 0; i < dev->wiphy.n_vendor_events; i++) { |
| 1620 | info = &dev->wiphy.vendor_events[i]; |
| 1621 | if (nla_put(msg, i + 1, sizeof(*info), info)) |
| 1622 | goto nla_put_failure; |
| 1623 | } |
| 1624 | nla_nest_end(msg, nested); |
| 1625 | } |
Felix Fietkau | 01e0daa | 2013-11-09 14:57:54 +0100 | [diff] [blame] | 1626 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1627 | /* done */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1628 | state->split_start = 0; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1629 | break; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1630 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1631 | return genlmsg_end(msg, hdr); |
| 1632 | |
| 1633 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 1634 | genlmsg_cancel(msg, hdr); |
| 1635 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1636 | } |
| 1637 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1638 | static int nl80211_dump_wiphy_parse(struct sk_buff *skb, |
| 1639 | struct netlink_callback *cb, |
| 1640 | struct nl80211_dump_wiphy_state *state) |
| 1641 | { |
| 1642 | struct nlattr **tb = nl80211_fam.attrbuf; |
| 1643 | int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 1644 | tb, nl80211_fam.maxattr, nl80211_policy); |
| 1645 | /* ignore parse errors for backward compatibility */ |
| 1646 | if (ret) |
| 1647 | return 0; |
| 1648 | |
| 1649 | state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP]; |
| 1650 | if (tb[NL80211_ATTR_WIPHY]) |
| 1651 | state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]); |
| 1652 | if (tb[NL80211_ATTR_WDEV]) |
| 1653 | state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32; |
| 1654 | if (tb[NL80211_ATTR_IFINDEX]) { |
| 1655 | struct net_device *netdev; |
| 1656 | struct cfg80211_registered_device *rdev; |
| 1657 | int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); |
| 1658 | |
| 1659 | netdev = dev_get_by_index(sock_net(skb->sk), ifidx); |
| 1660 | if (!netdev) |
| 1661 | return -ENODEV; |
| 1662 | if (netdev->ieee80211_ptr) { |
| 1663 | rdev = wiphy_to_dev( |
| 1664 | netdev->ieee80211_ptr->wiphy); |
| 1665 | state->filter_wiphy = rdev->wiphy_idx; |
| 1666 | } |
| 1667 | dev_put(netdev); |
| 1668 | } |
| 1669 | |
| 1670 | return 0; |
| 1671 | } |
| 1672 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1673 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) |
| 1674 | { |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1675 | int idx = 0, ret; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1676 | struct nl80211_dump_wiphy_state *state = (void *)cb->args[0]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1677 | struct cfg80211_registered_device *dev; |
Johannes Berg | 3a5a423 | 2013-06-19 10:09:57 +0200 | [diff] [blame] | 1678 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1679 | rtnl_lock(); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1680 | if (!state) { |
| 1681 | state = kzalloc(sizeof(*state), GFP_KERNEL); |
John W. Linville | 57ed5cd | 2013-06-28 13:18:21 -0400 | [diff] [blame] | 1682 | if (!state) { |
| 1683 | rtnl_unlock(); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1684 | return -ENOMEM; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1685 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1686 | state->filter_wiphy = -1; |
| 1687 | ret = nl80211_dump_wiphy_parse(skb, cb, state); |
| 1688 | if (ret) { |
| 1689 | kfree(state); |
| 1690 | rtnl_unlock(); |
| 1691 | return ret; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1692 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1693 | cb->args[0] = (long)state; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1694 | } |
| 1695 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1696 | list_for_each_entry(dev, &cfg80211_rdev_list, list) { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1697 | if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk))) |
| 1698 | continue; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1699 | if (++idx <= state->start) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1700 | continue; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1701 | if (state->filter_wiphy != -1 && |
| 1702 | state->filter_wiphy != dev->wiphy_idx) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1703 | continue; |
| 1704 | /* attempt to fit multiple wiphy data chunks into the skb */ |
| 1705 | do { |
| 1706 | ret = nl80211_send_wiphy(dev, skb, |
| 1707 | NETLINK_CB(cb->skb).portid, |
| 1708 | cb->nlh->nlmsg_seq, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1709 | NLM_F_MULTI, state); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1710 | if (ret < 0) { |
| 1711 | /* |
| 1712 | * If sending the wiphy data didn't fit (ENOBUFS |
| 1713 | * or EMSGSIZE returned), this SKB is still |
| 1714 | * empty (so it's not too big because another |
| 1715 | * wiphy dataset is already in the skb) and |
| 1716 | * we've not tried to adjust the dump allocation |
| 1717 | * yet ... then adjust the alloc size to be |
| 1718 | * bigger, and return 1 but with the empty skb. |
| 1719 | * This results in an empty message being RX'ed |
| 1720 | * in userspace, but that is ignored. |
| 1721 | * |
| 1722 | * We can then retry with the larger buffer. |
| 1723 | */ |
| 1724 | if ((ret == -ENOBUFS || ret == -EMSGSIZE) && |
| 1725 | !skb->len && |
| 1726 | cb->min_dump_alloc < 4096) { |
| 1727 | cb->min_dump_alloc = 4096; |
David S. Miller | d98cae64e | 2013-06-19 16:49:39 -0700 | [diff] [blame] | 1728 | rtnl_unlock(); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1729 | return 1; |
| 1730 | } |
| 1731 | idx--; |
| 1732 | break; |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1733 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1734 | } while (state->split_start > 0); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1735 | break; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1736 | } |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1737 | rtnl_unlock(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1738 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1739 | state->start = idx; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1740 | |
| 1741 | return skb->len; |
| 1742 | } |
| 1743 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1744 | static int nl80211_dump_wiphy_done(struct netlink_callback *cb) |
| 1745 | { |
| 1746 | kfree((void *)cb->args[0]); |
| 1747 | return 0; |
| 1748 | } |
| 1749 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1750 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1751 | { |
| 1752 | struct sk_buff *msg; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1753 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1754 | struct nl80211_dump_wiphy_state state = {}; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1755 | |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1756 | msg = nlmsg_new(4096, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1757 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1758 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1759 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1760 | if (nl80211_send_wiphy(dev, msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1761 | &state) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1762 | nlmsg_free(msg); |
| 1763 | return -ENOBUFS; |
| 1764 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1765 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 1766 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1767 | } |
| 1768 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1769 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
| 1770 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, |
| 1771 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, |
| 1772 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, |
| 1773 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, |
| 1774 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, |
| 1775 | }; |
| 1776 | |
| 1777 | static int parse_txq_params(struct nlattr *tb[], |
| 1778 | struct ieee80211_txq_params *txq_params) |
| 1779 | { |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1780 | if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] || |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1781 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
| 1782 | !tb[NL80211_TXQ_ATTR_AIFS]) |
| 1783 | return -EINVAL; |
| 1784 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1785 | txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1786 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
| 1787 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); |
| 1788 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); |
| 1789 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); |
| 1790 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1791 | if (txq_params->ac >= NL80211_NUM_ACS) |
| 1792 | return -EINVAL; |
| 1793 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1794 | return 0; |
| 1795 | } |
| 1796 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1797 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
| 1798 | { |
| 1799 | /* |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1800 | * You can only set the channel explicitly for WDS interfaces, |
| 1801 | * all others have their channel managed via their respective |
| 1802 | * "establish a connection" command (connect, join, ...) |
| 1803 | * |
| 1804 | * For AP/GO and mesh mode, the channel can be set with the |
| 1805 | * channel userspace API, but is only stored and passed to the |
| 1806 | * low-level driver when the AP starts or the mesh is joined. |
| 1807 | * This is for backward compatibility, userspace can also give |
| 1808 | * the channel in the start-ap or join-mesh commands instead. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1809 | * |
| 1810 | * Monitors are special as they are normally slaved to |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1811 | * whatever else is going on, so they have their own special |
| 1812 | * operation to set the monitor channel if possible. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1813 | */ |
| 1814 | return !wdev || |
| 1815 | wdev->iftype == NL80211_IFTYPE_AP || |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1816 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 1817 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
| 1818 | wdev->iftype == NL80211_IFTYPE_P2P_GO; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1819 | } |
| 1820 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1821 | static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev, |
| 1822 | struct genl_info *info, |
| 1823 | struct cfg80211_chan_def *chandef) |
| 1824 | { |
Mahesh Palivela | dbeca2e | 2012-11-29 14:11:07 +0530 | [diff] [blame] | 1825 | u32 control_freq; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1826 | |
| 1827 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 1828 | return -EINVAL; |
| 1829 | |
| 1830 | control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 1831 | |
| 1832 | chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1833 | chandef->width = NL80211_CHAN_WIDTH_20_NOHT; |
| 1834 | chandef->center_freq1 = control_freq; |
| 1835 | chandef->center_freq2 = 0; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1836 | |
| 1837 | /* Primary channel not allowed */ |
| 1838 | if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) |
| 1839 | return -EINVAL; |
| 1840 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1841 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 1842 | enum nl80211_channel_type chantype; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1843 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1844 | chantype = nla_get_u32( |
| 1845 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 1846 | |
| 1847 | switch (chantype) { |
| 1848 | case NL80211_CHAN_NO_HT: |
| 1849 | case NL80211_CHAN_HT20: |
| 1850 | case NL80211_CHAN_HT40PLUS: |
| 1851 | case NL80211_CHAN_HT40MINUS: |
| 1852 | cfg80211_chandef_create(chandef, chandef->chan, |
| 1853 | chantype); |
| 1854 | break; |
| 1855 | default: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1856 | return -EINVAL; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1857 | } |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1858 | } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) { |
| 1859 | chandef->width = |
| 1860 | nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]); |
| 1861 | if (info->attrs[NL80211_ATTR_CENTER_FREQ1]) |
| 1862 | chandef->center_freq1 = |
| 1863 | nla_get_u32( |
| 1864 | info->attrs[NL80211_ATTR_CENTER_FREQ1]); |
| 1865 | if (info->attrs[NL80211_ATTR_CENTER_FREQ2]) |
| 1866 | chandef->center_freq2 = |
| 1867 | nla_get_u32( |
| 1868 | info->attrs[NL80211_ATTR_CENTER_FREQ2]); |
| 1869 | } |
| 1870 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 1871 | if (!cfg80211_chandef_valid(chandef)) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1872 | return -EINVAL; |
| 1873 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 1874 | if (!cfg80211_chandef_usable(&rdev->wiphy, chandef, |
| 1875 | IEEE80211_CHAN_DISABLED)) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1876 | return -EINVAL; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1877 | |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 1878 | if ((chandef->width == NL80211_CHAN_WIDTH_5 || |
| 1879 | chandef->width == NL80211_CHAN_WIDTH_10) && |
| 1880 | !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ)) |
| 1881 | return -EINVAL; |
| 1882 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1883 | return 0; |
| 1884 | } |
| 1885 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1886 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
| 1887 | struct wireless_dev *wdev, |
| 1888 | struct genl_info *info) |
| 1889 | { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1890 | struct cfg80211_chan_def chandef; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1891 | int result; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1892 | enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR; |
| 1893 | |
| 1894 | if (wdev) |
| 1895 | iftype = wdev->iftype; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1896 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1897 | if (!nl80211_can_set_dev_channel(wdev)) |
| 1898 | return -EOPNOTSUPP; |
| 1899 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1900 | result = nl80211_parse_chandef(rdev, info, &chandef); |
| 1901 | if (result) |
| 1902 | return result; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1903 | |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1904 | switch (iftype) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1905 | case NL80211_IFTYPE_AP: |
| 1906 | case NL80211_IFTYPE_P2P_GO: |
| 1907 | if (wdev->beacon_interval) { |
| 1908 | result = -EBUSY; |
| 1909 | break; |
| 1910 | } |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1911 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef)) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1912 | result = -EINVAL; |
| 1913 | break; |
| 1914 | } |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1915 | wdev->preset_chandef = chandef; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1916 | result = 0; |
| 1917 | break; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1918 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1919 | result = cfg80211_set_mesh_channel(rdev, wdev, &chandef); |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1920 | break; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1921 | case NL80211_IFTYPE_MONITOR: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1922 | result = cfg80211_set_monitor_channel(rdev, &chandef); |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1923 | break; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1924 | default: |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1925 | result = -EINVAL; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1926 | } |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1927 | |
| 1928 | return result; |
| 1929 | } |
| 1930 | |
| 1931 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) |
| 1932 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1933 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1934 | struct net_device *netdev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1935 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1936 | return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1937 | } |
| 1938 | |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1939 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
| 1940 | { |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1941 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1942 | struct net_device *dev = info->user_ptr[1]; |
| 1943 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 388ac77 | 2010-10-07 13:11:09 +0200 | [diff] [blame] | 1944 | const u8 *bssid; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1945 | |
| 1946 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 1947 | return -EINVAL; |
| 1948 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1949 | if (netif_running(dev)) |
| 1950 | return -EBUSY; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1951 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1952 | if (!rdev->ops->set_wds_peer) |
| 1953 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1954 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1955 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
| 1956 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1957 | |
| 1958 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 1959 | return rdev_set_wds_peer(rdev, dev, bssid); |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1960 | } |
| 1961 | |
| 1962 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1963 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1964 | { |
| 1965 | struct cfg80211_registered_device *rdev; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1966 | struct net_device *netdev = NULL; |
| 1967 | struct wireless_dev *wdev; |
Bill Jordan | a1e567c | 2010-09-10 11:22:32 -0400 | [diff] [blame] | 1968 | int result = 0, rem_txq_params = 0; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1969 | struct nlattr *nl_txq_params; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1970 | u32 changed; |
| 1971 | u8 retry_short = 0, retry_long = 0; |
| 1972 | u32 frag_threshold = 0, rts_threshold = 0; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1973 | u8 coverage_class = 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1974 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1975 | ASSERT_RTNL(); |
| 1976 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1977 | /* |
| 1978 | * Try to find the wiphy and netdev. Normally this |
| 1979 | * function shouldn't need the netdev, but this is |
| 1980 | * done for backward compatibility -- previously |
| 1981 | * setting the channel was done per wiphy, but now |
| 1982 | * it is per netdev. Previous userland like hostapd |
| 1983 | * also passed a netdev to set_wiphy, so that it is |
| 1984 | * possible to let that go to the right netdev! |
| 1985 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1986 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1987 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
| 1988 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); |
| 1989 | |
| 1990 | netdev = dev_get_by_index(genl_info_net(info), ifindex); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1991 | if (netdev && netdev->ieee80211_ptr) |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1992 | rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1993 | else |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1994 | netdev = NULL; |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1995 | } |
| 1996 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1997 | if (!netdev) { |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 1998 | rdev = __cfg80211_rdev_from_attrs(genl_info_net(info), |
| 1999 | info->attrs); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2000 | if (IS_ERR(rdev)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2001 | return PTR_ERR(rdev); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2002 | wdev = NULL; |
| 2003 | netdev = NULL; |
| 2004 | result = 0; |
Johannes Berg | 71fe96b | 2012-10-24 10:04:58 +0200 | [diff] [blame] | 2005 | } else |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2006 | wdev = netdev->ieee80211_ptr; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2007 | |
| 2008 | /* |
| 2009 | * end workaround code, by now the rdev is available |
| 2010 | * and locked, and wdev may or may not be NULL. |
| 2011 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2012 | |
| 2013 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2014 | result = cfg80211_dev_rename( |
| 2015 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2016 | |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2017 | if (result) |
| 2018 | goto bad_res; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2019 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2020 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { |
| 2021 | struct ieee80211_txq_params txq_params; |
| 2022 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; |
| 2023 | |
| 2024 | if (!rdev->ops->set_txq_params) { |
| 2025 | result = -EOPNOTSUPP; |
| 2026 | goto bad_res; |
| 2027 | } |
| 2028 | |
Eliad Peller | f70f01c | 2011-09-25 20:06:53 +0300 | [diff] [blame] | 2029 | if (!netdev) { |
| 2030 | result = -EINVAL; |
| 2031 | goto bad_res; |
| 2032 | } |
| 2033 | |
Johannes Berg | 133a3ff | 2011-11-03 14:50:13 +0100 | [diff] [blame] | 2034 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 2035 | netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { |
| 2036 | result = -EINVAL; |
| 2037 | goto bad_res; |
| 2038 | } |
| 2039 | |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 2040 | if (!netif_running(netdev)) { |
| 2041 | result = -ENETDOWN; |
| 2042 | goto bad_res; |
| 2043 | } |
| 2044 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2045 | nla_for_each_nested(nl_txq_params, |
| 2046 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], |
| 2047 | rem_txq_params) { |
| 2048 | nla_parse(tb, NL80211_TXQ_ATTR_MAX, |
| 2049 | nla_data(nl_txq_params), |
| 2050 | nla_len(nl_txq_params), |
| 2051 | txq_params_policy); |
| 2052 | result = parse_txq_params(tb, &txq_params); |
| 2053 | if (result) |
| 2054 | goto bad_res; |
| 2055 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2056 | result = rdev_set_txq_params(rdev, netdev, |
| 2057 | &txq_params); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2058 | if (result) |
| 2059 | goto bad_res; |
| 2060 | } |
| 2061 | } |
| 2062 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2063 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 71fe96b | 2012-10-24 10:04:58 +0200 | [diff] [blame] | 2064 | result = __nl80211_set_channel(rdev, |
| 2065 | nl80211_can_set_dev_channel(wdev) ? wdev : NULL, |
| 2066 | info); |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2067 | if (result) |
| 2068 | goto bad_res; |
| 2069 | } |
| 2070 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2071 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2072 | struct wireless_dev *txp_wdev = wdev; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2073 | enum nl80211_tx_power_setting type; |
| 2074 | int idx, mbm = 0; |
| 2075 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2076 | if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER)) |
| 2077 | txp_wdev = NULL; |
| 2078 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2079 | if (!rdev->ops->set_tx_power) { |
Jiri Slaby | 60ea385 | 2010-07-07 15:02:46 +0200 | [diff] [blame] | 2080 | result = -EOPNOTSUPP; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2081 | goto bad_res; |
| 2082 | } |
| 2083 | |
| 2084 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; |
| 2085 | type = nla_get_u32(info->attrs[idx]); |
| 2086 | |
| 2087 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && |
| 2088 | (type != NL80211_TX_POWER_AUTOMATIC)) { |
| 2089 | result = -EINVAL; |
| 2090 | goto bad_res; |
| 2091 | } |
| 2092 | |
| 2093 | if (type != NL80211_TX_POWER_AUTOMATIC) { |
| 2094 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; |
| 2095 | mbm = nla_get_u32(info->attrs[idx]); |
| 2096 | } |
| 2097 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2098 | result = rdev_set_tx_power(rdev, txp_wdev, type, mbm); |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2099 | if (result) |
| 2100 | goto bad_res; |
| 2101 | } |
| 2102 | |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2103 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
| 2104 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { |
| 2105 | u32 tx_ant, rx_ant; |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2106 | if ((!rdev->wiphy.available_antennas_tx && |
| 2107 | !rdev->wiphy.available_antennas_rx) || |
| 2108 | !rdev->ops->set_antenna) { |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2109 | result = -EOPNOTSUPP; |
| 2110 | goto bad_res; |
| 2111 | } |
| 2112 | |
| 2113 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); |
| 2114 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); |
| 2115 | |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2116 | /* reject antenna configurations which don't match the |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2117 | * available antenna masks, except for the "all" mask */ |
| 2118 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || |
| 2119 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) { |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2120 | result = -EINVAL; |
| 2121 | goto bad_res; |
| 2122 | } |
| 2123 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2124 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
| 2125 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2126 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2127 | result = rdev_set_antenna(rdev, tx_ant, rx_ant); |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2128 | if (result) |
| 2129 | goto bad_res; |
| 2130 | } |
| 2131 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2132 | changed = 0; |
| 2133 | |
| 2134 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { |
| 2135 | retry_short = nla_get_u8( |
| 2136 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); |
| 2137 | if (retry_short == 0) { |
| 2138 | result = -EINVAL; |
| 2139 | goto bad_res; |
| 2140 | } |
| 2141 | changed |= WIPHY_PARAM_RETRY_SHORT; |
| 2142 | } |
| 2143 | |
| 2144 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { |
| 2145 | retry_long = nla_get_u8( |
| 2146 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); |
| 2147 | if (retry_long == 0) { |
| 2148 | result = -EINVAL; |
| 2149 | goto bad_res; |
| 2150 | } |
| 2151 | changed |= WIPHY_PARAM_RETRY_LONG; |
| 2152 | } |
| 2153 | |
| 2154 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { |
| 2155 | frag_threshold = nla_get_u32( |
| 2156 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); |
| 2157 | if (frag_threshold < 256) { |
| 2158 | result = -EINVAL; |
| 2159 | goto bad_res; |
| 2160 | } |
| 2161 | if (frag_threshold != (u32) -1) { |
| 2162 | /* |
| 2163 | * Fragments (apart from the last one) are required to |
| 2164 | * have even length. Make the fragmentation code |
| 2165 | * simpler by stripping LSB should someone try to use |
| 2166 | * odd threshold value. |
| 2167 | */ |
| 2168 | frag_threshold &= ~0x1; |
| 2169 | } |
| 2170 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; |
| 2171 | } |
| 2172 | |
| 2173 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { |
| 2174 | rts_threshold = nla_get_u32( |
| 2175 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); |
| 2176 | changed |= WIPHY_PARAM_RTS_THRESHOLD; |
| 2177 | } |
| 2178 | |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2179 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
| 2180 | coverage_class = nla_get_u8( |
| 2181 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); |
| 2182 | changed |= WIPHY_PARAM_COVERAGE_CLASS; |
| 2183 | } |
| 2184 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2185 | if (changed) { |
| 2186 | u8 old_retry_short, old_retry_long; |
| 2187 | u32 old_frag_threshold, old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2188 | u8 old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2189 | |
| 2190 | if (!rdev->ops->set_wiphy_params) { |
| 2191 | result = -EOPNOTSUPP; |
| 2192 | goto bad_res; |
| 2193 | } |
| 2194 | |
| 2195 | old_retry_short = rdev->wiphy.retry_short; |
| 2196 | old_retry_long = rdev->wiphy.retry_long; |
| 2197 | old_frag_threshold = rdev->wiphy.frag_threshold; |
| 2198 | old_rts_threshold = rdev->wiphy.rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2199 | old_coverage_class = rdev->wiphy.coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2200 | |
| 2201 | if (changed & WIPHY_PARAM_RETRY_SHORT) |
| 2202 | rdev->wiphy.retry_short = retry_short; |
| 2203 | if (changed & WIPHY_PARAM_RETRY_LONG) |
| 2204 | rdev->wiphy.retry_long = retry_long; |
| 2205 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) |
| 2206 | rdev->wiphy.frag_threshold = frag_threshold; |
| 2207 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) |
| 2208 | rdev->wiphy.rts_threshold = rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2209 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
| 2210 | rdev->wiphy.coverage_class = coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2211 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2212 | result = rdev_set_wiphy_params(rdev, changed); |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2213 | if (result) { |
| 2214 | rdev->wiphy.retry_short = old_retry_short; |
| 2215 | rdev->wiphy.retry_long = old_retry_long; |
| 2216 | rdev->wiphy.frag_threshold = old_frag_threshold; |
| 2217 | rdev->wiphy.rts_threshold = old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2218 | rdev->wiphy.coverage_class = old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2219 | } |
| 2220 | } |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2221 | |
Johannes Berg | 306d611 | 2008-12-08 12:39:04 +0100 | [diff] [blame] | 2222 | bad_res: |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2223 | if (netdev) |
| 2224 | dev_put(netdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2225 | return result; |
| 2226 | } |
| 2227 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 2228 | static inline u64 wdev_id(struct wireless_dev *wdev) |
| 2229 | { |
| 2230 | return (u64)wdev->identifier | |
| 2231 | ((u64)wiphy_to_dev(wdev->wiphy)->wiphy_idx << 32); |
| 2232 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2233 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2234 | static int nl80211_send_chandef(struct sk_buff *msg, |
Janusz Dziedzic | d2859df | 2013-11-06 13:55:51 +0100 | [diff] [blame] | 2235 | const struct cfg80211_chan_def *chandef) |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2236 | { |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 2237 | WARN_ON(!cfg80211_chandef_valid(chandef)); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2238 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2239 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
| 2240 | chandef->chan->center_freq)) |
| 2241 | return -ENOBUFS; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2242 | switch (chandef->width) { |
| 2243 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 2244 | case NL80211_CHAN_WIDTH_20: |
| 2245 | case NL80211_CHAN_WIDTH_40: |
| 2246 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 2247 | cfg80211_get_chandef_type(chandef))) |
| 2248 | return -ENOBUFS; |
| 2249 | break; |
| 2250 | default: |
| 2251 | break; |
| 2252 | } |
| 2253 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width)) |
| 2254 | return -ENOBUFS; |
| 2255 | if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1)) |
| 2256 | return -ENOBUFS; |
| 2257 | if (chandef->center_freq2 && |
| 2258 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2)) |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2259 | return -ENOBUFS; |
| 2260 | return 0; |
| 2261 | } |
| 2262 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2263 | 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] | 2264 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2265 | struct wireless_dev *wdev) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2266 | { |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2267 | struct net_device *dev = wdev->netdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2268 | void *hdr; |
| 2269 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2270 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_INTERFACE); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2271 | if (!hdr) |
| 2272 | return -1; |
| 2273 | |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2274 | if (dev && |
| 2275 | (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2276 | nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name))) |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2277 | goto nla_put_failure; |
| 2278 | |
| 2279 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 2280 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 2281 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2282 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2283 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
| 2284 | rdev->devlist_generation ^ |
| 2285 | (cfg80211_rdev_list_generation << 2))) |
| 2286 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2287 | |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 2288 | if (rdev->ops->get_channel) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2289 | int ret; |
| 2290 | struct cfg80211_chan_def chandef; |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 2291 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2292 | ret = rdev_get_channel(rdev, wdev, &chandef); |
| 2293 | if (ret == 0) { |
| 2294 | if (nl80211_send_chandef(msg, &chandef)) |
| 2295 | goto nla_put_failure; |
| 2296 | } |
Pontus Fuchs | d91df0e | 2012-04-03 16:39:58 +0200 | [diff] [blame] | 2297 | } |
| 2298 | |
Antonio Quartulli | b84e7a0 | 2012-11-07 12:52:20 +0100 | [diff] [blame] | 2299 | if (wdev->ssid_len) { |
| 2300 | if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid)) |
| 2301 | goto nla_put_failure; |
| 2302 | } |
| 2303 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2304 | return genlmsg_end(msg, hdr); |
| 2305 | |
| 2306 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 2307 | genlmsg_cancel(msg, hdr); |
| 2308 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2309 | } |
| 2310 | |
| 2311 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) |
| 2312 | { |
| 2313 | int wp_idx = 0; |
| 2314 | int if_idx = 0; |
| 2315 | int wp_start = cb->args[0]; |
| 2316 | int if_start = cb->args[1]; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2317 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2318 | struct wireless_dev *wdev; |
| 2319 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2320 | rtnl_lock(); |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2321 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 2322 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2323 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2324 | if (wp_idx < wp_start) { |
| 2325 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2326 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2327 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2328 | if_idx = 0; |
| 2329 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 2330 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2331 | if (if_idx < if_start) { |
| 2332 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2333 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2334 | } |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2335 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2336 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2337 | rdev, wdev) < 0) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2338 | goto out; |
| 2339 | } |
| 2340 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2341 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2342 | |
| 2343 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2344 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2345 | out: |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2346 | rtnl_unlock(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2347 | |
| 2348 | cb->args[0] = wp_idx; |
| 2349 | cb->args[1] = if_idx; |
| 2350 | |
| 2351 | return skb->len; |
| 2352 | } |
| 2353 | |
| 2354 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) |
| 2355 | { |
| 2356 | struct sk_buff *msg; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2357 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2358 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2359 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2360 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2361 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2362 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2363 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2364 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2365 | dev, wdev) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2366 | nlmsg_free(msg); |
| 2367 | return -ENOBUFS; |
| 2368 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2369 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 2370 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2371 | } |
| 2372 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2373 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
| 2374 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, |
| 2375 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, |
| 2376 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, |
| 2377 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, |
| 2378 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2379 | [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG }, |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2380 | }; |
| 2381 | |
| 2382 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) |
| 2383 | { |
| 2384 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; |
| 2385 | int flag; |
| 2386 | |
| 2387 | *mntrflags = 0; |
| 2388 | |
| 2389 | if (!nla) |
| 2390 | return -EINVAL; |
| 2391 | |
| 2392 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, |
| 2393 | nla, mntr_flags_policy)) |
| 2394 | return -EINVAL; |
| 2395 | |
| 2396 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) |
| 2397 | if (flags[flag]) |
| 2398 | *mntrflags |= (1<<flag); |
| 2399 | |
| 2400 | return 0; |
| 2401 | } |
| 2402 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2403 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2404 | struct net_device *netdev, u8 use_4addr, |
| 2405 | enum nl80211_iftype iftype) |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2406 | { |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2407 | if (!use_4addr) { |
Jiri Pirko | f350a0a8 | 2010-06-15 06:50:45 +0000 | [diff] [blame] | 2408 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2409 | return -EBUSY; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2410 | return 0; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2411 | } |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2412 | |
| 2413 | switch (iftype) { |
| 2414 | case NL80211_IFTYPE_AP_VLAN: |
| 2415 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) |
| 2416 | return 0; |
| 2417 | break; |
| 2418 | case NL80211_IFTYPE_STATION: |
| 2419 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) |
| 2420 | return 0; |
| 2421 | break; |
| 2422 | default: |
| 2423 | break; |
| 2424 | } |
| 2425 | |
| 2426 | return -EOPNOTSUPP; |
| 2427 | } |
| 2428 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2429 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
| 2430 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2431 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2432 | struct vif_params params; |
Johannes Berg | e36d56b | 2009-06-09 21:04:43 +0200 | [diff] [blame] | 2433 | int err; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2434 | enum nl80211_iftype otype, ntype; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2435 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2436 | u32 _flags, *flags = NULL; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2437 | bool change = false; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2438 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2439 | memset(¶ms, 0, sizeof(params)); |
| 2440 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2441 | otype = ntype = dev->ieee80211_ptr->iftype; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2442 | |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 2443 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2444 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2445 | if (otype != ntype) |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2446 | change = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2447 | if (ntype > NL80211_IFTYPE_MAX) |
| 2448 | return -EINVAL; |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 2449 | } |
| 2450 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2451 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2452 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2453 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2454 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
| 2455 | return -EINVAL; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2456 | if (netif_running(dev)) |
| 2457 | return -EBUSY; |
| 2458 | |
| 2459 | wdev_lock(wdev); |
| 2460 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 2461 | IEEE80211_MAX_MESH_ID_LEN); |
| 2462 | wdev->mesh_id_up_len = |
| 2463 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 2464 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 2465 | wdev->mesh_id_up_len); |
| 2466 | wdev_unlock(wdev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2467 | } |
| 2468 | |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2469 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
| 2470 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
| 2471 | change = true; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2472 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2473 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2474 | return err; |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2475 | } else { |
| 2476 | params.use_4addr = -1; |
| 2477 | } |
| 2478 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2479 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2480 | if (ntype != NL80211_IFTYPE_MONITOR) |
| 2481 | return -EINVAL; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2482 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
| 2483 | &_flags); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2484 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2485 | return err; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2486 | |
| 2487 | flags = &_flags; |
| 2488 | change = true; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2489 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2490 | |
Luciano Coelho | 1800329 | 2013-08-29 13:26:57 +0300 | [diff] [blame] | 2491 | if (flags && (*flags & MONITOR_FLAG_ACTIVE) && |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2492 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
| 2493 | return -EOPNOTSUPP; |
| 2494 | |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2495 | if (change) |
Johannes Berg | 3d54d25 | 2009-08-21 14:51:05 +0200 | [diff] [blame] | 2496 | err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2497 | else |
| 2498 | err = 0; |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 2499 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2500 | if (!err && params.use_4addr != -1) |
| 2501 | dev->ieee80211_ptr->use_4addr = params.use_4addr; |
| 2502 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2503 | return err; |
| 2504 | } |
| 2505 | |
| 2506 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) |
| 2507 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2508 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2509 | struct vif_params params; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2510 | struct wireless_dev *wdev; |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2511 | struct sk_buff *msg; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2512 | int err; |
| 2513 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2514 | u32 flags; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2515 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2516 | memset(¶ms, 0, sizeof(params)); |
| 2517 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2518 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
| 2519 | return -EINVAL; |
| 2520 | |
| 2521 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
| 2522 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
| 2523 | if (type > NL80211_IFTYPE_MAX) |
| 2524 | return -EINVAL; |
| 2525 | } |
| 2526 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2527 | if (!rdev->ops->add_virtual_intf || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2528 | !(rdev->wiphy.interface_modes & (1 << type))) |
| 2529 | return -EOPNOTSUPP; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2530 | |
Arend van Spriel | 1c18f14 | 2013-01-08 10:17:27 +0100 | [diff] [blame] | 2531 | if (type == NL80211_IFTYPE_P2P_DEVICE && info->attrs[NL80211_ATTR_MAC]) { |
| 2532 | nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC], |
| 2533 | ETH_ALEN); |
| 2534 | if (!is_valid_ether_addr(params.macaddr)) |
| 2535 | return -EADDRNOTAVAIL; |
| 2536 | } |
| 2537 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2538 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2539 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2540 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2541 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2542 | return err; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2543 | } |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2544 | |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2545 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 2546 | if (!msg) |
| 2547 | return -ENOMEM; |
| 2548 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2549 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
| 2550 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, |
| 2551 | &flags); |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2552 | |
Luciano Coelho | 1800329 | 2013-08-29 13:26:57 +0300 | [diff] [blame] | 2553 | if (!err && (flags & MONITOR_FLAG_ACTIVE) && |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2554 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
| 2555 | return -EOPNOTSUPP; |
| 2556 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2557 | wdev = rdev_add_virtual_intf(rdev, |
| 2558 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), |
| 2559 | type, err ? NULL : &flags, ¶ms); |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2560 | if (IS_ERR(wdev)) { |
| 2561 | nlmsg_free(msg); |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2562 | return PTR_ERR(wdev); |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2563 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2564 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2565 | switch (type) { |
| 2566 | case NL80211_IFTYPE_MESH_POINT: |
| 2567 | if (!info->attrs[NL80211_ATTR_MESH_ID]) |
| 2568 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2569 | wdev_lock(wdev); |
| 2570 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 2571 | IEEE80211_MAX_MESH_ID_LEN); |
| 2572 | wdev->mesh_id_up_len = |
| 2573 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 2574 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 2575 | wdev->mesh_id_up_len); |
| 2576 | wdev_unlock(wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2577 | break; |
| 2578 | case NL80211_IFTYPE_P2P_DEVICE: |
| 2579 | /* |
| 2580 | * P2P Device doesn't have a netdev, so doesn't go |
| 2581 | * through the netdev notifier and must be added here |
| 2582 | */ |
| 2583 | mutex_init(&wdev->mtx); |
| 2584 | INIT_LIST_HEAD(&wdev->event_list); |
| 2585 | spin_lock_init(&wdev->event_lock); |
| 2586 | INIT_LIST_HEAD(&wdev->mgmt_registrations); |
| 2587 | spin_lock_init(&wdev->mgmt_registrations_lock); |
| 2588 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2589 | wdev->identifier = ++rdev->wdev_id; |
| 2590 | list_add_rcu(&wdev->list, &rdev->wdev_list); |
| 2591 | rdev->devlist_generation++; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2592 | break; |
| 2593 | default: |
| 2594 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2595 | } |
| 2596 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2597 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2598 | rdev, wdev) < 0) { |
| 2599 | nlmsg_free(msg); |
| 2600 | return -ENOBUFS; |
| 2601 | } |
| 2602 | |
| 2603 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2604 | } |
| 2605 | |
| 2606 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) |
| 2607 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2608 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2609 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2610 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2611 | if (!rdev->ops->del_virtual_intf) |
| 2612 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2613 | |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2614 | /* |
| 2615 | * If we remove a wireless device without a netdev then clear |
| 2616 | * user_ptr[1] so that nl80211_post_doit won't dereference it |
| 2617 | * to check if it needs to do dev_put(). Otherwise it crashes |
| 2618 | * since the wdev has been freed, unlike with a netdev where |
| 2619 | * we need the dev_put() for the netdev to really be freed. |
| 2620 | */ |
| 2621 | if (!wdev->netdev) |
| 2622 | info->user_ptr[1] = NULL; |
| 2623 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2624 | return rdev_del_virtual_intf(rdev, wdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2625 | } |
| 2626 | |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 2627 | static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info) |
| 2628 | { |
| 2629 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2630 | struct net_device *dev = info->user_ptr[1]; |
| 2631 | u16 noack_map; |
| 2632 | |
| 2633 | if (!info->attrs[NL80211_ATTR_NOACK_MAP]) |
| 2634 | return -EINVAL; |
| 2635 | |
| 2636 | if (!rdev->ops->set_noack_map) |
| 2637 | return -EOPNOTSUPP; |
| 2638 | |
| 2639 | noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]); |
| 2640 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2641 | return rdev_set_noack_map(rdev, dev, noack_map); |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 2642 | } |
| 2643 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2644 | struct get_key_cookie { |
| 2645 | struct sk_buff *msg; |
| 2646 | int error; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2647 | int idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2648 | }; |
| 2649 | |
| 2650 | static void get_key_callback(void *c, struct key_params *params) |
| 2651 | { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2652 | struct nlattr *key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2653 | struct get_key_cookie *cookie = c; |
| 2654 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2655 | if ((params->key && |
| 2656 | nla_put(cookie->msg, NL80211_ATTR_KEY_DATA, |
| 2657 | params->key_len, params->key)) || |
| 2658 | (params->seq && |
| 2659 | nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ, |
| 2660 | params->seq_len, params->seq)) || |
| 2661 | (params->cipher && |
| 2662 | nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER, |
| 2663 | params->cipher))) |
| 2664 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2665 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2666 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
| 2667 | if (!key) |
| 2668 | goto nla_put_failure; |
| 2669 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2670 | if ((params->key && |
| 2671 | nla_put(cookie->msg, NL80211_KEY_DATA, |
| 2672 | params->key_len, params->key)) || |
| 2673 | (params->seq && |
| 2674 | nla_put(cookie->msg, NL80211_KEY_SEQ, |
| 2675 | params->seq_len, params->seq)) || |
| 2676 | (params->cipher && |
| 2677 | nla_put_u32(cookie->msg, NL80211_KEY_CIPHER, |
| 2678 | params->cipher))) |
| 2679 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2680 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2681 | if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx)) |
| 2682 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2683 | |
| 2684 | nla_nest_end(cookie->msg, key); |
| 2685 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2686 | return; |
| 2687 | nla_put_failure: |
| 2688 | cookie->error = 1; |
| 2689 | } |
| 2690 | |
| 2691 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) |
| 2692 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2693 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2694 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2695 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2696 | u8 key_idx = 0; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2697 | const u8 *mac_addr = NULL; |
| 2698 | bool pairwise; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2699 | struct get_key_cookie cookie = { |
| 2700 | .error = 0, |
| 2701 | }; |
| 2702 | void *hdr; |
| 2703 | struct sk_buff *msg; |
| 2704 | |
| 2705 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 2706 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 2707 | |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 2708 | if (key_idx > 5) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2709 | return -EINVAL; |
| 2710 | |
| 2711 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2712 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2713 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2714 | pairwise = !!mac_addr; |
| 2715 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 2716 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 2717 | if (kt >= NUM_NL80211_KEYTYPES) |
| 2718 | return -EINVAL; |
| 2719 | if (kt != NL80211_KEYTYPE_GROUP && |
| 2720 | kt != NL80211_KEYTYPE_PAIRWISE) |
| 2721 | return -EINVAL; |
| 2722 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; |
| 2723 | } |
| 2724 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2725 | if (!rdev->ops->get_key) |
| 2726 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2727 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2728 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2729 | if (!msg) |
| 2730 | return -ENOMEM; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2731 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2732 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2733 | NL80211_CMD_NEW_KEY); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 2734 | if (!hdr) |
Johannes Berg | 9fe271a | 2013-10-25 11:15:12 +0200 | [diff] [blame] | 2735 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2736 | |
| 2737 | cookie.msg = msg; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2738 | cookie.idx = key_idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2739 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2740 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 2741 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) |
| 2742 | goto nla_put_failure; |
| 2743 | if (mac_addr && |
| 2744 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 2745 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2746 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2747 | if (pairwise && mac_addr && |
| 2748 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 2749 | return -ENOENT; |
| 2750 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2751 | err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie, |
| 2752 | get_key_callback); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2753 | |
| 2754 | if (err) |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 2755 | goto free_msg; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2756 | |
| 2757 | if (cookie.error) |
| 2758 | goto nla_put_failure; |
| 2759 | |
| 2760 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2761 | return genlmsg_reply(msg, info); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2762 | |
| 2763 | nla_put_failure: |
| 2764 | err = -ENOBUFS; |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 2765 | free_msg: |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2766 | nlmsg_free(msg); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2767 | return err; |
| 2768 | } |
| 2769 | |
| 2770 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) |
| 2771 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2772 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2773 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2774 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2775 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2776 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2777 | err = nl80211_parse_key(info, &key); |
| 2778 | if (err) |
| 2779 | return err; |
| 2780 | |
| 2781 | if (key.idx < 0) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2782 | return -EINVAL; |
| 2783 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2784 | /* only support setting default key */ |
| 2785 | if (!key.def && !key.defmgmt) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2786 | return -EINVAL; |
| 2787 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2788 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2789 | |
| 2790 | if (key.def) { |
| 2791 | if (!rdev->ops->set_default_key) { |
| 2792 | err = -EOPNOTSUPP; |
| 2793 | goto out; |
| 2794 | } |
| 2795 | |
| 2796 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2797 | if (err) |
| 2798 | goto out; |
| 2799 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2800 | err = rdev_set_default_key(rdev, dev, key.idx, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2801 | key.def_uni, key.def_multi); |
| 2802 | |
| 2803 | if (err) |
| 2804 | goto out; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2805 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 2806 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2807 | dev->ieee80211_ptr->wext.default_key = key.idx; |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2808 | #endif |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2809 | } else { |
| 2810 | if (key.def_uni || !key.def_multi) { |
| 2811 | err = -EINVAL; |
| 2812 | goto out; |
| 2813 | } |
| 2814 | |
| 2815 | if (!rdev->ops->set_default_mgmt_key) { |
| 2816 | err = -EOPNOTSUPP; |
| 2817 | goto out; |
| 2818 | } |
| 2819 | |
| 2820 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2821 | if (err) |
| 2822 | goto out; |
| 2823 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2824 | err = rdev_set_default_mgmt_key(rdev, dev, key.idx); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2825 | if (err) |
| 2826 | goto out; |
| 2827 | |
| 2828 | #ifdef CONFIG_CFG80211_WEXT |
| 2829 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; |
| 2830 | #endif |
| 2831 | } |
| 2832 | |
| 2833 | out: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2834 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2835 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2836 | return err; |
| 2837 | } |
| 2838 | |
| 2839 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) |
| 2840 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2841 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2842 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2843 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2844 | struct key_parse key; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2845 | const u8 *mac_addr = NULL; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2846 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2847 | err = nl80211_parse_key(info, &key); |
| 2848 | if (err) |
| 2849 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2850 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2851 | if (!key.p.key) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2852 | return -EINVAL; |
| 2853 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2854 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2855 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2856 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2857 | if (key.type == -1) { |
| 2858 | if (mac_addr) |
| 2859 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 2860 | else |
| 2861 | key.type = NL80211_KEYTYPE_GROUP; |
| 2862 | } |
| 2863 | |
| 2864 | /* for now */ |
| 2865 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 2866 | key.type != NL80211_KEYTYPE_GROUP) |
| 2867 | return -EINVAL; |
| 2868 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2869 | if (!rdev->ops->add_key) |
| 2870 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2871 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2872 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
| 2873 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2874 | mac_addr)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2875 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2876 | |
| 2877 | wdev_lock(dev->ieee80211_ptr); |
| 2878 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2879 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2880 | err = rdev_add_key(rdev, dev, key.idx, |
| 2881 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2882 | mac_addr, &key.p); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2883 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2884 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2885 | return err; |
| 2886 | } |
| 2887 | |
| 2888 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) |
| 2889 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2890 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2891 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2892 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2893 | u8 *mac_addr = NULL; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2894 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2895 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2896 | err = nl80211_parse_key(info, &key); |
| 2897 | if (err) |
| 2898 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2899 | |
| 2900 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2901 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2902 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2903 | if (key.type == -1) { |
| 2904 | if (mac_addr) |
| 2905 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 2906 | else |
| 2907 | key.type = NL80211_KEYTYPE_GROUP; |
| 2908 | } |
| 2909 | |
| 2910 | /* for now */ |
| 2911 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 2912 | key.type != NL80211_KEYTYPE_GROUP) |
| 2913 | return -EINVAL; |
| 2914 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2915 | if (!rdev->ops->del_key) |
| 2916 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2917 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2918 | wdev_lock(dev->ieee80211_ptr); |
| 2919 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2920 | |
| 2921 | if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr && |
| 2922 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 2923 | err = -ENOENT; |
| 2924 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2925 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2926 | err = rdev_del_key(rdev, dev, key.idx, |
| 2927 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2928 | mac_addr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2929 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 2930 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2931 | if (!err) { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2932 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2933 | dev->ieee80211_ptr->wext.default_key = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2934 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2935 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
| 2936 | } |
| 2937 | #endif |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2938 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2939 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2940 | return err; |
| 2941 | } |
| 2942 | |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 2943 | /* This function returns an error or the number of nested attributes */ |
| 2944 | static int validate_acl_mac_addrs(struct nlattr *nl_attr) |
| 2945 | { |
| 2946 | struct nlattr *attr; |
| 2947 | int n_entries = 0, tmp; |
| 2948 | |
| 2949 | nla_for_each_nested(attr, nl_attr, tmp) { |
| 2950 | if (nla_len(attr) != ETH_ALEN) |
| 2951 | return -EINVAL; |
| 2952 | |
| 2953 | n_entries++; |
| 2954 | } |
| 2955 | |
| 2956 | return n_entries; |
| 2957 | } |
| 2958 | |
| 2959 | /* |
| 2960 | * This function parses ACL information and allocates memory for ACL data. |
| 2961 | * On successful return, the calling function is responsible to free the |
| 2962 | * ACL buffer returned by this function. |
| 2963 | */ |
| 2964 | static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy, |
| 2965 | struct genl_info *info) |
| 2966 | { |
| 2967 | enum nl80211_acl_policy acl_policy; |
| 2968 | struct nlattr *attr; |
| 2969 | struct cfg80211_acl_data *acl; |
| 2970 | int i = 0, n_entries, tmp; |
| 2971 | |
| 2972 | if (!wiphy->max_acl_mac_addrs) |
| 2973 | return ERR_PTR(-EOPNOTSUPP); |
| 2974 | |
| 2975 | if (!info->attrs[NL80211_ATTR_ACL_POLICY]) |
| 2976 | return ERR_PTR(-EINVAL); |
| 2977 | |
| 2978 | acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]); |
| 2979 | if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED && |
| 2980 | acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED) |
| 2981 | return ERR_PTR(-EINVAL); |
| 2982 | |
| 2983 | if (!info->attrs[NL80211_ATTR_MAC_ADDRS]) |
| 2984 | return ERR_PTR(-EINVAL); |
| 2985 | |
| 2986 | n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]); |
| 2987 | if (n_entries < 0) |
| 2988 | return ERR_PTR(n_entries); |
| 2989 | |
| 2990 | if (n_entries > wiphy->max_acl_mac_addrs) |
| 2991 | return ERR_PTR(-ENOTSUPP); |
| 2992 | |
| 2993 | acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries), |
| 2994 | GFP_KERNEL); |
| 2995 | if (!acl) |
| 2996 | return ERR_PTR(-ENOMEM); |
| 2997 | |
| 2998 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) { |
| 2999 | memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN); |
| 3000 | i++; |
| 3001 | } |
| 3002 | |
| 3003 | acl->n_acl_entries = n_entries; |
| 3004 | acl->acl_policy = acl_policy; |
| 3005 | |
| 3006 | return acl; |
| 3007 | } |
| 3008 | |
| 3009 | static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info) |
| 3010 | { |
| 3011 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3012 | struct net_device *dev = info->user_ptr[1]; |
| 3013 | struct cfg80211_acl_data *acl; |
| 3014 | int err; |
| 3015 | |
| 3016 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3017 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3018 | return -EOPNOTSUPP; |
| 3019 | |
| 3020 | if (!dev->ieee80211_ptr->beacon_interval) |
| 3021 | return -EINVAL; |
| 3022 | |
| 3023 | acl = parse_acl_data(&rdev->wiphy, info); |
| 3024 | if (IS_ERR(acl)) |
| 3025 | return PTR_ERR(acl); |
| 3026 | |
| 3027 | err = rdev_set_mac_acl(rdev, dev, acl); |
| 3028 | |
| 3029 | kfree(acl); |
| 3030 | |
| 3031 | return err; |
| 3032 | } |
| 3033 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3034 | static int nl80211_parse_beacon(struct nlattr *attrs[], |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3035 | struct cfg80211_beacon_data *bcn) |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3036 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3037 | bool haveinfo = false; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3038 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3039 | if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) || |
| 3040 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) || |
| 3041 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) || |
| 3042 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP])) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 3043 | return -EINVAL; |
| 3044 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3045 | memset(bcn, 0, sizeof(*bcn)); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3046 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3047 | if (attrs[NL80211_ATTR_BEACON_HEAD]) { |
| 3048 | bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]); |
| 3049 | bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3050 | if (!bcn->head_len) |
| 3051 | return -EINVAL; |
| 3052 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3053 | } |
| 3054 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3055 | if (attrs[NL80211_ATTR_BEACON_TAIL]) { |
| 3056 | bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]); |
| 3057 | bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3058 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3059 | } |
| 3060 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3061 | if (!haveinfo) |
| 3062 | return -EINVAL; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3063 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3064 | if (attrs[NL80211_ATTR_IE]) { |
| 3065 | bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]); |
| 3066 | bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 3067 | } |
| 3068 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3069 | if (attrs[NL80211_ATTR_IE_PROBE_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3070 | bcn->proberesp_ies = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3071 | nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3072 | bcn->proberesp_ies_len = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3073 | nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 3074 | } |
| 3075 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3076 | if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3077 | bcn->assocresp_ies = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3078 | nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3079 | bcn->assocresp_ies_len = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3080 | nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 3081 | } |
| 3082 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3083 | if (attrs[NL80211_ATTR_PROBE_RESP]) { |
| 3084 | bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]); |
| 3085 | bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]); |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 3086 | } |
| 3087 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3088 | return 0; |
| 3089 | } |
| 3090 | |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3091 | static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev, |
| 3092 | struct cfg80211_ap_settings *params) |
| 3093 | { |
| 3094 | struct wireless_dev *wdev; |
| 3095 | bool ret = false; |
| 3096 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 3097 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3098 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 3099 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 3100 | continue; |
| 3101 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3102 | if (!wdev->preset_chandef.chan) |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3103 | continue; |
| 3104 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3105 | params->chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3106 | ret = true; |
| 3107 | break; |
| 3108 | } |
| 3109 | |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3110 | return ret; |
| 3111 | } |
| 3112 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 3113 | static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev, |
| 3114 | enum nl80211_auth_type auth_type, |
| 3115 | enum nl80211_commands cmd) |
| 3116 | { |
| 3117 | if (auth_type > NL80211_AUTHTYPE_MAX) |
| 3118 | return false; |
| 3119 | |
| 3120 | switch (cmd) { |
| 3121 | case NL80211_CMD_AUTHENTICATE: |
| 3122 | if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && |
| 3123 | auth_type == NL80211_AUTHTYPE_SAE) |
| 3124 | return false; |
| 3125 | return true; |
| 3126 | case NL80211_CMD_CONNECT: |
| 3127 | case NL80211_CMD_START_AP: |
| 3128 | /* SAE not supported yet */ |
| 3129 | if (auth_type == NL80211_AUTHTYPE_SAE) |
| 3130 | return false; |
| 3131 | return true; |
| 3132 | default: |
| 3133 | return false; |
| 3134 | } |
| 3135 | } |
| 3136 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3137 | static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) |
| 3138 | { |
| 3139 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3140 | struct net_device *dev = info->user_ptr[1]; |
| 3141 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3142 | struct cfg80211_ap_settings params; |
| 3143 | int err; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 3144 | u8 radar_detect_width = 0; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3145 | |
| 3146 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3147 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3148 | return -EOPNOTSUPP; |
| 3149 | |
| 3150 | if (!rdev->ops->start_ap) |
| 3151 | return -EOPNOTSUPP; |
| 3152 | |
| 3153 | if (wdev->beacon_interval) |
| 3154 | return -EALREADY; |
| 3155 | |
| 3156 | memset(¶ms, 0, sizeof(params)); |
| 3157 | |
| 3158 | /* these are required for START_AP */ |
| 3159 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || |
| 3160 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || |
| 3161 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) |
| 3162 | return -EINVAL; |
| 3163 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3164 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3165 | if (err) |
| 3166 | return err; |
| 3167 | |
| 3168 | params.beacon_interval = |
| 3169 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 3170 | params.dtim_period = |
| 3171 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 3172 | |
| 3173 | err = cfg80211_validate_beacon_int(rdev, params.beacon_interval); |
| 3174 | if (err) |
| 3175 | return err; |
| 3176 | |
| 3177 | /* |
| 3178 | * In theory, some of these attributes should be required here |
| 3179 | * but since they were not used when the command was originally |
| 3180 | * added, keep them optional for old user space programs to let |
| 3181 | * them continue to work with drivers that do not need the |
| 3182 | * additional information -- drivers must check! |
| 3183 | */ |
| 3184 | if (info->attrs[NL80211_ATTR_SSID]) { |
| 3185 | params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 3186 | params.ssid_len = |
| 3187 | nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 3188 | if (params.ssid_len == 0 || |
| 3189 | params.ssid_len > IEEE80211_MAX_SSID_LEN) |
| 3190 | return -EINVAL; |
| 3191 | } |
| 3192 | |
| 3193 | if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) { |
| 3194 | params.hidden_ssid = nla_get_u32( |
| 3195 | info->attrs[NL80211_ATTR_HIDDEN_SSID]); |
| 3196 | if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE && |
| 3197 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN && |
| 3198 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS) |
| 3199 | return -EINVAL; |
| 3200 | } |
| 3201 | |
| 3202 | params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
| 3203 | |
| 3204 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 3205 | params.auth_type = nla_get_u32( |
| 3206 | info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 3207 | if (!nl80211_valid_auth_type(rdev, params.auth_type, |
| 3208 | NL80211_CMD_START_AP)) |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3209 | return -EINVAL; |
| 3210 | } else |
| 3211 | params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 3212 | |
| 3213 | err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, |
| 3214 | NL80211_MAX_NR_CIPHER_SUITES); |
| 3215 | if (err) |
| 3216 | return err; |
| 3217 | |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 3218 | if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) { |
| 3219 | if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER)) |
| 3220 | return -EOPNOTSUPP; |
| 3221 | params.inactivity_timeout = nla_get_u16( |
| 3222 | info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]); |
| 3223 | } |
| 3224 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 3225 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 3226 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3227 | return -EINVAL; |
| 3228 | params.p2p_ctwindow = |
| 3229 | nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
| 3230 | if (params.p2p_ctwindow > 127) |
| 3231 | return -EINVAL; |
| 3232 | if (params.p2p_ctwindow != 0 && |
| 3233 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 3234 | return -EINVAL; |
| 3235 | } |
| 3236 | |
| 3237 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 3238 | u8 tmp; |
| 3239 | |
| 3240 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3241 | return -EINVAL; |
| 3242 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
| 3243 | if (tmp > 1) |
| 3244 | return -EINVAL; |
| 3245 | params.p2p_opp_ps = tmp; |
| 3246 | if (params.p2p_opp_ps != 0 && |
| 3247 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 3248 | return -EINVAL; |
| 3249 | } |
| 3250 | |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3251 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3252 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
| 3253 | if (err) |
| 3254 | return err; |
| 3255 | } else if (wdev->preset_chandef.chan) { |
| 3256 | params.chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3257 | } else if (!nl80211_get_ap_channel(rdev, ¶ms)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3258 | return -EINVAL; |
| 3259 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3260 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, ¶ms.chandef)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3261 | return -EINVAL; |
| 3262 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 3263 | err = cfg80211_chandef_dfs_required(wdev->wiphy, ¶ms.chandef); |
| 3264 | if (err < 0) |
| 3265 | return err; |
| 3266 | if (err) { |
| 3267 | radar_detect_width = BIT(params.chandef.width); |
| 3268 | params.radar_required = true; |
| 3269 | } |
| 3270 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 3271 | err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype, |
| 3272 | params.chandef.chan, |
| 3273 | CHAN_MODE_SHARED, |
| 3274 | radar_detect_width); |
Michal Kazior | e4e3245 | 2012-06-29 12:47:08 +0200 | [diff] [blame] | 3275 | if (err) |
| 3276 | return err; |
| 3277 | |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 3278 | if (info->attrs[NL80211_ATTR_ACL_POLICY]) { |
| 3279 | params.acl = parse_acl_data(&rdev->wiphy, info); |
| 3280 | if (IS_ERR(params.acl)) |
| 3281 | return PTR_ERR(params.acl); |
| 3282 | } |
| 3283 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 3284 | wdev_lock(wdev); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3285 | err = rdev_start_ap(rdev, dev, ¶ms); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3286 | if (!err) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3287 | wdev->preset_chandef = params.chandef; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3288 | wdev->beacon_interval = params.beacon_interval; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3289 | wdev->channel = params.chandef.chan; |
Antonio Quartulli | 06e191e | 2012-11-07 12:52:19 +0100 | [diff] [blame] | 3290 | wdev->ssid_len = params.ssid_len; |
| 3291 | memcpy(wdev->ssid, params.ssid, wdev->ssid_len); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3292 | } |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 3293 | wdev_unlock(wdev); |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 3294 | |
| 3295 | kfree(params.acl); |
| 3296 | |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 3297 | return err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3298 | } |
| 3299 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3300 | static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info) |
| 3301 | { |
| 3302 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3303 | struct net_device *dev = info->user_ptr[1]; |
| 3304 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3305 | struct cfg80211_beacon_data params; |
| 3306 | int err; |
| 3307 | |
| 3308 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3309 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3310 | return -EOPNOTSUPP; |
| 3311 | |
| 3312 | if (!rdev->ops->change_beacon) |
| 3313 | return -EOPNOTSUPP; |
| 3314 | |
| 3315 | if (!wdev->beacon_interval) |
| 3316 | return -EINVAL; |
| 3317 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3318 | err = nl80211_parse_beacon(info->attrs, ¶ms); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3319 | if (err) |
| 3320 | return err; |
| 3321 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 3322 | wdev_lock(wdev); |
| 3323 | err = rdev_change_beacon(rdev, dev, ¶ms); |
| 3324 | wdev_unlock(wdev); |
| 3325 | |
| 3326 | return err; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3327 | } |
| 3328 | |
| 3329 | 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] | 3330 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3331 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3332 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3333 | |
Michal Kazior | 6077178 | 2012-06-29 12:46:56 +0200 | [diff] [blame] | 3334 | return cfg80211_stop_ap(rdev, dev); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3335 | } |
| 3336 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3337 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
| 3338 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, |
| 3339 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, |
| 3340 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, |
Jouni Malinen | 0e46724 | 2009-05-11 21:57:55 +0300 | [diff] [blame] | 3341 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 3342 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
Johannes Berg | d83023d | 2011-12-14 09:29:15 +0100 | [diff] [blame] | 3343 | [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3344 | }; |
| 3345 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3346 | static int parse_station_flags(struct genl_info *info, |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3347 | enum nl80211_iftype iftype, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3348 | struct station_parameters *params) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3349 | { |
| 3350 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3351 | struct nlattr *nla; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3352 | int flag; |
| 3353 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3354 | /* |
| 3355 | * Try parsing the new attribute first so userspace |
| 3356 | * can specify both for older kernels. |
| 3357 | */ |
| 3358 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; |
| 3359 | if (nla) { |
| 3360 | struct nl80211_sta_flag_update *sta_flags; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3361 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3362 | sta_flags = nla_data(nla); |
| 3363 | params->sta_flags_mask = sta_flags->mask; |
| 3364 | params->sta_flags_set = sta_flags->set; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3365 | params->sta_flags_set &= params->sta_flags_mask; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3366 | if ((params->sta_flags_mask | |
| 3367 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) |
| 3368 | return -EINVAL; |
| 3369 | return 0; |
| 3370 | } |
| 3371 | |
| 3372 | /* if present, parse the old attribute */ |
| 3373 | |
| 3374 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3375 | if (!nla) |
| 3376 | return 0; |
| 3377 | |
| 3378 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, |
| 3379 | nla, sta_flags_policy)) |
| 3380 | return -EINVAL; |
| 3381 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3382 | /* |
| 3383 | * Only allow certain flags for interface types so that |
| 3384 | * other attributes are silently ignored. Remember that |
| 3385 | * this is backward compatibility code with old userspace |
| 3386 | * and shouldn't be hit in other cases anyway. |
| 3387 | */ |
| 3388 | switch (iftype) { |
| 3389 | case NL80211_IFTYPE_AP: |
| 3390 | case NL80211_IFTYPE_AP_VLAN: |
| 3391 | case NL80211_IFTYPE_P2P_GO: |
| 3392 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3393 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 3394 | BIT(NL80211_STA_FLAG_WME) | |
| 3395 | BIT(NL80211_STA_FLAG_MFP); |
| 3396 | break; |
| 3397 | case NL80211_IFTYPE_P2P_CLIENT: |
| 3398 | case NL80211_IFTYPE_STATION: |
| 3399 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3400 | BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3401 | break; |
| 3402 | case NL80211_IFTYPE_MESH_POINT: |
| 3403 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3404 | BIT(NL80211_STA_FLAG_MFP) | |
| 3405 | BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 3406 | default: |
| 3407 | return -EINVAL; |
| 3408 | } |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3409 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 3410 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) { |
| 3411 | if (flags[flag]) { |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3412 | params->sta_flags_set |= (1<<flag); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3413 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 3414 | /* no longer support new API additions in old API */ |
| 3415 | if (flag > NL80211_STA_FLAG_MAX_OLD_API) |
| 3416 | return -EINVAL; |
| 3417 | } |
| 3418 | } |
| 3419 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3420 | return 0; |
| 3421 | } |
| 3422 | |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3423 | static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, |
| 3424 | int attr) |
| 3425 | { |
| 3426 | struct nlattr *rate; |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 3427 | u32 bitrate; |
| 3428 | u16 bitrate_compat; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3429 | |
| 3430 | rate = nla_nest_start(msg, attr); |
| 3431 | if (!rate) |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 3432 | return false; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3433 | |
| 3434 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ |
| 3435 | bitrate = cfg80211_calculate_bitrate(info); |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 3436 | /* report 16-bit bitrate only if we can */ |
| 3437 | bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 3438 | if (bitrate > 0 && |
| 3439 | nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate)) |
| 3440 | return false; |
| 3441 | if (bitrate_compat > 0 && |
| 3442 | nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat)) |
| 3443 | return false; |
| 3444 | |
| 3445 | if (info->flags & RATE_INFO_FLAGS_MCS) { |
| 3446 | if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) |
| 3447 | return false; |
| 3448 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && |
| 3449 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) |
| 3450 | return false; |
| 3451 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 3452 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 3453 | return false; |
| 3454 | } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) { |
| 3455 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs)) |
| 3456 | return false; |
| 3457 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss)) |
| 3458 | return false; |
| 3459 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && |
| 3460 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) |
| 3461 | return false; |
| 3462 | if (info->flags & RATE_INFO_FLAGS_80_MHZ_WIDTH && |
| 3463 | nla_put_flag(msg, NL80211_RATE_INFO_80_MHZ_WIDTH)) |
| 3464 | return false; |
| 3465 | if (info->flags & RATE_INFO_FLAGS_80P80_MHZ_WIDTH && |
| 3466 | nla_put_flag(msg, NL80211_RATE_INFO_80P80_MHZ_WIDTH)) |
| 3467 | return false; |
| 3468 | if (info->flags & RATE_INFO_FLAGS_160_MHZ_WIDTH && |
| 3469 | nla_put_flag(msg, NL80211_RATE_INFO_160_MHZ_WIDTH)) |
| 3470 | return false; |
| 3471 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 3472 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 3473 | return false; |
| 3474 | } |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3475 | |
| 3476 | nla_nest_end(msg, rate); |
| 3477 | return true; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3478 | } |
| 3479 | |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 3480 | static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal, |
| 3481 | int id) |
| 3482 | { |
| 3483 | void *attr; |
| 3484 | int i = 0; |
| 3485 | |
| 3486 | if (!mask) |
| 3487 | return true; |
| 3488 | |
| 3489 | attr = nla_nest_start(msg, id); |
| 3490 | if (!attr) |
| 3491 | return false; |
| 3492 | |
| 3493 | for (i = 0; i < IEEE80211_MAX_CHAINS; i++) { |
| 3494 | if (!(mask & BIT(i))) |
| 3495 | continue; |
| 3496 | |
| 3497 | if (nla_put_u8(msg, i, signal[i])) |
| 3498 | return false; |
| 3499 | } |
| 3500 | |
| 3501 | nla_nest_end(msg, attr); |
| 3502 | |
| 3503 | return true; |
| 3504 | } |
| 3505 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3506 | 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] | 3507 | int flags, |
| 3508 | struct cfg80211_registered_device *rdev, |
| 3509 | struct net_device *dev, |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 3510 | const u8 *mac_addr, struct station_info *sinfo) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3511 | { |
| 3512 | void *hdr; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3513 | struct nlattr *sinfoattr, *bss_param; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3514 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3515 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3516 | if (!hdr) |
| 3517 | return -1; |
| 3518 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3519 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 3520 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 3521 | nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation)) |
| 3522 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 3523 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3524 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
| 3525 | if (!sinfoattr) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3526 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3527 | if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) && |
| 3528 | nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME, |
| 3529 | sinfo->connected_time)) |
| 3530 | goto nla_put_failure; |
| 3531 | if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) && |
| 3532 | nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME, |
| 3533 | sinfo->inactive_time)) |
| 3534 | goto nla_put_failure; |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3535 | if ((sinfo->filled & (STATION_INFO_RX_BYTES | |
| 3536 | STATION_INFO_RX_BYTES64)) && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3537 | nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES, |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3538 | (u32)sinfo->rx_bytes)) |
| 3539 | goto nla_put_failure; |
| 3540 | if ((sinfo->filled & (STATION_INFO_TX_BYTES | |
Felix Fietkau | 4325d72 | 2013-05-23 15:05:59 +0200 | [diff] [blame] | 3541 | STATION_INFO_TX_BYTES64)) && |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3542 | nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES, |
| 3543 | (u32)sinfo->tx_bytes)) |
| 3544 | goto nla_put_failure; |
| 3545 | if ((sinfo->filled & STATION_INFO_RX_BYTES64) && |
| 3546 | nla_put_u64(msg, NL80211_STA_INFO_RX_BYTES64, |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3547 | sinfo->rx_bytes)) |
| 3548 | goto nla_put_failure; |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3549 | if ((sinfo->filled & STATION_INFO_TX_BYTES64) && |
| 3550 | nla_put_u64(msg, NL80211_STA_INFO_TX_BYTES64, |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3551 | sinfo->tx_bytes)) |
| 3552 | goto nla_put_failure; |
| 3553 | if ((sinfo->filled & STATION_INFO_LLID) && |
| 3554 | nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid)) |
| 3555 | goto nla_put_failure; |
| 3556 | if ((sinfo->filled & STATION_INFO_PLID) && |
| 3557 | nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid)) |
| 3558 | goto nla_put_failure; |
| 3559 | if ((sinfo->filled & STATION_INFO_PLINK_STATE) && |
| 3560 | nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE, |
| 3561 | sinfo->plink_state)) |
| 3562 | goto nla_put_failure; |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3563 | switch (rdev->wiphy.signal_type) { |
| 3564 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3565 | if ((sinfo->filled & STATION_INFO_SIGNAL) && |
| 3566 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL, |
| 3567 | sinfo->signal)) |
| 3568 | goto nla_put_failure; |
| 3569 | if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) && |
| 3570 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG, |
| 3571 | sinfo->signal_avg)) |
| 3572 | goto nla_put_failure; |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3573 | break; |
| 3574 | default: |
| 3575 | break; |
| 3576 | } |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 3577 | if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL) { |
| 3578 | if (!nl80211_put_signal(msg, sinfo->chains, |
| 3579 | sinfo->chain_signal, |
| 3580 | NL80211_STA_INFO_CHAIN_SIGNAL)) |
| 3581 | goto nla_put_failure; |
| 3582 | } |
| 3583 | if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL_AVG) { |
| 3584 | if (!nl80211_put_signal(msg, sinfo->chains, |
| 3585 | sinfo->chain_signal_avg, |
| 3586 | NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) |
| 3587 | goto nla_put_failure; |
| 3588 | } |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3589 | if (sinfo->filled & STATION_INFO_TX_BITRATE) { |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3590 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
| 3591 | NL80211_STA_INFO_TX_BITRATE)) |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3592 | goto nla_put_failure; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3593 | } |
| 3594 | if (sinfo->filled & STATION_INFO_RX_BITRATE) { |
| 3595 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, |
| 3596 | NL80211_STA_INFO_RX_BITRATE)) |
| 3597 | goto nla_put_failure; |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3598 | } |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3599 | if ((sinfo->filled & STATION_INFO_RX_PACKETS) && |
| 3600 | nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS, |
| 3601 | sinfo->rx_packets)) |
| 3602 | goto nla_put_failure; |
| 3603 | if ((sinfo->filled & STATION_INFO_TX_PACKETS) && |
| 3604 | nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS, |
| 3605 | sinfo->tx_packets)) |
| 3606 | goto nla_put_failure; |
| 3607 | if ((sinfo->filled & STATION_INFO_TX_RETRIES) && |
| 3608 | nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES, |
| 3609 | sinfo->tx_retries)) |
| 3610 | goto nla_put_failure; |
| 3611 | if ((sinfo->filled & STATION_INFO_TX_FAILED) && |
| 3612 | nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED, |
| 3613 | sinfo->tx_failed)) |
| 3614 | goto nla_put_failure; |
| 3615 | if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) && |
| 3616 | nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS, |
| 3617 | sinfo->beacon_loss_count)) |
| 3618 | goto nla_put_failure; |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 3619 | if ((sinfo->filled & STATION_INFO_LOCAL_PM) && |
| 3620 | nla_put_u32(msg, NL80211_STA_INFO_LOCAL_PM, |
| 3621 | sinfo->local_pm)) |
| 3622 | goto nla_put_failure; |
| 3623 | if ((sinfo->filled & STATION_INFO_PEER_PM) && |
| 3624 | nla_put_u32(msg, NL80211_STA_INFO_PEER_PM, |
| 3625 | sinfo->peer_pm)) |
| 3626 | goto nla_put_failure; |
| 3627 | if ((sinfo->filled & STATION_INFO_NONPEER_PM) && |
| 3628 | nla_put_u32(msg, NL80211_STA_INFO_NONPEER_PM, |
| 3629 | sinfo->nonpeer_pm)) |
| 3630 | goto nla_put_failure; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3631 | if (sinfo->filled & STATION_INFO_BSS_PARAM) { |
| 3632 | bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); |
| 3633 | if (!bss_param) |
| 3634 | goto nla_put_failure; |
| 3635 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3636 | if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) && |
| 3637 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) || |
| 3638 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) && |
| 3639 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) || |
| 3640 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) && |
| 3641 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) || |
| 3642 | nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, |
| 3643 | sinfo->bss_param.dtim_period) || |
| 3644 | nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, |
| 3645 | sinfo->bss_param.beacon_interval)) |
| 3646 | goto nla_put_failure; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3647 | |
| 3648 | nla_nest_end(msg, bss_param); |
| 3649 | } |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3650 | if ((sinfo->filled & STATION_INFO_STA_FLAGS) && |
| 3651 | nla_put(msg, NL80211_STA_INFO_STA_FLAGS, |
| 3652 | sizeof(struct nl80211_sta_flag_update), |
| 3653 | &sinfo->sta_flags)) |
| 3654 | goto nla_put_failure; |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 3655 | if ((sinfo->filled & STATION_INFO_T_OFFSET) && |
| 3656 | nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET, |
| 3657 | sinfo->t_offset)) |
| 3658 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3659 | nla_nest_end(msg, sinfoattr); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3660 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3661 | if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) && |
| 3662 | nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, |
| 3663 | sinfo->assoc_req_ies)) |
| 3664 | goto nla_put_failure; |
Jouni Malinen | 50d3dfb | 2011-08-08 12:11:52 +0300 | [diff] [blame] | 3665 | |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3666 | return genlmsg_end(msg, hdr); |
| 3667 | |
| 3668 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 3669 | genlmsg_cancel(msg, hdr); |
| 3670 | return -EMSGSIZE; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3671 | } |
| 3672 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3673 | static int nl80211_dump_station(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3674 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3675 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3676 | struct station_info sinfo; |
| 3677 | struct cfg80211_registered_device *dev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3678 | struct wireless_dev *wdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3679 | u8 mac_addr[ETH_ALEN]; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3680 | int sta_idx = cb->args[2]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3681 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3682 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3683 | err = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3684 | if (err) |
| 3685 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3686 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3687 | if (!wdev->netdev) { |
| 3688 | err = -EINVAL; |
| 3689 | goto out_err; |
| 3690 | } |
| 3691 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3692 | if (!dev->ops->dump_station) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3693 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3694 | goto out_err; |
| 3695 | } |
| 3696 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3697 | while (1) { |
Jouni Malinen | f612ced | 2011-08-11 11:46:22 +0300 | [diff] [blame] | 3698 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3699 | err = rdev_dump_station(dev, wdev->netdev, sta_idx, |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3700 | mac_addr, &sinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3701 | if (err == -ENOENT) |
| 3702 | break; |
| 3703 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3704 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3705 | |
| 3706 | if (nl80211_send_station(skb, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3707 | NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3708 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3709 | dev, wdev->netdev, mac_addr, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3710 | &sinfo) < 0) |
| 3711 | goto out; |
| 3712 | |
| 3713 | sta_idx++; |
| 3714 | } |
| 3715 | |
| 3716 | |
| 3717 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3718 | cb->args[2] = sta_idx; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3719 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3720 | out_err: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3721 | nl80211_finish_wdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3722 | |
| 3723 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3724 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3725 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3726 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
| 3727 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3728 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3729 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3730 | struct station_info sinfo; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3731 | struct sk_buff *msg; |
| 3732 | u8 *mac_addr = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3733 | int err; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3734 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3735 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3736 | |
| 3737 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3738 | return -EINVAL; |
| 3739 | |
| 3740 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3741 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3742 | if (!rdev->ops->get_station) |
| 3743 | return -EOPNOTSUPP; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3744 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3745 | err = rdev_get_station(rdev, dev, mac_addr, &sinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3746 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3747 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3748 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3749 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3750 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3751 | return -ENOMEM; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3752 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3753 | 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] | 3754 | rdev, dev, mac_addr, &sinfo) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3755 | nlmsg_free(msg); |
| 3756 | return -ENOBUFS; |
| 3757 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3758 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3759 | return genlmsg_reply(msg, info); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3760 | } |
| 3761 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3762 | int cfg80211_check_station_change(struct wiphy *wiphy, |
| 3763 | struct station_parameters *params, |
| 3764 | enum cfg80211_station_type statype) |
| 3765 | { |
| 3766 | if (params->listen_interval != -1) |
| 3767 | return -EINVAL; |
| 3768 | if (params->aid) |
| 3769 | return -EINVAL; |
| 3770 | |
| 3771 | /* When you run into this, adjust the code below for the new flag */ |
| 3772 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); |
| 3773 | |
| 3774 | switch (statype) { |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 3775 | case CFG80211_STA_MESH_PEER_KERNEL: |
| 3776 | case CFG80211_STA_MESH_PEER_USER: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3777 | /* |
| 3778 | * No ignoring the TDLS flag here -- the userspace mesh |
| 3779 | * code doesn't have the bug of including TDLS in the |
| 3780 | * mask everywhere. |
| 3781 | */ |
| 3782 | if (params->sta_flags_mask & |
| 3783 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3784 | BIT(NL80211_STA_FLAG_MFP) | |
| 3785 | BIT(NL80211_STA_FLAG_AUTHORIZED))) |
| 3786 | return -EINVAL; |
| 3787 | break; |
| 3788 | case CFG80211_STA_TDLS_PEER_SETUP: |
| 3789 | case CFG80211_STA_TDLS_PEER_ACTIVE: |
| 3790 | if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 3791 | return -EINVAL; |
| 3792 | /* ignore since it can't change */ |
| 3793 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3794 | break; |
| 3795 | default: |
| 3796 | /* disallow mesh-specific things */ |
| 3797 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) |
| 3798 | return -EINVAL; |
| 3799 | if (params->local_pm) |
| 3800 | return -EINVAL; |
| 3801 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
| 3802 | return -EINVAL; |
| 3803 | } |
| 3804 | |
| 3805 | if (statype != CFG80211_STA_TDLS_PEER_SETUP && |
| 3806 | statype != CFG80211_STA_TDLS_PEER_ACTIVE) { |
| 3807 | /* TDLS can't be set, ... */ |
| 3808 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
| 3809 | return -EINVAL; |
| 3810 | /* |
| 3811 | * ... but don't bother the driver with it. This works around |
| 3812 | * a hostapd/wpa_supplicant issue -- it always includes the |
| 3813 | * TLDS_PEER flag in the mask even for AP mode. |
| 3814 | */ |
| 3815 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3816 | } |
| 3817 | |
| 3818 | if (statype != CFG80211_STA_TDLS_PEER_SETUP) { |
| 3819 | /* reject other things that can't change */ |
| 3820 | if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) |
| 3821 | return -EINVAL; |
| 3822 | if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY) |
| 3823 | return -EINVAL; |
| 3824 | if (params->supported_rates) |
| 3825 | return -EINVAL; |
| 3826 | if (params->ext_capab || params->ht_capa || params->vht_capa) |
| 3827 | return -EINVAL; |
| 3828 | } |
| 3829 | |
| 3830 | if (statype != CFG80211_STA_AP_CLIENT) { |
| 3831 | if (params->vlan) |
| 3832 | return -EINVAL; |
| 3833 | } |
| 3834 | |
| 3835 | switch (statype) { |
| 3836 | case CFG80211_STA_AP_MLME_CLIENT: |
| 3837 | /* Use this only for authorizing/unauthorizing a station */ |
| 3838 | if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))) |
| 3839 | return -EOPNOTSUPP; |
| 3840 | break; |
| 3841 | case CFG80211_STA_AP_CLIENT: |
| 3842 | /* accept only the listed bits */ |
| 3843 | if (params->sta_flags_mask & |
| 3844 | ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3845 | BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3846 | BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 3847 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 3848 | BIT(NL80211_STA_FLAG_WME) | |
| 3849 | BIT(NL80211_STA_FLAG_MFP))) |
| 3850 | return -EINVAL; |
| 3851 | |
| 3852 | /* but authenticated/associated only if driver handles it */ |
| 3853 | if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
| 3854 | params->sta_flags_mask & |
| 3855 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3856 | BIT(NL80211_STA_FLAG_ASSOCIATED))) |
| 3857 | return -EINVAL; |
| 3858 | break; |
| 3859 | case CFG80211_STA_IBSS: |
| 3860 | case CFG80211_STA_AP_STA: |
| 3861 | /* reject any changes other than AUTHORIZED */ |
| 3862 | if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) |
| 3863 | return -EINVAL; |
| 3864 | break; |
| 3865 | case CFG80211_STA_TDLS_PEER_SETUP: |
| 3866 | /* reject any changes other than AUTHORIZED or WME */ |
| 3867 | if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3868 | BIT(NL80211_STA_FLAG_WME))) |
| 3869 | return -EINVAL; |
| 3870 | /* force (at least) rates when authorizing */ |
| 3871 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) && |
| 3872 | !params->supported_rates) |
| 3873 | return -EINVAL; |
| 3874 | break; |
| 3875 | case CFG80211_STA_TDLS_PEER_ACTIVE: |
| 3876 | /* reject any changes */ |
| 3877 | return -EINVAL; |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 3878 | case CFG80211_STA_MESH_PEER_KERNEL: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3879 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
| 3880 | return -EINVAL; |
| 3881 | break; |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 3882 | case CFG80211_STA_MESH_PEER_USER: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3883 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) |
| 3884 | return -EINVAL; |
| 3885 | break; |
| 3886 | } |
| 3887 | |
| 3888 | return 0; |
| 3889 | } |
| 3890 | EXPORT_SYMBOL(cfg80211_check_station_change); |
| 3891 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3892 | /* |
Felix Fietkau | c258d2d | 2009-11-11 17:23:31 +0100 | [diff] [blame] | 3893 | * 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] | 3894 | */ |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3895 | static struct net_device *get_vlan(struct genl_info *info, |
| 3896 | struct cfg80211_registered_device *rdev) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3897 | { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3898 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3899 | struct net_device *v; |
| 3900 | int ret; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3901 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3902 | if (!vlanattr) |
| 3903 | return NULL; |
| 3904 | |
| 3905 | v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); |
| 3906 | if (!v) |
| 3907 | return ERR_PTR(-ENODEV); |
| 3908 | |
| 3909 | if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { |
| 3910 | ret = -EINVAL; |
| 3911 | goto error; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3912 | } |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3913 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3914 | if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
| 3915 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3916 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { |
| 3917 | ret = -EINVAL; |
| 3918 | goto error; |
| 3919 | } |
| 3920 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3921 | if (!netif_running(v)) { |
| 3922 | ret = -ENETDOWN; |
| 3923 | goto error; |
| 3924 | } |
| 3925 | |
| 3926 | return v; |
| 3927 | error: |
| 3928 | dev_put(v); |
| 3929 | return ERR_PTR(ret); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3930 | } |
| 3931 | |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3932 | static struct nla_policy |
| 3933 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] __read_mostly = { |
| 3934 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, |
| 3935 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, |
| 3936 | }; |
| 3937 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 3938 | static int nl80211_parse_sta_wme(struct genl_info *info, |
| 3939 | struct station_parameters *params) |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3940 | { |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3941 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; |
| 3942 | struct nlattr *nla; |
| 3943 | int err; |
| 3944 | |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3945 | /* parse WME attributes if present */ |
| 3946 | if (!info->attrs[NL80211_ATTR_STA_WME]) |
| 3947 | return 0; |
| 3948 | |
| 3949 | nla = info->attrs[NL80211_ATTR_STA_WME]; |
| 3950 | err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla, |
| 3951 | nl80211_sta_wme_policy); |
| 3952 | if (err) |
| 3953 | return err; |
| 3954 | |
| 3955 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) |
| 3956 | params->uapsd_queues = nla_get_u8( |
| 3957 | tb[NL80211_STA_WME_UAPSD_QUEUES]); |
| 3958 | if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) |
| 3959 | return -EINVAL; |
| 3960 | |
| 3961 | if (tb[NL80211_STA_WME_MAX_SP]) |
| 3962 | params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); |
| 3963 | |
| 3964 | if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) |
| 3965 | return -EINVAL; |
| 3966 | |
| 3967 | params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; |
| 3968 | |
| 3969 | return 0; |
| 3970 | } |
| 3971 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 3972 | static int nl80211_parse_sta_channel_info(struct genl_info *info, |
| 3973 | struct station_parameters *params) |
| 3974 | { |
| 3975 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) { |
| 3976 | params->supported_channels = |
| 3977 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); |
| 3978 | params->supported_channels_len = |
| 3979 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); |
| 3980 | /* |
| 3981 | * Need to include at least one (first channel, number of |
| 3982 | * channels) tuple for each subband, and must have proper |
| 3983 | * tuples for the rest of the data as well. |
| 3984 | */ |
| 3985 | if (params->supported_channels_len < 2) |
| 3986 | return -EINVAL; |
| 3987 | if (params->supported_channels_len % 2) |
| 3988 | return -EINVAL; |
| 3989 | } |
| 3990 | |
| 3991 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) { |
| 3992 | params->supported_oper_classes = |
| 3993 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); |
| 3994 | params->supported_oper_classes_len = |
| 3995 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); |
| 3996 | /* |
| 3997 | * The value of the Length field of the Supported Operating |
| 3998 | * Classes element is between 2 and 253. |
| 3999 | */ |
| 4000 | if (params->supported_oper_classes_len < 2 || |
| 4001 | params->supported_oper_classes_len > 253) |
| 4002 | return -EINVAL; |
| 4003 | } |
| 4004 | return 0; |
| 4005 | } |
| 4006 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4007 | static int nl80211_set_station_tdls(struct genl_info *info, |
| 4008 | struct station_parameters *params) |
| 4009 | { |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 4010 | int err; |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4011 | /* Dummy STA entry gets updated once the peer capabilities are known */ |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 4012 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
| 4013 | params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4014 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 4015 | params->ht_capa = |
| 4016 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
| 4017 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 4018 | params->vht_capa = |
| 4019 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 4020 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 4021 | err = nl80211_parse_sta_channel_info(info, params); |
| 4022 | if (err) |
| 4023 | return err; |
| 4024 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4025 | return nl80211_parse_sta_wme(info, params); |
| 4026 | } |
| 4027 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4028 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
| 4029 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4030 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4031 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4032 | struct station_parameters params; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4033 | u8 *mac_addr; |
| 4034 | int err; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4035 | |
| 4036 | memset(¶ms, 0, sizeof(params)); |
| 4037 | |
| 4038 | params.listen_interval = -1; |
| 4039 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4040 | if (!rdev->ops->change_station) |
| 4041 | return -EOPNOTSUPP; |
| 4042 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4043 | if (info->attrs[NL80211_ATTR_STA_AID]) |
| 4044 | return -EINVAL; |
| 4045 | |
| 4046 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4047 | return -EINVAL; |
| 4048 | |
| 4049 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4050 | |
| 4051 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { |
| 4052 | params.supported_rates = |
| 4053 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4054 | params.supported_rates_len = |
| 4055 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4056 | } |
| 4057 | |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 4058 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
| 4059 | params.capability = |
| 4060 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); |
| 4061 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; |
| 4062 | } |
| 4063 | |
| 4064 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { |
| 4065 | params.ext_capab = |
| 4066 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4067 | params.ext_capab_len = |
| 4068 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4069 | } |
| 4070 | |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 4071 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
Johannes Berg | ba23d20 | 2012-12-27 17:32:09 +0100 | [diff] [blame] | 4072 | return -EINVAL; |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 4073 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 4074 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4075 | return -EINVAL; |
| 4076 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4077 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4078 | params.plink_action = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4079 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 4080 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) |
| 4081 | return -EINVAL; |
| 4082 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4083 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4084 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) { |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 4085 | params.plink_state = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4086 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
| 4087 | if (params.plink_state >= NUM_NL80211_PLINK_STATES) |
| 4088 | return -EINVAL; |
| 4089 | params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE; |
| 4090 | } |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 4091 | |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4092 | if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) { |
| 4093 | enum nl80211_mesh_power_mode pm = nla_get_u32( |
| 4094 | info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]); |
| 4095 | |
| 4096 | if (pm <= NL80211_MESH_POWER_UNKNOWN || |
| 4097 | pm > NL80211_MESH_POWER_MAX) |
| 4098 | return -EINVAL; |
| 4099 | |
| 4100 | params.local_pm = pm; |
| 4101 | } |
| 4102 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4103 | /* Include parameters for TDLS peer (will check later) */ |
| 4104 | err = nl80211_set_station_tdls(info, ¶ms); |
| 4105 | if (err) |
| 4106 | return err; |
| 4107 | |
| 4108 | params.vlan = get_vlan(info, rdev); |
| 4109 | if (IS_ERR(params.vlan)) |
| 4110 | return PTR_ERR(params.vlan); |
| 4111 | |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4112 | switch (dev->ieee80211_ptr->iftype) { |
| 4113 | case NL80211_IFTYPE_AP: |
| 4114 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4115 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4116 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4117 | case NL80211_IFTYPE_STATION: |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 4118 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4119 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4120 | break; |
| 4121 | default: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4122 | err = -EOPNOTSUPP; |
| 4123 | goto out_put_vlan; |
Johannes Berg | 034d655 | 2009-05-27 10:35:29 +0200 | [diff] [blame] | 4124 | } |
| 4125 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4126 | /* driver will call cfg80211_check_station_change() */ |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4127 | err = rdev_change_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4128 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4129 | out_put_vlan: |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4130 | if (params.vlan) |
| 4131 | dev_put(params.vlan); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4132 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4133 | return err; |
| 4134 | } |
| 4135 | |
| 4136 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) |
| 4137 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4138 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4139 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4140 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4141 | struct station_parameters params; |
| 4142 | u8 *mac_addr = NULL; |
| 4143 | |
| 4144 | memset(¶ms, 0, sizeof(params)); |
| 4145 | |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4146 | if (!rdev->ops->add_station) |
| 4147 | return -EOPNOTSUPP; |
| 4148 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4149 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4150 | return -EINVAL; |
| 4151 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4152 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 4153 | return -EINVAL; |
| 4154 | |
| 4155 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) |
| 4156 | return -EINVAL; |
| 4157 | |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 4158 | if (!info->attrs[NL80211_ATTR_STA_AID] && |
| 4159 | !info->attrs[NL80211_ATTR_PEER_AID]) |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 4160 | return -EINVAL; |
| 4161 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4162 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4163 | params.supported_rates = |
| 4164 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4165 | params.supported_rates_len = |
| 4166 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4167 | params.listen_interval = |
| 4168 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 4169 | |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4170 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 4171 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4172 | else |
| 4173 | 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] | 4174 | if (!params.aid || params.aid > IEEE80211_MAX_AID) |
| 4175 | return -EINVAL; |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 4176 | |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 4177 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
| 4178 | params.capability = |
| 4179 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); |
| 4180 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; |
| 4181 | } |
| 4182 | |
| 4183 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { |
| 4184 | params.ext_capab = |
| 4185 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4186 | params.ext_capab_len = |
| 4187 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4188 | } |
| 4189 | |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 4190 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 4191 | params.ht_capa = |
| 4192 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4193 | |
Mahesh Palivela | f461be3e | 2012-10-11 08:04:52 +0000 | [diff] [blame] | 4194 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 4195 | params.vht_capa = |
| 4196 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 4197 | |
Marek Kwaczynski | 60f4a7b | 2013-12-03 10:04:59 +0100 | [diff] [blame] | 4198 | if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) { |
| 4199 | params.opmode_notif_used = true; |
| 4200 | params.opmode_notif = |
| 4201 | nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]); |
| 4202 | } |
| 4203 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4204 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 4205 | params.plink_action = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4206 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 4207 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) |
| 4208 | return -EINVAL; |
| 4209 | } |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 4210 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 4211 | err = nl80211_parse_sta_channel_info(info, ¶ms); |
| 4212 | if (err) |
| 4213 | return err; |
| 4214 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4215 | err = nl80211_parse_sta_wme(info, ¶ms); |
| 4216 | if (err) |
| 4217 | return err; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4218 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 4219 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4220 | return -EINVAL; |
| 4221 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4222 | /* When you run into this, adjust the code below for the new flag */ |
| 4223 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); |
| 4224 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4225 | switch (dev->ieee80211_ptr->iftype) { |
| 4226 | case NL80211_IFTYPE_AP: |
| 4227 | case NL80211_IFTYPE_AP_VLAN: |
| 4228 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4229 | /* ignore WME attributes if iface/sta is not capable */ |
| 4230 | if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) || |
| 4231 | !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) |
| 4232 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4233 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4234 | /* TDLS peers cannot be added */ |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4235 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
| 4236 | info->attrs[NL80211_ATTR_PEER_AID]) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 4237 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4238 | /* but don't bother the driver with it */ |
| 4239 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4240 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4241 | /* allow authenticated/associated only if driver handles it */ |
| 4242 | if (!(rdev->wiphy.features & |
| 4243 | NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
| 4244 | params.sta_flags_mask & |
| 4245 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 4246 | BIT(NL80211_STA_FLAG_ASSOCIATED))) |
| 4247 | return -EINVAL; |
| 4248 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4249 | /* must be last in here for error handling */ |
| 4250 | params.vlan = get_vlan(info, rdev); |
| 4251 | if (IS_ERR(params.vlan)) |
| 4252 | return PTR_ERR(params.vlan); |
| 4253 | break; |
| 4254 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4255 | /* ignore uAPSD data */ |
| 4256 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
| 4257 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4258 | /* associated is disallowed */ |
| 4259 | if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) |
| 4260 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4261 | /* TDLS peers cannot be added */ |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4262 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
| 4263 | info->attrs[NL80211_ATTR_PEER_AID]) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 4264 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4265 | break; |
| 4266 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 93d08f0 | 2013-03-04 09:29:46 +0100 | [diff] [blame] | 4267 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4268 | /* ignore uAPSD data */ |
| 4269 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
| 4270 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4271 | /* these are disallowed */ |
| 4272 | if (params.sta_flags_mask & |
| 4273 | (BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 4274 | BIT(NL80211_STA_FLAG_AUTHENTICATED))) |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4275 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4276 | /* Only TDLS peers can be added */ |
| 4277 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 4278 | return -EINVAL; |
| 4279 | /* Can only add if TDLS ... */ |
| 4280 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) |
| 4281 | return -EOPNOTSUPP; |
| 4282 | /* ... with external setup is supported */ |
| 4283 | if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) |
| 4284 | return -EOPNOTSUPP; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4285 | /* |
| 4286 | * Older wpa_supplicant versions always mark the TDLS peer |
| 4287 | * as authorized, but it shouldn't yet be. |
| 4288 | */ |
| 4289 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED); |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4290 | break; |
| 4291 | default: |
| 4292 | return -EOPNOTSUPP; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4293 | } |
| 4294 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4295 | /* be aware of params.vlan when changing code here */ |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4296 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4297 | err = rdev_add_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4298 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4299 | if (params.vlan) |
| 4300 | dev_put(params.vlan); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4301 | return err; |
| 4302 | } |
| 4303 | |
| 4304 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) |
| 4305 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4306 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4307 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4308 | u8 *mac_addr = NULL; |
| 4309 | |
| 4310 | if (info->attrs[NL80211_ATTR_MAC]) |
| 4311 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4312 | |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 4313 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Marco Porsch | d5d9de0 | 2010-03-30 10:00:16 +0200 | [diff] [blame] | 4314 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4315 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4316 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4317 | return -EINVAL; |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 4318 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4319 | if (!rdev->ops->del_station) |
| 4320 | return -EOPNOTSUPP; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4321 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4322 | return rdev_del_station(rdev, dev, mac_addr); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4323 | } |
| 4324 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4325 | 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] | 4326 | int flags, struct net_device *dev, |
| 4327 | u8 *dst, u8 *next_hop, |
| 4328 | struct mpath_info *pinfo) |
| 4329 | { |
| 4330 | void *hdr; |
| 4331 | struct nlattr *pinfoattr; |
| 4332 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4333 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4334 | if (!hdr) |
| 4335 | return -1; |
| 4336 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4337 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 4338 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || |
| 4339 | nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) || |
| 4340 | nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation)) |
| 4341 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 4342 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4343 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
| 4344 | if (!pinfoattr) |
| 4345 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4346 | if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) && |
| 4347 | nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN, |
| 4348 | pinfo->frame_qlen)) |
| 4349 | goto nla_put_failure; |
| 4350 | if (((pinfo->filled & MPATH_INFO_SN) && |
| 4351 | nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) || |
| 4352 | ((pinfo->filled & MPATH_INFO_METRIC) && |
| 4353 | nla_put_u32(msg, NL80211_MPATH_INFO_METRIC, |
| 4354 | pinfo->metric)) || |
| 4355 | ((pinfo->filled & MPATH_INFO_EXPTIME) && |
| 4356 | nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME, |
| 4357 | pinfo->exptime)) || |
| 4358 | ((pinfo->filled & MPATH_INFO_FLAGS) && |
| 4359 | nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS, |
| 4360 | pinfo->flags)) || |
| 4361 | ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) && |
| 4362 | nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, |
| 4363 | pinfo->discovery_timeout)) || |
| 4364 | ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) && |
| 4365 | nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, |
| 4366 | pinfo->discovery_retries))) |
| 4367 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4368 | |
| 4369 | nla_nest_end(msg, pinfoattr); |
| 4370 | |
| 4371 | return genlmsg_end(msg, hdr); |
| 4372 | |
| 4373 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 4374 | genlmsg_cancel(msg, hdr); |
| 4375 | return -EMSGSIZE; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4376 | } |
| 4377 | |
| 4378 | static int nl80211_dump_mpath(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4379 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4380 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4381 | struct mpath_info pinfo; |
| 4382 | struct cfg80211_registered_device *dev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4383 | struct wireless_dev *wdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4384 | u8 dst[ETH_ALEN]; |
| 4385 | u8 next_hop[ETH_ALEN]; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4386 | int path_idx = cb->args[2]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4387 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4388 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4389 | err = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4390 | if (err) |
| 4391 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4392 | |
| 4393 | if (!dev->ops->dump_mpath) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4394 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4395 | goto out_err; |
| 4396 | } |
| 4397 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4398 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4399 | err = -EOPNOTSUPP; |
Roel Kluin | 0448b5f | 2009-08-22 21:15:49 +0200 | [diff] [blame] | 4400 | goto out_err; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4401 | } |
| 4402 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4403 | while (1) { |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4404 | err = rdev_dump_mpath(dev, wdev->netdev, path_idx, dst, |
| 4405 | next_hop, &pinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4406 | if (err == -ENOENT) |
| 4407 | break; |
| 4408 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4409 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4410 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4411 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4412 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4413 | wdev->netdev, dst, next_hop, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4414 | &pinfo) < 0) |
| 4415 | goto out; |
| 4416 | |
| 4417 | path_idx++; |
| 4418 | } |
| 4419 | |
| 4420 | |
| 4421 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4422 | cb->args[2] = path_idx; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4423 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4424 | out_err: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4425 | nl80211_finish_wdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4426 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4427 | } |
| 4428 | |
| 4429 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4430 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4431 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4432 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4433 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4434 | struct mpath_info pinfo; |
| 4435 | struct sk_buff *msg; |
| 4436 | u8 *dst = NULL; |
| 4437 | u8 next_hop[ETH_ALEN]; |
| 4438 | |
| 4439 | memset(&pinfo, 0, sizeof(pinfo)); |
| 4440 | |
| 4441 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4442 | return -EINVAL; |
| 4443 | |
| 4444 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4445 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4446 | if (!rdev->ops->get_mpath) |
| 4447 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4448 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4449 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4450 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4451 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4452 | err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4453 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4454 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4455 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4456 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4457 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4458 | return -ENOMEM; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4459 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4460 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4461 | dev, dst, next_hop, &pinfo) < 0) { |
| 4462 | nlmsg_free(msg); |
| 4463 | return -ENOBUFS; |
| 4464 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4465 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4466 | return genlmsg_reply(msg, info); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4467 | } |
| 4468 | |
| 4469 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4470 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4471 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4472 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4473 | u8 *dst = NULL; |
| 4474 | u8 *next_hop = NULL; |
| 4475 | |
| 4476 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4477 | return -EINVAL; |
| 4478 | |
| 4479 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 4480 | return -EINVAL; |
| 4481 | |
| 4482 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4483 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 4484 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4485 | if (!rdev->ops->change_mpath) |
| 4486 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4487 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4488 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4489 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4490 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4491 | return rdev_change_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4492 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4493 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4494 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4495 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4496 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4497 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4498 | u8 *dst = NULL; |
| 4499 | u8 *next_hop = NULL; |
| 4500 | |
| 4501 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4502 | return -EINVAL; |
| 4503 | |
| 4504 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 4505 | return -EINVAL; |
| 4506 | |
| 4507 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4508 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 4509 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4510 | if (!rdev->ops->add_mpath) |
| 4511 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4512 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4513 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4514 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4515 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4516 | return rdev_add_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4517 | } |
| 4518 | |
| 4519 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4520 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4521 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4522 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4523 | u8 *dst = NULL; |
| 4524 | |
| 4525 | if (info->attrs[NL80211_ATTR_MAC]) |
| 4526 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4527 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4528 | if (!rdev->ops->del_mpath) |
| 4529 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4530 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4531 | return rdev_del_mpath(rdev, dev, dst); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4532 | } |
| 4533 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4534 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
| 4535 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4536 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4537 | struct net_device *dev = info->user_ptr[1]; |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 4538 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4539 | struct bss_parameters params; |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 4540 | int err; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4541 | |
| 4542 | memset(¶ms, 0, sizeof(params)); |
| 4543 | /* default to not changing parameters */ |
| 4544 | params.use_cts_prot = -1; |
| 4545 | params.use_short_preamble = -1; |
| 4546 | params.use_short_slot_time = -1; |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 4547 | params.ap_isolate = -1; |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 4548 | params.ht_opmode = -1; |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 4549 | params.p2p_ctwindow = -1; |
| 4550 | params.p2p_opp_ps = -1; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4551 | |
| 4552 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) |
| 4553 | params.use_cts_prot = |
| 4554 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); |
| 4555 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) |
| 4556 | params.use_short_preamble = |
| 4557 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); |
| 4558 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) |
| 4559 | params.use_short_slot_time = |
| 4560 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 4561 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 4562 | params.basic_rates = |
| 4563 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 4564 | params.basic_rates_len = |
| 4565 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 4566 | } |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 4567 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
| 4568 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 4569 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
| 4570 | params.ht_opmode = |
| 4571 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4572 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 4573 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 4574 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4575 | return -EINVAL; |
| 4576 | params.p2p_ctwindow = |
| 4577 | nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
| 4578 | if (params.p2p_ctwindow < 0) |
| 4579 | return -EINVAL; |
| 4580 | if (params.p2p_ctwindow != 0 && |
| 4581 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 4582 | return -EINVAL; |
| 4583 | } |
| 4584 | |
| 4585 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 4586 | u8 tmp; |
| 4587 | |
| 4588 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4589 | return -EINVAL; |
| 4590 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
| 4591 | if (tmp > 1) |
| 4592 | return -EINVAL; |
| 4593 | params.p2p_opp_ps = tmp; |
| 4594 | if (params.p2p_opp_ps && |
| 4595 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 4596 | return -EINVAL; |
| 4597 | } |
| 4598 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4599 | if (!rdev->ops->change_bss) |
| 4600 | return -EOPNOTSUPP; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4601 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4602 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4603 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4604 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4605 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 4606 | wdev_lock(wdev); |
| 4607 | err = rdev_change_bss(rdev, dev, ¶ms); |
| 4608 | wdev_unlock(wdev); |
| 4609 | |
| 4610 | return err; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4611 | } |
| 4612 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 4613 | 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] | 4614 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
| 4615 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, |
| 4616 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, |
| 4617 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, |
| 4618 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, |
| 4619 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, |
| 4620 | }; |
| 4621 | |
| 4622 | static int parse_reg_rule(struct nlattr *tb[], |
| 4623 | struct ieee80211_reg_rule *reg_rule) |
| 4624 | { |
| 4625 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; |
| 4626 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; |
| 4627 | |
| 4628 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) |
| 4629 | return -EINVAL; |
| 4630 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) |
| 4631 | return -EINVAL; |
| 4632 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) |
| 4633 | return -EINVAL; |
| 4634 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) |
| 4635 | return -EINVAL; |
| 4636 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) |
| 4637 | return -EINVAL; |
| 4638 | |
| 4639 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); |
| 4640 | |
| 4641 | freq_range->start_freq_khz = |
| 4642 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); |
| 4643 | freq_range->end_freq_khz = |
| 4644 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); |
| 4645 | freq_range->max_bandwidth_khz = |
| 4646 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); |
| 4647 | |
| 4648 | power_rule->max_eirp = |
| 4649 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); |
| 4650 | |
| 4651 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) |
| 4652 | power_rule->max_antenna_gain = |
| 4653 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); |
| 4654 | |
| 4655 | return 0; |
| 4656 | } |
| 4657 | |
| 4658 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 4659 | { |
| 4660 | int r; |
| 4661 | char *data = NULL; |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4662 | enum nl80211_user_reg_hint_type user_reg_hint_type; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4663 | |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 4664 | /* |
| 4665 | * You should only get this when cfg80211 hasn't yet initialized |
| 4666 | * completely when built-in to the kernel right between the time |
| 4667 | * window between nl80211_init() and regulatory_init(), if that is |
| 4668 | * even possible. |
| 4669 | */ |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4670 | if (unlikely(!rcu_access_pointer(cfg80211_regdomain))) |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 4671 | return -EINPROGRESS; |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 4672 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 4673 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 4674 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4675 | |
| 4676 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 4677 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4678 | if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]) |
| 4679 | user_reg_hint_type = |
| 4680 | nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]); |
| 4681 | else |
| 4682 | user_reg_hint_type = NL80211_USER_REG_HINT_USER; |
| 4683 | |
| 4684 | switch (user_reg_hint_type) { |
| 4685 | case NL80211_USER_REG_HINT_USER: |
| 4686 | case NL80211_USER_REG_HINT_CELL_BASE: |
| 4687 | break; |
| 4688 | default: |
| 4689 | return -EINVAL; |
| 4690 | } |
| 4691 | |
| 4692 | r = regulatory_hint_user(data, user_reg_hint_type); |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 4693 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4694 | return r; |
| 4695 | } |
| 4696 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4697 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4698 | struct genl_info *info) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4699 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4700 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4701 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4702 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 4703 | struct mesh_config cur_params; |
| 4704 | int err = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4705 | void *hdr; |
| 4706 | struct nlattr *pinfoattr; |
| 4707 | struct sk_buff *msg; |
| 4708 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4709 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4710 | return -EOPNOTSUPP; |
| 4711 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4712 | if (!rdev->ops->get_mesh_config) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4713 | return -EOPNOTSUPP; |
Jouni Malinen | f3f9258 | 2009-03-20 17:57:36 +0200 | [diff] [blame] | 4714 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4715 | wdev_lock(wdev); |
| 4716 | /* If not connected, get default parameters */ |
| 4717 | if (!wdev->mesh_id_len) |
| 4718 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); |
| 4719 | else |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4720 | err = rdev_get_mesh_config(rdev, dev, &cur_params); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4721 | wdev_unlock(wdev); |
| 4722 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4723 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4724 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4725 | |
| 4726 | /* Draw up a netlink message to send back */ |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4727 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4728 | if (!msg) |
| 4729 | return -ENOMEM; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4730 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4731 | NL80211_CMD_GET_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4732 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4733 | goto out; |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4734 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4735 | if (!pinfoattr) |
| 4736 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4737 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 4738 | nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 4739 | cur_params.dot11MeshRetryTimeout) || |
| 4740 | nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 4741 | cur_params.dot11MeshConfirmTimeout) || |
| 4742 | nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 4743 | cur_params.dot11MeshHoldingTimeout) || |
| 4744 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 4745 | cur_params.dot11MeshMaxPeerLinks) || |
| 4746 | nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES, |
| 4747 | cur_params.dot11MeshMaxRetries) || |
| 4748 | nla_put_u8(msg, NL80211_MESHCONF_TTL, |
| 4749 | cur_params.dot11MeshTTL) || |
| 4750 | nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL, |
| 4751 | cur_params.element_ttl) || |
| 4752 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 4753 | cur_params.auto_open_plinks) || |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 4754 | nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 4755 | cur_params.dot11MeshNbrOffsetMaxNeighbor) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4756 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 4757 | cur_params.dot11MeshHWMPmaxPREQretries) || |
| 4758 | nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 4759 | cur_params.path_refresh_time) || |
| 4760 | nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 4761 | cur_params.min_discovery_timeout) || |
| 4762 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 4763 | cur_params.dot11MeshHWMPactivePathTimeout) || |
| 4764 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 4765 | cur_params.dot11MeshHWMPpreqMinInterval) || |
| 4766 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
| 4767 | cur_params.dot11MeshHWMPperrMinInterval) || |
| 4768 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 4769 | cur_params.dot11MeshHWMPnetDiameterTraversalTime) || |
| 4770 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 4771 | cur_params.dot11MeshHWMPRootMode) || |
| 4772 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
| 4773 | cur_params.dot11MeshHWMPRannInterval) || |
| 4774 | nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
| 4775 | cur_params.dot11MeshGateAnnouncementProtocol) || |
| 4776 | nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, |
| 4777 | cur_params.dot11MeshForwarding) || |
| 4778 | nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, |
Ashok Nagarajan | 70c33ea | 2012-04-30 14:20:32 -0700 | [diff] [blame] | 4779 | cur_params.rssi_threshold) || |
| 4780 | nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4781 | cur_params.ht_opmode) || |
| 4782 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 4783 | cur_params.dot11MeshHWMPactivePathToRootTimeout) || |
| 4784 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4785 | cur_params.dot11MeshHWMProotInterval) || |
| 4786 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4787 | cur_params.dot11MeshHWMPconfirmationInterval) || |
| 4788 | nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE, |
| 4789 | cur_params.power_mode) || |
| 4790 | nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW, |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 4791 | cur_params.dot11MeshAwakeWindowDuration) || |
| 4792 | nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT, |
| 4793 | cur_params.plink_timeout)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4794 | goto nla_put_failure; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4795 | nla_nest_end(msg, pinfoattr); |
| 4796 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4797 | return genlmsg_reply(msg, info); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4798 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4799 | nla_put_failure: |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4800 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4801 | out: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 4802 | nlmsg_free(msg); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4803 | return -ENOBUFS; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4804 | } |
| 4805 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 4806 | 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] | 4807 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
| 4808 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, |
| 4809 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, |
| 4810 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, |
| 4811 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, |
| 4812 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 4813 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4814 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 4815 | [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4816 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
| 4817 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, |
| 4818 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, |
| 4819 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, |
| 4820 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 4821 | [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4822 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
Javier Cardona | 699403d | 2011-08-09 16:45:09 -0700 | [diff] [blame] | 4823 | [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 }, |
Javier Cardona | 0507e15 | 2011-08-09 16:45:10 -0700 | [diff] [blame] | 4824 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 }, |
Javier Cardona | 16dd726 | 2011-08-09 16:45:11 -0700 | [diff] [blame] | 4825 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | 94f9065 | 2012-01-21 01:02:16 +0800 | [diff] [blame] | 4826 | [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4827 | [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 }, |
| 4828 | [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4829 | [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 }, |
| 4830 | [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4831 | [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 }, |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4832 | [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 }, |
| 4833 | [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 }, |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 4834 | [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4835 | }; |
| 4836 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4837 | static const struct nla_policy |
| 4838 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 4839 | [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4840 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
| 4841 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 4842 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
Colleen Twitty | 6e16d90 | 2013-05-08 11:45:59 -0700 | [diff] [blame] | 4843 | [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 }, |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 4844 | [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG }, |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4845 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4846 | .len = IEEE80211_MAX_DATA_LEN }, |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 4847 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4848 | }; |
| 4849 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4850 | static int nl80211_parse_mesh_config(struct genl_info *info, |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4851 | struct mesh_config *cfg, |
| 4852 | u32 *mask_out) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4853 | { |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4854 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4855 | u32 mask = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4856 | |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4857 | #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \ |
| 4858 | do { \ |
| 4859 | if (tb[attr]) { \ |
| 4860 | if (fn(tb[attr]) < min || fn(tb[attr]) > max) \ |
| 4861 | return -EINVAL; \ |
| 4862 | cfg->param = fn(tb[attr]); \ |
| 4863 | mask |= (1 << (attr - 1)); \ |
| 4864 | } \ |
| 4865 | } while (0) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4866 | |
| 4867 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4868 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4869 | return -EINVAL; |
| 4870 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4871 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4872 | nl80211_meshconf_params_policy)) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4873 | return -EINVAL; |
| 4874 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4875 | /* This makes sure that there aren't more than 32 mesh config |
| 4876 | * parameters (otherwise our bitfield scheme would not work.) */ |
| 4877 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); |
| 4878 | |
| 4879 | /* Fill in the params struct */ |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4880 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4881 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 4882 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4883 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4884 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 4885 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4886 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4887 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 4888 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4889 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4890 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 4891 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4892 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4893 | mask, NL80211_MESHCONF_MAX_RETRIES, |
| 4894 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4895 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4896 | mask, NL80211_MESHCONF_TTL, nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4897 | 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] | 4898 | mask, NL80211_MESHCONF_ELEMENT_TTL, |
| 4899 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4900 | 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] | 4901 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 4902 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4903 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, |
| 4904 | 1, 255, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4905 | NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 4906 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4907 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4908 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 4909 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4910 | 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] | 4911 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 4912 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4913 | 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] | 4914 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 4915 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4916 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
| 4917 | 1, 65535, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4918 | NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 4919 | nla_get_u32); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4920 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4921 | 1, 65535, mask, |
| 4922 | NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4923 | nla_get_u16); |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 4924 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4925 | 1, 65535, mask, |
| 4926 | NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4927 | nla_get_u16); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4928 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4929 | dot11MeshHWMPnetDiameterTraversalTime, |
| 4930 | 1, 65535, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4931 | NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 4932 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4933 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4, |
| 4934 | mask, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 4935 | nla_get_u8); |
| 4936 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535, |
| 4937 | mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4938 | nla_get_u16); |
Rui Paulo | 63c5723 | 2009-11-09 23:46:57 +0000 | [diff] [blame] | 4939 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4940 | dot11MeshGateAnnouncementProtocol, 0, 1, |
| 4941 | mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4942 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4943 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4944 | mask, NL80211_MESHCONF_FORWARDING, |
| 4945 | nla_get_u8); |
Chun-Yeow Yeoh | 83374fe | 2013-07-11 18:24:03 +0800 | [diff] [blame] | 4946 | 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] | 4947 | mask, NL80211_MESHCONF_RSSI_THRESHOLD, |
Chun-Yeow Yeoh | 83374fe | 2013-07-11 18:24:03 +0800 | [diff] [blame] | 4948 | nla_get_s32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4949 | 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] | 4950 | mask, NL80211_MESHCONF_HT_OPMODE, |
| 4951 | nla_get_u16); |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4952 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4953 | 1, 65535, mask, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4954 | NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 4955 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4956 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4957 | mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
| 4958 | nla_get_u16); |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4959 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4960 | dot11MeshHWMPconfirmationInterval, |
| 4961 | 1, 65535, mask, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4962 | NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
| 4963 | nla_get_u16); |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4964 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode, |
| 4965 | NL80211_MESH_POWER_ACTIVE, |
| 4966 | NL80211_MESH_POWER_MAX, |
| 4967 | mask, NL80211_MESHCONF_POWER_MODE, |
| 4968 | nla_get_u32); |
| 4969 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration, |
| 4970 | 0, 65535, mask, |
| 4971 | NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16); |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 4972 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 1, 0xffffffff, |
| 4973 | mask, NL80211_MESHCONF_PLINK_TIMEOUT, |
| 4974 | nla_get_u32); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4975 | if (mask_out) |
| 4976 | *mask_out = mask; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4977 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4978 | return 0; |
| 4979 | |
| 4980 | #undef FILL_IN_MESH_PARAM_IF_SET |
| 4981 | } |
| 4982 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4983 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
| 4984 | struct mesh_setup *setup) |
| 4985 | { |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 4986 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4987 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
| 4988 | |
| 4989 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) |
| 4990 | return -EINVAL; |
| 4991 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, |
| 4992 | info->attrs[NL80211_ATTR_MESH_SETUP], |
| 4993 | nl80211_mesh_setup_params_policy)) |
| 4994 | return -EINVAL; |
| 4995 | |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 4996 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC]) |
| 4997 | setup->sync_method = |
| 4998 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ? |
| 4999 | IEEE80211_SYNC_METHOD_VENDOR : |
| 5000 | IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET; |
| 5001 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5002 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
| 5003 | setup->path_sel_proto = |
| 5004 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? |
| 5005 | IEEE80211_PATH_PROTOCOL_VENDOR : |
| 5006 | IEEE80211_PATH_PROTOCOL_HWMP; |
| 5007 | |
| 5008 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) |
| 5009 | setup->path_metric = |
| 5010 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? |
| 5011 | IEEE80211_PATH_METRIC_VENDOR : |
| 5012 | IEEE80211_PATH_METRIC_AIRTIME; |
| 5013 | |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 5014 | |
| 5015 | if (tb[NL80211_MESH_SETUP_IE]) { |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5016 | struct nlattr *ieattr = |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 5017 | tb[NL80211_MESH_SETUP_IE]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5018 | if (!is_valid_ie_attr(ieattr)) |
| 5019 | return -EINVAL; |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 5020 | setup->ie = nla_data(ieattr); |
| 5021 | setup->ie_len = nla_len(ieattr); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5022 | } |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 5023 | if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] && |
| 5024 | !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM)) |
| 5025 | return -EINVAL; |
| 5026 | setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]); |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 5027 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
| 5028 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 5029 | if (setup->is_secure) |
| 5030 | setup->user_mpm = true; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5031 | |
Colleen Twitty | 6e16d90 | 2013-05-08 11:45:59 -0700 | [diff] [blame] | 5032 | if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) { |
| 5033 | if (!setup->user_mpm) |
| 5034 | return -EINVAL; |
| 5035 | setup->auth_id = |
| 5036 | nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]); |
| 5037 | } |
| 5038 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5039 | return 0; |
| 5040 | } |
| 5041 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5042 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5043 | struct genl_info *info) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5044 | { |
| 5045 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5046 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5047 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5048 | struct mesh_config cfg; |
| 5049 | u32 mask; |
| 5050 | int err; |
| 5051 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5052 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 5053 | return -EOPNOTSUPP; |
| 5054 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5055 | if (!rdev->ops->update_mesh_config) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5056 | return -EOPNOTSUPP; |
| 5057 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5058 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5059 | if (err) |
| 5060 | return err; |
| 5061 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5062 | wdev_lock(wdev); |
| 5063 | if (!wdev->mesh_id_len) |
| 5064 | err = -ENOLINK; |
| 5065 | |
| 5066 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5067 | err = rdev_update_mesh_config(rdev, dev, mask, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5068 | |
| 5069 | wdev_unlock(wdev); |
| 5070 | |
| 5071 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5072 | } |
| 5073 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5074 | static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info) |
| 5075 | { |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5076 | const struct ieee80211_regdomain *regdom; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5077 | struct sk_buff *msg; |
| 5078 | void *hdr = NULL; |
| 5079 | struct nlattr *nl_reg_rules; |
| 5080 | unsigned int i; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5081 | |
| 5082 | if (!cfg80211_regdomain) |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5083 | return -EINVAL; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5084 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 5085 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5086 | if (!msg) |
| 5087 | return -ENOBUFS; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5088 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5089 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5090 | NL80211_CMD_GET_REG); |
| 5091 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 5092 | goto put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5093 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 5094 | if (reg_last_request_cell_base() && |
| 5095 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, |
| 5096 | NL80211_USER_REG_HINT_CELL_BASE)) |
| 5097 | goto nla_put_failure; |
| 5098 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5099 | rcu_read_lock(); |
| 5100 | regdom = rcu_dereference(cfg80211_regdomain); |
| 5101 | |
| 5102 | if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) || |
| 5103 | (regdom->dfs_region && |
| 5104 | nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region))) |
| 5105 | goto nla_put_failure_rcu; |
| 5106 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5107 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
| 5108 | if (!nl_reg_rules) |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5109 | goto nla_put_failure_rcu; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5110 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5111 | for (i = 0; i < regdom->n_reg_rules; i++) { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5112 | struct nlattr *nl_reg_rule; |
| 5113 | const struct ieee80211_reg_rule *reg_rule; |
| 5114 | const struct ieee80211_freq_range *freq_range; |
| 5115 | const struct ieee80211_power_rule *power_rule; |
| 5116 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5117 | reg_rule = ®dom->reg_rules[i]; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5118 | freq_range = ®_rule->freq_range; |
| 5119 | power_rule = ®_rule->power_rule; |
| 5120 | |
| 5121 | nl_reg_rule = nla_nest_start(msg, i); |
| 5122 | if (!nl_reg_rule) |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5123 | goto nla_put_failure_rcu; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5124 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5125 | if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
| 5126 | reg_rule->flags) || |
| 5127 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START, |
| 5128 | freq_range->start_freq_khz) || |
| 5129 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END, |
| 5130 | freq_range->end_freq_khz) || |
| 5131 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, |
| 5132 | freq_range->max_bandwidth_khz) || |
| 5133 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
| 5134 | power_rule->max_antenna_gain) || |
| 5135 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, |
| 5136 | power_rule->max_eirp)) |
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 | |
| 5139 | nla_nest_end(msg, nl_reg_rule); |
| 5140 | } |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5141 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5142 | |
| 5143 | nla_nest_end(msg, nl_reg_rules); |
| 5144 | |
| 5145 | genlmsg_end(msg, hdr); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5146 | return genlmsg_reply(msg, info); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5147 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5148 | nla_put_failure_rcu: |
| 5149 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5150 | nla_put_failure: |
| 5151 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 5152 | put_failure: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 5153 | nlmsg_free(msg); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5154 | return -EMSGSIZE; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5155 | } |
| 5156 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5157 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 5158 | { |
| 5159 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; |
| 5160 | struct nlattr *nl_reg_rule; |
| 5161 | char *alpha2 = NULL; |
| 5162 | int rem_reg_rules = 0, r = 0; |
| 5163 | u32 num_rules = 0, rule_idx = 0, size_of_regd; |
Luis R. Rodriguez | 4c7d398 | 2013-11-13 18:54:02 +0100 | [diff] [blame] | 5164 | enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5165 | struct ieee80211_regdomain *rd = NULL; |
| 5166 | |
| 5167 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 5168 | return -EINVAL; |
| 5169 | |
| 5170 | if (!info->attrs[NL80211_ATTR_REG_RULES]) |
| 5171 | return -EINVAL; |
| 5172 | |
| 5173 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 5174 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 5175 | if (info->attrs[NL80211_ATTR_DFS_REGION]) |
| 5176 | dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); |
| 5177 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5178 | 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] | 5179 | rem_reg_rules) { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5180 | num_rules++; |
| 5181 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) |
Luis R. Rodriguez | 4776c6e | 2009-05-13 17:04:39 -0400 | [diff] [blame] | 5182 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5183 | } |
| 5184 | |
Luis R. Rodriguez | e438768 | 2013-11-05 09:18:01 -0800 | [diff] [blame] | 5185 | if (!reg_is_valid_request(alpha2)) |
| 5186 | return -EINVAL; |
| 5187 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5188 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 5189 | num_rules * sizeof(struct ieee80211_reg_rule); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5190 | |
| 5191 | rd = kzalloc(size_of_regd, GFP_KERNEL); |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 5192 | if (!rd) |
| 5193 | return -ENOMEM; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5194 | |
| 5195 | rd->n_reg_rules = num_rules; |
| 5196 | rd->alpha2[0] = alpha2[0]; |
| 5197 | rd->alpha2[1] = alpha2[1]; |
| 5198 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 5199 | /* |
| 5200 | * Disable DFS master mode if the DFS region was |
| 5201 | * not supported or known on this kernel. |
| 5202 | */ |
| 5203 | if (reg_supported_dfs_region(dfs_region)) |
| 5204 | rd->dfs_region = dfs_region; |
| 5205 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5206 | 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] | 5207 | rem_reg_rules) { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5208 | nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 5209 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), |
| 5210 | reg_rule_policy); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5211 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
| 5212 | if (r) |
| 5213 | goto bad_reg; |
| 5214 | |
| 5215 | rule_idx++; |
| 5216 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 5217 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
| 5218 | r = -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5219 | goto bad_reg; |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 5220 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5221 | } |
| 5222 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5223 | r = set_regdom(rd); |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 5224 | /* set_regdom took ownership */ |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 5225 | rd = NULL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5226 | |
Johannes Berg | d2372b3 | 2008-10-24 20:32:20 +0200 | [diff] [blame] | 5227 | bad_reg: |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5228 | kfree(rd); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 5229 | return r; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5230 | } |
| 5231 | |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5232 | static int validate_scan_freqs(struct nlattr *freqs) |
| 5233 | { |
| 5234 | struct nlattr *attr1, *attr2; |
| 5235 | int n_channels = 0, tmp1, tmp2; |
| 5236 | |
| 5237 | nla_for_each_nested(attr1, freqs, tmp1) { |
| 5238 | n_channels++; |
| 5239 | /* |
| 5240 | * Some hardware has a limited channel list for |
| 5241 | * scanning, and it is pretty much nonsensical |
| 5242 | * to scan for a channel twice, so disallow that |
| 5243 | * and don't require drivers to check that the |
| 5244 | * channel list they get isn't longer than what |
| 5245 | * they can scan, as long as they can scan all |
| 5246 | * the channels they registered at once. |
| 5247 | */ |
| 5248 | nla_for_each_nested(attr2, freqs, tmp2) |
| 5249 | if (attr1 != attr2 && |
| 5250 | nla_get_u32(attr1) == nla_get_u32(attr2)) |
| 5251 | return 0; |
| 5252 | } |
| 5253 | |
| 5254 | return n_channels; |
| 5255 | } |
| 5256 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5257 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
| 5258 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5259 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 5260 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5261 | struct cfg80211_scan_request *request; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5262 | struct nlattr *attr; |
| 5263 | struct wiphy *wiphy; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5264 | int err, tmp, n_ssids = 0, n_channels, i; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5265 | size_t ie_len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5266 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5267 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5268 | return -EINVAL; |
| 5269 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5270 | wiphy = &rdev->wiphy; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5271 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5272 | if (!rdev->ops->scan) |
| 5273 | return -EOPNOTSUPP; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5274 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5275 | if (rdev->scan_req) { |
| 5276 | err = -EBUSY; |
| 5277 | goto unlock; |
| 5278 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5279 | |
| 5280 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5281 | n_channels = validate_scan_freqs( |
| 5282 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5283 | if (!n_channels) { |
| 5284 | err = -EINVAL; |
| 5285 | goto unlock; |
| 5286 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5287 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5288 | enum ieee80211_band band; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5289 | n_channels = 0; |
| 5290 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5291 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 5292 | if (wiphy->bands[band]) |
| 5293 | n_channels += wiphy->bands[band]->n_channels; |
| 5294 | } |
| 5295 | |
| 5296 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 5297 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) |
| 5298 | n_ssids++; |
| 5299 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5300 | if (n_ssids > wiphy->max_scan_ssids) { |
| 5301 | err = -EINVAL; |
| 5302 | goto unlock; |
| 5303 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5304 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5305 | if (info->attrs[NL80211_ATTR_IE]) |
| 5306 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5307 | else |
| 5308 | ie_len = 0; |
| 5309 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5310 | if (ie_len > wiphy->max_scan_ie_len) { |
| 5311 | err = -EINVAL; |
| 5312 | goto unlock; |
| 5313 | } |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 5314 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5315 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 5316 | + sizeof(*request->ssids) * n_ssids |
| 5317 | + sizeof(*request->channels) * n_channels |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5318 | + ie_len, GFP_KERNEL); |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5319 | if (!request) { |
| 5320 | err = -ENOMEM; |
| 5321 | goto unlock; |
| 5322 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5323 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5324 | if (n_ssids) |
Johannes Berg | 5ba6353 | 2009-08-07 17:54:07 +0200 | [diff] [blame] | 5325 | request->ssids = (void *)&request->channels[n_channels]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5326 | request->n_ssids = n_ssids; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5327 | if (ie_len) { |
| 5328 | if (request->ssids) |
| 5329 | request->ie = (void *)(request->ssids + n_ssids); |
| 5330 | else |
| 5331 | request->ie = (void *)(request->channels + n_channels); |
| 5332 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5333 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5334 | i = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5335 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 5336 | /* user specified, bail out if channel not found */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5337 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5338 | struct ieee80211_channel *chan; |
| 5339 | |
| 5340 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 5341 | |
| 5342 | if (!chan) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5343 | err = -EINVAL; |
| 5344 | goto out_free; |
| 5345 | } |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5346 | |
| 5347 | /* ignore disabled channels */ |
| 5348 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5349 | continue; |
| 5350 | |
| 5351 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5352 | i++; |
| 5353 | } |
| 5354 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5355 | enum ieee80211_band band; |
| 5356 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5357 | /* all channels */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5358 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 5359 | int j; |
| 5360 | if (!wiphy->bands[band]) |
| 5361 | continue; |
| 5362 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5363 | struct ieee80211_channel *chan; |
| 5364 | |
| 5365 | chan = &wiphy->bands[band]->channels[j]; |
| 5366 | |
| 5367 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5368 | continue; |
| 5369 | |
| 5370 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5371 | i++; |
| 5372 | } |
| 5373 | } |
| 5374 | } |
| 5375 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5376 | if (!i) { |
| 5377 | err = -EINVAL; |
| 5378 | goto out_free; |
| 5379 | } |
| 5380 | |
| 5381 | request->n_channels = i; |
| 5382 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5383 | i = 0; |
| 5384 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 5385 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5386 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5387 | err = -EINVAL; |
| 5388 | goto out_free; |
| 5389 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5390 | request->ssids[i].ssid_len = nla_len(attr); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5391 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5392 | i++; |
| 5393 | } |
| 5394 | } |
| 5395 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5396 | if (info->attrs[NL80211_ATTR_IE]) { |
| 5397 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Johannes Berg | de95a54 | 2009-04-01 11:58:36 +0200 | [diff] [blame] | 5398 | memcpy((void *)request->ie, |
| 5399 | nla_data(info->attrs[NL80211_ATTR_IE]), |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5400 | request->ie_len); |
| 5401 | } |
| 5402 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5403 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) |
Johannes Berg | a401d2b | 2011-07-20 00:52:16 +0200 | [diff] [blame] | 5404 | if (wiphy->bands[i]) |
| 5405 | request->rates[i] = |
| 5406 | (1 << wiphy->bands[i]->n_bitrates) - 1; |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5407 | |
| 5408 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { |
| 5409 | nla_for_each_nested(attr, |
| 5410 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], |
| 5411 | tmp) { |
| 5412 | enum ieee80211_band band = nla_type(attr); |
| 5413 | |
Dan Carpenter | 8440462 | 2011-07-29 11:52:18 +0300 | [diff] [blame] | 5414 | if (band < 0 || band >= IEEE80211_NUM_BANDS) { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5415 | err = -EINVAL; |
| 5416 | goto out_free; |
| 5417 | } |
Felix Fietkau | 1b09cd8 | 2013-11-20 19:40:41 +0100 | [diff] [blame] | 5418 | |
| 5419 | if (!wiphy->bands[band]) |
| 5420 | continue; |
| 5421 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5422 | err = ieee80211_get_ratemask(wiphy->bands[band], |
| 5423 | nla_data(attr), |
| 5424 | nla_len(attr), |
| 5425 | &request->rates[band]); |
| 5426 | if (err) |
| 5427 | goto out_free; |
| 5428 | } |
| 5429 | } |
| 5430 | |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5431 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5432 | request->flags = nla_get_u32( |
| 5433 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); |
Johannes Berg | 00c3a6e | 2013-10-26 17:14:38 +0200 | [diff] [blame] | 5434 | if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 5435 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) { |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5436 | err = -EOPNOTSUPP; |
| 5437 | goto out_free; |
| 5438 | } |
| 5439 | } |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5440 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 5441 | request->no_cck = |
| 5442 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 5443 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 5444 | request->wdev = wdev; |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5445 | request->wiphy = &rdev->wiphy; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 5446 | request->scan_start = jiffies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5447 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5448 | rdev->scan_req = request; |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5449 | err = rdev_scan(rdev, request); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5450 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5451 | if (!err) { |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 5452 | nl80211_send_scan_start(rdev, wdev); |
| 5453 | if (wdev->netdev) |
| 5454 | dev_hold(wdev->netdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5455 | } else { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5456 | out_free: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5457 | rdev->scan_req = NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5458 | kfree(request); |
| 5459 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 5460 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5461 | unlock: |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5462 | return err; |
| 5463 | } |
| 5464 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5465 | static int nl80211_start_sched_scan(struct sk_buff *skb, |
| 5466 | struct genl_info *info) |
| 5467 | { |
| 5468 | struct cfg80211_sched_scan_request *request; |
| 5469 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5470 | struct net_device *dev = info->user_ptr[1]; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5471 | struct nlattr *attr; |
| 5472 | struct wiphy *wiphy; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5473 | 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] | 5474 | u32 interval; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5475 | enum ieee80211_band band; |
| 5476 | size_t ie_len; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5477 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5478 | |
| 5479 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 5480 | !rdev->ops->sched_scan_start) |
| 5481 | return -EOPNOTSUPP; |
| 5482 | |
| 5483 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5484 | return -EINVAL; |
| 5485 | |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 5486 | if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
| 5487 | return -EINVAL; |
| 5488 | |
| 5489 | interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); |
| 5490 | if (interval == 0) |
| 5491 | return -EINVAL; |
| 5492 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5493 | wiphy = &rdev->wiphy; |
| 5494 | |
| 5495 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 5496 | n_channels = validate_scan_freqs( |
| 5497 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
| 5498 | if (!n_channels) |
| 5499 | return -EINVAL; |
| 5500 | } else { |
| 5501 | n_channels = 0; |
| 5502 | |
| 5503 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 5504 | if (wiphy->bands[band]) |
| 5505 | n_channels += wiphy->bands[band]->n_channels; |
| 5506 | } |
| 5507 | |
| 5508 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 5509 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 5510 | tmp) |
| 5511 | n_ssids++; |
| 5512 | |
Luciano Coelho | 93b6aa6 | 2011-07-13 14:57:28 +0300 | [diff] [blame] | 5513 | if (n_ssids > wiphy->max_sched_scan_ssids) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5514 | return -EINVAL; |
| 5515 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5516 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) |
| 5517 | nla_for_each_nested(attr, |
| 5518 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
| 5519 | tmp) |
| 5520 | n_match_sets++; |
| 5521 | |
| 5522 | if (n_match_sets > wiphy->max_match_sets) |
| 5523 | return -EINVAL; |
| 5524 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5525 | if (info->attrs[NL80211_ATTR_IE]) |
| 5526 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5527 | else |
| 5528 | ie_len = 0; |
| 5529 | |
Luciano Coelho | 5a865ba | 2011-07-13 14:57:29 +0300 | [diff] [blame] | 5530 | if (ie_len > wiphy->max_sched_scan_ie_len) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5531 | return -EINVAL; |
| 5532 | |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 5533 | if (rdev->sched_scan_req) { |
| 5534 | err = -EINPROGRESS; |
| 5535 | goto out; |
| 5536 | } |
| 5537 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5538 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 5539 | + sizeof(*request->ssids) * n_ssids |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5540 | + sizeof(*request->match_sets) * n_match_sets |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 5541 | + sizeof(*request->channels) * n_channels |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5542 | + ie_len, GFP_KERNEL); |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 5543 | if (!request) { |
| 5544 | err = -ENOMEM; |
| 5545 | goto out; |
| 5546 | } |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5547 | |
| 5548 | if (n_ssids) |
| 5549 | request->ssids = (void *)&request->channels[n_channels]; |
| 5550 | request->n_ssids = n_ssids; |
| 5551 | if (ie_len) { |
| 5552 | if (request->ssids) |
| 5553 | request->ie = (void *)(request->ssids + n_ssids); |
| 5554 | else |
| 5555 | request->ie = (void *)(request->channels + n_channels); |
| 5556 | } |
| 5557 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5558 | if (n_match_sets) { |
| 5559 | if (request->ie) |
| 5560 | request->match_sets = (void *)(request->ie + ie_len); |
| 5561 | else if (request->ssids) |
| 5562 | request->match_sets = |
| 5563 | (void *)(request->ssids + n_ssids); |
| 5564 | else |
| 5565 | request->match_sets = |
| 5566 | (void *)(request->channels + n_channels); |
| 5567 | } |
| 5568 | request->n_match_sets = n_match_sets; |
| 5569 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5570 | i = 0; |
| 5571 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 5572 | /* user specified, bail out if channel not found */ |
| 5573 | nla_for_each_nested(attr, |
| 5574 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], |
| 5575 | tmp) { |
| 5576 | struct ieee80211_channel *chan; |
| 5577 | |
| 5578 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 5579 | |
| 5580 | if (!chan) { |
| 5581 | err = -EINVAL; |
| 5582 | goto out_free; |
| 5583 | } |
| 5584 | |
| 5585 | /* ignore disabled channels */ |
| 5586 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5587 | continue; |
| 5588 | |
| 5589 | request->channels[i] = chan; |
| 5590 | i++; |
| 5591 | } |
| 5592 | } else { |
| 5593 | /* all channels */ |
| 5594 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 5595 | int j; |
| 5596 | if (!wiphy->bands[band]) |
| 5597 | continue; |
| 5598 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
| 5599 | struct ieee80211_channel *chan; |
| 5600 | |
| 5601 | chan = &wiphy->bands[band]->channels[j]; |
| 5602 | |
| 5603 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5604 | continue; |
| 5605 | |
| 5606 | request->channels[i] = chan; |
| 5607 | i++; |
| 5608 | } |
| 5609 | } |
| 5610 | } |
| 5611 | |
| 5612 | if (!i) { |
| 5613 | err = -EINVAL; |
| 5614 | goto out_free; |
| 5615 | } |
| 5616 | |
| 5617 | request->n_channels = i; |
| 5618 | |
| 5619 | i = 0; |
| 5620 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 5621 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 5622 | tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5623 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5624 | err = -EINVAL; |
| 5625 | goto out_free; |
| 5626 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5627 | request->ssids[i].ssid_len = nla_len(attr); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5628 | memcpy(request->ssids[i].ssid, nla_data(attr), |
| 5629 | nla_len(attr)); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5630 | i++; |
| 5631 | } |
| 5632 | } |
| 5633 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5634 | i = 0; |
| 5635 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
| 5636 | nla_for_each_nested(attr, |
| 5637 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
| 5638 | tmp) { |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 5639 | struct nlattr *ssid, *rssi; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5640 | |
| 5641 | nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
| 5642 | nla_data(attr), nla_len(attr), |
| 5643 | nl80211_match_policy); |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 5644 | ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5645 | if (ssid) { |
| 5646 | if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) { |
| 5647 | err = -EINVAL; |
| 5648 | goto out_free; |
| 5649 | } |
| 5650 | memcpy(request->match_sets[i].ssid.ssid, |
| 5651 | nla_data(ssid), nla_len(ssid)); |
| 5652 | request->match_sets[i].ssid.ssid_len = |
| 5653 | nla_len(ssid); |
| 5654 | } |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 5655 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; |
| 5656 | if (rssi) |
| 5657 | request->rssi_thold = nla_get_u32(rssi); |
| 5658 | else |
| 5659 | request->rssi_thold = |
| 5660 | NL80211_SCAN_RSSI_THOLD_OFF; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5661 | i++; |
| 5662 | } |
| 5663 | } |
| 5664 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5665 | if (info->attrs[NL80211_ATTR_IE]) { |
| 5666 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5667 | memcpy((void *)request->ie, |
| 5668 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 5669 | request->ie_len); |
| 5670 | } |
| 5671 | |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5672 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5673 | request->flags = nla_get_u32( |
| 5674 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); |
Johannes Berg | 00c3a6e | 2013-10-26 17:14:38 +0200 | [diff] [blame] | 5675 | if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 5676 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) { |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5677 | err = -EOPNOTSUPP; |
| 5678 | goto out_free; |
| 5679 | } |
| 5680 | } |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5681 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5682 | request->dev = dev; |
| 5683 | request->wiphy = &rdev->wiphy; |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 5684 | request->interval = interval; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 5685 | request->scan_start = jiffies; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5686 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5687 | err = rdev_sched_scan_start(rdev, dev, request); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5688 | if (!err) { |
| 5689 | rdev->sched_scan_req = request; |
| 5690 | nl80211_send_sched_scan(rdev, dev, |
| 5691 | NL80211_CMD_START_SCHED_SCAN); |
| 5692 | goto out; |
| 5693 | } |
| 5694 | |
| 5695 | out_free: |
| 5696 | kfree(request); |
| 5697 | out: |
| 5698 | return err; |
| 5699 | } |
| 5700 | |
| 5701 | static int nl80211_stop_sched_scan(struct sk_buff *skb, |
| 5702 | struct genl_info *info) |
| 5703 | { |
| 5704 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5705 | |
| 5706 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 5707 | !rdev->ops->sched_scan_stop) |
| 5708 | return -EOPNOTSUPP; |
| 5709 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5710 | return __cfg80211_stop_sched_scan(rdev, false); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5711 | } |
| 5712 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5713 | static int nl80211_start_radar_detection(struct sk_buff *skb, |
| 5714 | struct genl_info *info) |
| 5715 | { |
| 5716 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5717 | struct net_device *dev = info->user_ptr[1]; |
| 5718 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 5719 | struct cfg80211_chan_def chandef; |
Luis R. Rodriguez | 55f7435 | 2013-11-25 20:56:10 +0100 | [diff] [blame] | 5720 | enum nl80211_dfs_regions dfs_region; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5721 | int err; |
| 5722 | |
Luis R. Rodriguez | 55f7435 | 2013-11-25 20:56:10 +0100 | [diff] [blame] | 5723 | dfs_region = reg_get_dfs_region(wdev->wiphy); |
| 5724 | if (dfs_region == NL80211_DFS_UNSET) |
| 5725 | return -EINVAL; |
| 5726 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5727 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 5728 | if (err) |
| 5729 | return err; |
| 5730 | |
Simon Wunderlich | ff311bc | 2013-09-03 19:43:18 +0200 | [diff] [blame] | 5731 | if (netif_carrier_ok(dev)) |
| 5732 | return -EBUSY; |
| 5733 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5734 | if (wdev->cac_started) |
| 5735 | return -EBUSY; |
| 5736 | |
| 5737 | err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef); |
| 5738 | if (err < 0) |
| 5739 | return err; |
| 5740 | |
| 5741 | if (err == 0) |
| 5742 | return -EINVAL; |
| 5743 | |
Janusz Dziedzic | fe7c3a1 | 2013-11-05 14:48:48 +0100 | [diff] [blame] | 5744 | if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef)) |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5745 | return -EINVAL; |
| 5746 | |
| 5747 | if (!rdev->ops->start_radar_detection) |
| 5748 | return -EOPNOTSUPP; |
| 5749 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5750 | err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype, |
| 5751 | chandef.chan, CHAN_MODE_SHARED, |
| 5752 | BIT(chandef.width)); |
| 5753 | if (err) |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5754 | return err; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5755 | |
| 5756 | err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef); |
| 5757 | if (!err) { |
| 5758 | wdev->channel = chandef.chan; |
| 5759 | wdev->cac_started = true; |
| 5760 | wdev->cac_start_time = jiffies; |
| 5761 | } |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5762 | return err; |
| 5763 | } |
| 5764 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5765 | static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info) |
| 5766 | { |
| 5767 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5768 | struct net_device *dev = info->user_ptr[1]; |
| 5769 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 5770 | struct cfg80211_csa_settings params; |
| 5771 | /* csa_attrs is defined static to avoid waste of stack size - this |
| 5772 | * function is called under RTNL lock, so this should not be a problem. |
| 5773 | */ |
| 5774 | static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1]; |
| 5775 | u8 radar_detect_width = 0; |
| 5776 | int err; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5777 | bool need_new_beacon = false; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5778 | |
| 5779 | if (!rdev->ops->channel_switch || |
| 5780 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)) |
| 5781 | return -EOPNOTSUPP; |
| 5782 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5783 | switch (dev->ieee80211_ptr->iftype) { |
| 5784 | case NL80211_IFTYPE_AP: |
| 5785 | case NL80211_IFTYPE_P2P_GO: |
| 5786 | need_new_beacon = true; |
| 5787 | |
| 5788 | /* useless if AP is not running */ |
| 5789 | if (!wdev->beacon_interval) |
| 5790 | return -EINVAL; |
| 5791 | break; |
| 5792 | case NL80211_IFTYPE_ADHOC: |
Chun-Yeow Yeoh | c6da674 | 2013-10-14 19:08:28 -0700 | [diff] [blame] | 5793 | case NL80211_IFTYPE_MESH_POINT: |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5794 | break; |
| 5795 | default: |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5796 | return -EOPNOTSUPP; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5797 | } |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5798 | |
| 5799 | memset(¶ms, 0, sizeof(params)); |
| 5800 | |
| 5801 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 5802 | !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]) |
| 5803 | return -EINVAL; |
| 5804 | |
| 5805 | /* only important for AP, IBSS and mesh create IEs internally */ |
Andrei Otcheretianski | d0a361a | 2013-10-17 10:52:17 +0200 | [diff] [blame] | 5806 | if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES]) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5807 | return -EINVAL; |
| 5808 | |
| 5809 | params.count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]); |
| 5810 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5811 | if (!need_new_beacon) |
| 5812 | goto skip_beacons; |
| 5813 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5814 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon_after); |
| 5815 | if (err) |
| 5816 | return err; |
| 5817 | |
| 5818 | err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX, |
| 5819 | info->attrs[NL80211_ATTR_CSA_IES], |
| 5820 | nl80211_policy); |
| 5821 | if (err) |
| 5822 | return err; |
| 5823 | |
| 5824 | err = nl80211_parse_beacon(csa_attrs, ¶ms.beacon_csa); |
| 5825 | if (err) |
| 5826 | return err; |
| 5827 | |
| 5828 | if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]) |
| 5829 | return -EINVAL; |
| 5830 | |
| 5831 | params.counter_offset_beacon = |
| 5832 | nla_get_u16(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); |
| 5833 | if (params.counter_offset_beacon >= params.beacon_csa.tail_len) |
| 5834 | return -EINVAL; |
| 5835 | |
| 5836 | /* sanity check - counters should be the same */ |
| 5837 | if (params.beacon_csa.tail[params.counter_offset_beacon] != |
| 5838 | params.count) |
| 5839 | return -EINVAL; |
| 5840 | |
| 5841 | if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) { |
| 5842 | params.counter_offset_presp = |
| 5843 | nla_get_u16(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); |
| 5844 | if (params.counter_offset_presp >= |
| 5845 | params.beacon_csa.probe_resp_len) |
| 5846 | return -EINVAL; |
| 5847 | |
| 5848 | if (params.beacon_csa.probe_resp[params.counter_offset_presp] != |
| 5849 | params.count) |
| 5850 | return -EINVAL; |
| 5851 | } |
| 5852 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5853 | skip_beacons: |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5854 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
| 5855 | if (err) |
| 5856 | return err; |
| 5857 | |
| 5858 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, ¶ms.chandef)) |
| 5859 | return -EINVAL; |
| 5860 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5861 | if (dev->ieee80211_ptr->iftype == NL80211_IFTYPE_AP || |
Simon Wunderlich | 5336fa8 | 2013-10-07 18:41:05 +0200 | [diff] [blame] | 5862 | dev->ieee80211_ptr->iftype == NL80211_IFTYPE_P2P_GO || |
| 5863 | dev->ieee80211_ptr->iftype == NL80211_IFTYPE_ADHOC) { |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5864 | err = cfg80211_chandef_dfs_required(wdev->wiphy, |
| 5865 | ¶ms.chandef); |
| 5866 | if (err < 0) { |
| 5867 | return err; |
| 5868 | } else if (err) { |
| 5869 | radar_detect_width = BIT(params.chandef.width); |
| 5870 | params.radar_required = true; |
| 5871 | } |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5872 | } |
| 5873 | |
| 5874 | err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype, |
| 5875 | params.chandef.chan, |
| 5876 | CHAN_MODE_SHARED, |
| 5877 | radar_detect_width); |
| 5878 | if (err) |
| 5879 | return err; |
| 5880 | |
| 5881 | if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX]) |
| 5882 | params.block_tx = true; |
| 5883 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 5884 | wdev_lock(wdev); |
| 5885 | err = rdev_channel_switch(rdev, dev, ¶ms); |
| 5886 | wdev_unlock(wdev); |
| 5887 | |
| 5888 | return err; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5889 | } |
| 5890 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 5891 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
| 5892 | u32 seq, int flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5893 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5894 | struct wireless_dev *wdev, |
| 5895 | struct cfg80211_internal_bss *intbss) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5896 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5897 | struct cfg80211_bss *res = &intbss->pub; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5898 | const struct cfg80211_bss_ies *ies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5899 | void *hdr; |
| 5900 | struct nlattr *bss; |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5901 | bool tsf = false; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5902 | |
| 5903 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5904 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5905 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5906 | NL80211_CMD_NEW_SCAN_RESULTS); |
| 5907 | if (!hdr) |
| 5908 | return -1; |
| 5909 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 5910 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
| 5911 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5912 | if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation)) |
| 5913 | goto nla_put_failure; |
| 5914 | if (wdev->netdev && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5915 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex)) |
| 5916 | goto nla_put_failure; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5917 | if (nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 5918 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5919 | |
| 5920 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); |
| 5921 | if (!bss) |
| 5922 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5923 | if ((!is_zero_ether_addr(res->bssid) && |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5924 | nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5925 | goto nla_put_failure; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5926 | |
| 5927 | rcu_read_lock(); |
| 5928 | ies = rcu_dereference(res->ies); |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5929 | if (ies) { |
| 5930 | if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf)) |
| 5931 | goto fail_unlock_rcu; |
| 5932 | tsf = true; |
| 5933 | if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS, |
| 5934 | ies->len, ies->data)) |
| 5935 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5936 | } |
| 5937 | ies = rcu_dereference(res->beacon_ies); |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5938 | if (ies) { |
| 5939 | if (!tsf && nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf)) |
| 5940 | goto fail_unlock_rcu; |
| 5941 | if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES, |
| 5942 | ies->len, ies->data)) |
| 5943 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5944 | } |
| 5945 | rcu_read_unlock(); |
| 5946 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5947 | if (res->beacon_interval && |
| 5948 | nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval)) |
| 5949 | goto nla_put_failure; |
| 5950 | if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) || |
| 5951 | nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) || |
Simon Wunderlich | dcd6eac | 2013-07-08 16:55:49 +0200 | [diff] [blame] | 5952 | nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5953 | nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO, |
| 5954 | jiffies_to_msecs(jiffies - intbss->ts))) |
| 5955 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5956 | |
Johannes Berg | 77965c9 | 2009-02-18 18:45:06 +0100 | [diff] [blame] | 5957 | switch (rdev->wiphy.signal_type) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5958 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5959 | if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal)) |
| 5960 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5961 | break; |
| 5962 | case CFG80211_SIGNAL_TYPE_UNSPEC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5963 | if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal)) |
| 5964 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5965 | break; |
| 5966 | default: |
| 5967 | break; |
| 5968 | } |
| 5969 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5970 | switch (wdev->iftype) { |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5971 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5972 | case NL80211_IFTYPE_STATION: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5973 | if (intbss == wdev->current_bss && |
| 5974 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 5975 | NL80211_BSS_STATUS_ASSOCIATED)) |
| 5976 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5977 | break; |
| 5978 | case NL80211_IFTYPE_ADHOC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5979 | if (intbss == wdev->current_bss && |
| 5980 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 5981 | NL80211_BSS_STATUS_IBSS_JOINED)) |
| 5982 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5983 | break; |
| 5984 | default: |
| 5985 | break; |
| 5986 | } |
| 5987 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5988 | nla_nest_end(msg, bss); |
| 5989 | |
| 5990 | return genlmsg_end(msg, hdr); |
| 5991 | |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5992 | fail_unlock_rcu: |
| 5993 | rcu_read_unlock(); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5994 | nla_put_failure: |
| 5995 | genlmsg_cancel(msg, hdr); |
| 5996 | return -EMSGSIZE; |
| 5997 | } |
| 5998 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5999 | 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] | 6000 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6001 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6002 | struct cfg80211_internal_bss *scan; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6003 | struct wireless_dev *wdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6004 | int start = cb->args[2], idx = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6005 | int err; |
| 6006 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6007 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 6008 | if (err) |
| 6009 | return err; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6010 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6011 | wdev_lock(wdev); |
| 6012 | spin_lock_bh(&rdev->bss_lock); |
| 6013 | cfg80211_bss_expire(rdev); |
| 6014 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 6015 | cb->seq = rdev->bss_generation; |
| 6016 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6017 | list_for_each_entry(scan, &rdev->bss_list, list) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6018 | if (++idx <= start) |
| 6019 | continue; |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 6020 | if (nl80211_send_bss(skb, cb, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6021 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6022 | rdev, wdev, scan) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6023 | idx--; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 6024 | break; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6025 | } |
| 6026 | } |
| 6027 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6028 | spin_unlock_bh(&rdev->bss_lock); |
| 6029 | wdev_unlock(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6030 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6031 | cb->args[2] = idx; |
| 6032 | nl80211_finish_wdev_dump(rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6033 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 6034 | return skb->len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6035 | } |
| 6036 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6037 | 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] | 6038 | int flags, struct net_device *dev, |
| 6039 | struct survey_info *survey) |
| 6040 | { |
| 6041 | void *hdr; |
| 6042 | struct nlattr *infoattr; |
| 6043 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6044 | hdr = nl80211hdr_put(msg, portid, seq, flags, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6045 | NL80211_CMD_NEW_SURVEY_RESULTS); |
| 6046 | if (!hdr) |
| 6047 | return -ENOMEM; |
| 6048 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6049 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
| 6050 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6051 | |
| 6052 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); |
| 6053 | if (!infoattr) |
| 6054 | goto nla_put_failure; |
| 6055 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6056 | if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY, |
| 6057 | survey->channel->center_freq)) |
| 6058 | goto nla_put_failure; |
| 6059 | |
| 6060 | if ((survey->filled & SURVEY_INFO_NOISE_DBM) && |
| 6061 | nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise)) |
| 6062 | goto nla_put_failure; |
| 6063 | if ((survey->filled & SURVEY_INFO_IN_USE) && |
| 6064 | nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE)) |
| 6065 | goto nla_put_failure; |
| 6066 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) && |
| 6067 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME, |
| 6068 | survey->channel_time)) |
| 6069 | goto nla_put_failure; |
| 6070 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) && |
| 6071 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY, |
| 6072 | survey->channel_time_busy)) |
| 6073 | goto nla_put_failure; |
| 6074 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) && |
| 6075 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY, |
| 6076 | survey->channel_time_ext_busy)) |
| 6077 | goto nla_put_failure; |
| 6078 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) && |
| 6079 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX, |
| 6080 | survey->channel_time_rx)) |
| 6081 | goto nla_put_failure; |
| 6082 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) && |
| 6083 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX, |
| 6084 | survey->channel_time_tx)) |
| 6085 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6086 | |
| 6087 | nla_nest_end(msg, infoattr); |
| 6088 | |
| 6089 | return genlmsg_end(msg, hdr); |
| 6090 | |
| 6091 | nla_put_failure: |
| 6092 | genlmsg_cancel(msg, hdr); |
| 6093 | return -EMSGSIZE; |
| 6094 | } |
| 6095 | |
| 6096 | static int nl80211_dump_survey(struct sk_buff *skb, |
| 6097 | struct netlink_callback *cb) |
| 6098 | { |
| 6099 | struct survey_info survey; |
| 6100 | struct cfg80211_registered_device *dev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6101 | struct wireless_dev *wdev; |
| 6102 | int survey_idx = cb->args[2]; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6103 | int res; |
| 6104 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6105 | res = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 6106 | if (res) |
| 6107 | return res; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6108 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6109 | if (!wdev->netdev) { |
| 6110 | res = -EINVAL; |
| 6111 | goto out_err; |
| 6112 | } |
| 6113 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6114 | if (!dev->ops->dump_survey) { |
| 6115 | res = -EOPNOTSUPP; |
| 6116 | goto out_err; |
| 6117 | } |
| 6118 | |
| 6119 | while (1) { |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 6120 | struct ieee80211_channel *chan; |
| 6121 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6122 | res = rdev_dump_survey(dev, wdev->netdev, survey_idx, &survey); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6123 | if (res == -ENOENT) |
| 6124 | break; |
| 6125 | if (res) |
| 6126 | goto out_err; |
| 6127 | |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 6128 | /* Survey without a channel doesn't make sense */ |
| 6129 | if (!survey.channel) { |
| 6130 | res = -EINVAL; |
| 6131 | goto out; |
| 6132 | } |
| 6133 | |
| 6134 | chan = ieee80211_get_channel(&dev->wiphy, |
| 6135 | survey.channel->center_freq); |
| 6136 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) { |
| 6137 | survey_idx++; |
| 6138 | continue; |
| 6139 | } |
| 6140 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6141 | if (nl80211_send_survey(skb, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6142 | NETLINK_CB(cb->skb).portid, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6143 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6144 | wdev->netdev, &survey) < 0) |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6145 | goto out; |
| 6146 | survey_idx++; |
| 6147 | } |
| 6148 | |
| 6149 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6150 | cb->args[2] = survey_idx; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6151 | res = skb->len; |
| 6152 | out_err: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6153 | nl80211_finish_wdev_dump(dev); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6154 | return res; |
| 6155 | } |
| 6156 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6157 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
| 6158 | { |
| 6159 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | |
| 6160 | NL80211_WPA_VERSION_2)); |
| 6161 | } |
| 6162 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6163 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
| 6164 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6165 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6166 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6167 | struct ieee80211_channel *chan; |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 6168 | const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL; |
| 6169 | int err, ssid_len, ie_len = 0, sae_data_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6170 | enum nl80211_auth_type auth_type; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6171 | struct key_parse key; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6172 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6173 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6174 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6175 | return -EINVAL; |
| 6176 | |
| 6177 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6178 | return -EINVAL; |
| 6179 | |
Jouni Malinen | 1778092 | 2009-03-27 20:52:47 +0200 | [diff] [blame] | 6180 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
| 6181 | return -EINVAL; |
| 6182 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6183 | if (!info->attrs[NL80211_ATTR_SSID]) |
| 6184 | return -EINVAL; |
| 6185 | |
| 6186 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 6187 | return -EINVAL; |
| 6188 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6189 | err = nl80211_parse_key(info, &key); |
| 6190 | if (err) |
| 6191 | return err; |
| 6192 | |
| 6193 | if (key.idx >= 0) { |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 6194 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
| 6195 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6196 | if (!key.p.key || !key.p.key_len) |
| 6197 | return -EINVAL; |
| 6198 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || |
| 6199 | key.p.key_len != WLAN_KEY_LEN_WEP40) && |
| 6200 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || |
| 6201 | key.p.key_len != WLAN_KEY_LEN_WEP104)) |
| 6202 | return -EINVAL; |
| 6203 | if (key.idx > 4) |
| 6204 | return -EINVAL; |
| 6205 | } else { |
| 6206 | key.p.key_len = 0; |
| 6207 | key.p.key = NULL; |
| 6208 | } |
| 6209 | |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 6210 | if (key.idx >= 0) { |
| 6211 | int i; |
| 6212 | bool ok = false; |
| 6213 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { |
| 6214 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { |
| 6215 | ok = true; |
| 6216 | break; |
| 6217 | } |
| 6218 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6219 | if (!ok) |
| 6220 | return -EINVAL; |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 6221 | } |
| 6222 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6223 | if (!rdev->ops->auth) |
| 6224 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6225 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6226 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6227 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6228 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6229 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6230 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 6231 | chan = ieee80211_get_channel(&rdev->wiphy, |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6232 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6233 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
| 6234 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6235 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6236 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 6237 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 6238 | |
| 6239 | if (info->attrs[NL80211_ATTR_IE]) { |
| 6240 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6241 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 6242 | } |
| 6243 | |
| 6244 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 6245 | if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6246 | return -EINVAL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6247 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 6248 | if (auth_type == NL80211_AUTHTYPE_SAE && |
| 6249 | !info->attrs[NL80211_ATTR_SAE_DATA]) |
| 6250 | return -EINVAL; |
| 6251 | |
| 6252 | if (info->attrs[NL80211_ATTR_SAE_DATA]) { |
| 6253 | if (auth_type != NL80211_AUTHTYPE_SAE) |
| 6254 | return -EINVAL; |
| 6255 | sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]); |
| 6256 | sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]); |
| 6257 | /* need to include at least Auth Transaction and Status Code */ |
| 6258 | if (sae_data_len < 4) |
| 6259 | return -EINVAL; |
| 6260 | } |
| 6261 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6262 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 6263 | |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 6264 | /* |
| 6265 | * Since we no longer track auth state, ignore |
| 6266 | * requests to only change local state. |
| 6267 | */ |
| 6268 | if (local_state_change) |
| 6269 | return 0; |
| 6270 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6271 | wdev_lock(dev->ieee80211_ptr); |
| 6272 | err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, |
| 6273 | ssid, ssid_len, ie, ie_len, |
| 6274 | key.p.key, key.p.key_len, key.idx, |
| 6275 | sae_data, sae_data_len); |
| 6276 | wdev_unlock(dev->ieee80211_ptr); |
| 6277 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6278 | } |
| 6279 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 6280 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 6281 | struct genl_info *info, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 6282 | struct cfg80211_crypto_settings *settings, |
| 6283 | int cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6284 | { |
Johannes Berg | c0b2bbd | 2009-07-25 16:54:36 +0200 | [diff] [blame] | 6285 | memset(settings, 0, sizeof(*settings)); |
| 6286 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6287 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
| 6288 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 6289 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
| 6290 | u16 proto; |
| 6291 | proto = nla_get_u16( |
| 6292 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); |
| 6293 | settings->control_port_ethertype = cpu_to_be16(proto); |
| 6294 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 6295 | proto != ETH_P_PAE) |
| 6296 | return -EINVAL; |
| 6297 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) |
| 6298 | settings->control_port_no_encrypt = true; |
| 6299 | } else |
| 6300 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); |
| 6301 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6302 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
| 6303 | void *data; |
| 6304 | int len, i; |
| 6305 | |
| 6306 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 6307 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 6308 | settings->n_ciphers_pairwise = len / sizeof(u32); |
| 6309 | |
| 6310 | if (len % sizeof(u32)) |
| 6311 | return -EINVAL; |
| 6312 | |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 6313 | if (settings->n_ciphers_pairwise > cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6314 | return -EINVAL; |
| 6315 | |
| 6316 | memcpy(settings->ciphers_pairwise, data, len); |
| 6317 | |
| 6318 | for (i = 0; i < settings->n_ciphers_pairwise; i++) |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 6319 | if (!cfg80211_supported_cipher_suite( |
| 6320 | &rdev->wiphy, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6321 | settings->ciphers_pairwise[i])) |
| 6322 | return -EINVAL; |
| 6323 | } |
| 6324 | |
| 6325 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { |
| 6326 | settings->cipher_group = |
| 6327 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 6328 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
| 6329 | settings->cipher_group)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6330 | return -EINVAL; |
| 6331 | } |
| 6332 | |
| 6333 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { |
| 6334 | settings->wpa_versions = |
| 6335 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); |
| 6336 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) |
| 6337 | return -EINVAL; |
| 6338 | } |
| 6339 | |
| 6340 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { |
| 6341 | void *data; |
Jouni Malinen | 6d30240 | 2011-09-21 18:11:33 +0300 | [diff] [blame] | 6342 | int len; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6343 | |
| 6344 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 6345 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 6346 | settings->n_akm_suites = len / sizeof(u32); |
| 6347 | |
| 6348 | if (len % sizeof(u32)) |
| 6349 | return -EINVAL; |
| 6350 | |
Jouni Malinen | 1b9ca02 | 2011-09-21 16:13:07 +0300 | [diff] [blame] | 6351 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) |
| 6352 | return -EINVAL; |
| 6353 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6354 | memcpy(settings->akm_suites, data, len); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6355 | } |
| 6356 | |
| 6357 | return 0; |
| 6358 | } |
| 6359 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6360 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
| 6361 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6362 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6363 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 6364 | struct ieee80211_channel *chan; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6365 | struct cfg80211_assoc_request req = {}; |
| 6366 | const u8 *bssid, *ssid; |
| 6367 | int err, ssid_len = 0; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6368 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6369 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6370 | return -EINVAL; |
| 6371 | |
| 6372 | if (!info->attrs[NL80211_ATTR_MAC] || |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6373 | !info->attrs[NL80211_ATTR_SSID] || |
| 6374 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6375 | return -EINVAL; |
| 6376 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6377 | if (!rdev->ops->assoc) |
| 6378 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6379 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6380 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6381 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6382 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6383 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6384 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6385 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6386 | chan = ieee80211_get_channel(&rdev->wiphy, |
| 6387 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6388 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
| 6389 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6390 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6391 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 6392 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6393 | |
| 6394 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6395 | req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6396 | req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6397 | } |
| 6398 | |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 6399 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 6400 | enum nl80211_mfp mfp = |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 6401 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 6402 | if (mfp == NL80211_MFP_REQUIRED) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6403 | req.use_mfp = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6404 | else if (mfp != NL80211_MFP_NO) |
| 6405 | return -EINVAL; |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 6406 | } |
| 6407 | |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 6408 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6409 | req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 6410 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6411 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6412 | req.flags |= ASSOC_REQ_DISABLE_HT; |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6413 | |
| 6414 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6415 | memcpy(&req.ht_capa_mask, |
| 6416 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 6417 | sizeof(req.ht_capa_mask)); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6418 | |
| 6419 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6420 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6421 | return -EINVAL; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6422 | memcpy(&req.ht_capa, |
| 6423 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 6424 | sizeof(req.ht_capa)); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6425 | } |
| 6426 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6427 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6428 | req.flags |= ASSOC_REQ_DISABLE_VHT; |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6429 | |
| 6430 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6431 | memcpy(&req.vht_capa_mask, |
| 6432 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), |
| 6433 | sizeof(req.vht_capa_mask)); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6434 | |
| 6435 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6436 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6437 | return -EINVAL; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6438 | memcpy(&req.vht_capa, |
| 6439 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), |
| 6440 | sizeof(req.vht_capa)); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6441 | } |
| 6442 | |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6443 | err = nl80211_crypto_settings(rdev, info, &req.crypto, 1); |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6444 | if (!err) { |
| 6445 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6446 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, |
| 6447 | ssid, ssid_len, &req); |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6448 | wdev_unlock(dev->ieee80211_ptr); |
| 6449 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6450 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6451 | return err; |
| 6452 | } |
| 6453 | |
| 6454 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) |
| 6455 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6456 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6457 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6458 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6459 | int ie_len = 0, err; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6460 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6461 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6462 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6463 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6464 | return -EINVAL; |
| 6465 | |
| 6466 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6467 | return -EINVAL; |
| 6468 | |
| 6469 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 6470 | return -EINVAL; |
| 6471 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6472 | if (!rdev->ops->deauth) |
| 6473 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6474 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6475 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6476 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6477 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6478 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6479 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6480 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6481 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 6482 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6483 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6484 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 6485 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6486 | |
| 6487 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6488 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6489 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6490 | } |
| 6491 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6492 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 6493 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6494 | wdev_lock(dev->ieee80211_ptr); |
| 6495 | err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, |
| 6496 | local_state_change); |
| 6497 | wdev_unlock(dev->ieee80211_ptr); |
| 6498 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6499 | } |
| 6500 | |
| 6501 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) |
| 6502 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6503 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6504 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6505 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6506 | int ie_len = 0, err; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6507 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6508 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6509 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6510 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6511 | return -EINVAL; |
| 6512 | |
| 6513 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6514 | return -EINVAL; |
| 6515 | |
| 6516 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 6517 | return -EINVAL; |
| 6518 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6519 | if (!rdev->ops->disassoc) |
| 6520 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6521 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6522 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6523 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6524 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6525 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6526 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6527 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6528 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 6529 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6530 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6531 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 6532 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6533 | |
| 6534 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6535 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6536 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6537 | } |
| 6538 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6539 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 6540 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6541 | wdev_lock(dev->ieee80211_ptr); |
| 6542 | err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, |
| 6543 | local_state_change); |
| 6544 | wdev_unlock(dev->ieee80211_ptr); |
| 6545 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6546 | } |
| 6547 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 6548 | static bool |
| 6549 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, |
| 6550 | int mcast_rate[IEEE80211_NUM_BANDS], |
| 6551 | int rateval) |
| 6552 | { |
| 6553 | struct wiphy *wiphy = &rdev->wiphy; |
| 6554 | bool found = false; |
| 6555 | int band, i; |
| 6556 | |
| 6557 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 6558 | struct ieee80211_supported_band *sband; |
| 6559 | |
| 6560 | sband = wiphy->bands[band]; |
| 6561 | if (!sband) |
| 6562 | continue; |
| 6563 | |
| 6564 | for (i = 0; i < sband->n_bitrates; i++) { |
| 6565 | if (sband->bitrates[i].bitrate == rateval) { |
| 6566 | mcast_rate[band] = i + 1; |
| 6567 | found = true; |
| 6568 | break; |
| 6569 | } |
| 6570 | } |
| 6571 | } |
| 6572 | |
| 6573 | return found; |
| 6574 | } |
| 6575 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6576 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
| 6577 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6578 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6579 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6580 | struct cfg80211_ibss_params ibss; |
| 6581 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6582 | struct cfg80211_cached_keys *connkeys = NULL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6583 | int err; |
| 6584 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 6585 | memset(&ibss, 0, sizeof(ibss)); |
| 6586 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6587 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6588 | return -EINVAL; |
| 6589 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6590 | if (!info->attrs[NL80211_ATTR_SSID] || |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6591 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 6592 | return -EINVAL; |
| 6593 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 6594 | ibss.beacon_interval = 100; |
| 6595 | |
| 6596 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 6597 | ibss.beacon_interval = |
| 6598 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 6599 | if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000) |
| 6600 | return -EINVAL; |
| 6601 | } |
| 6602 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6603 | if (!rdev->ops->join_ibss) |
| 6604 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6605 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6606 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 6607 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6608 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 6609 | wiphy = &rdev->wiphy; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6610 | |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 6611 | if (info->attrs[NL80211_ATTR_MAC]) { |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6612 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 6613 | |
| 6614 | if (!is_valid_ether_addr(ibss.bssid)) |
| 6615 | return -EINVAL; |
| 6616 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6617 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 6618 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 6619 | |
| 6620 | if (info->attrs[NL80211_ATTR_IE]) { |
| 6621 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6622 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 6623 | } |
| 6624 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6625 | err = nl80211_parse_chandef(rdev, info, &ibss.chandef); |
| 6626 | if (err) |
| 6627 | return err; |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 6628 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6629 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef)) |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 6630 | return -EINVAL; |
| 6631 | |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 6632 | switch (ibss.chandef.width) { |
Simon Wunderlich | bf37264 | 2013-07-08 16:55:58 +0200 | [diff] [blame] | 6633 | case NL80211_CHAN_WIDTH_5: |
| 6634 | case NL80211_CHAN_WIDTH_10: |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 6635 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 6636 | break; |
| 6637 | case NL80211_CHAN_WIDTH_20: |
| 6638 | case NL80211_CHAN_WIDTH_40: |
| 6639 | if (rdev->wiphy.features & NL80211_FEATURE_HT_IBSS) |
| 6640 | break; |
| 6641 | default: |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 6642 | return -EINVAL; |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 6643 | } |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 6644 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6645 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6646 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6647 | |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 6648 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 6649 | u8 *rates = |
| 6650 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 6651 | int n_rates = |
| 6652 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 6653 | struct ieee80211_supported_band *sband = |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6654 | wiphy->bands[ibss.chandef.chan->band]; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 6655 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 6656 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 6657 | &ibss.basic_rates); |
| 6658 | if (err) |
| 6659 | return err; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 6660 | } |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 6661 | |
Simon Wunderlich | 803768f | 2013-06-28 10:39:58 +0200 | [diff] [blame] | 6662 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 6663 | memcpy(&ibss.ht_capa_mask, |
| 6664 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 6665 | sizeof(ibss.ht_capa_mask)); |
| 6666 | |
| 6667 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
| 6668 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 6669 | return -EINVAL; |
| 6670 | memcpy(&ibss.ht_capa, |
| 6671 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 6672 | sizeof(ibss.ht_capa)); |
| 6673 | } |
| 6674 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 6675 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 6676 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, |
| 6677 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 6678 | return -EINVAL; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 6679 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6680 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6681 | bool no_ht = false; |
| 6682 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6683 | connkeys = nl80211_parse_connkeys(rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6684 | info->attrs[NL80211_ATTR_KEYS], |
| 6685 | &no_ht); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6686 | if (IS_ERR(connkeys)) |
| 6687 | return PTR_ERR(connkeys); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6688 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 6689 | if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) && |
| 6690 | no_ht) { |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6691 | kfree(connkeys); |
| 6692 | return -EINVAL; |
| 6693 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6694 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6695 | |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 6696 | ibss.control_port = |
| 6697 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]); |
| 6698 | |
Simon Wunderlich | 5336fa8 | 2013-10-07 18:41:05 +0200 | [diff] [blame] | 6699 | ibss.userspace_handles_dfs = |
| 6700 | nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]); |
| 6701 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6702 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6703 | if (err) |
| 6704 | kfree(connkeys); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6705 | return err; |
| 6706 | } |
| 6707 | |
| 6708 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) |
| 6709 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6710 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6711 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6712 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6713 | if (!rdev->ops->leave_ibss) |
| 6714 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6715 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6716 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 6717 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6718 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6719 | return cfg80211_leave_ibss(rdev, dev, false); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6720 | } |
| 6721 | |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 6722 | static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info) |
| 6723 | { |
| 6724 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6725 | struct net_device *dev = info->user_ptr[1]; |
| 6726 | int mcast_rate[IEEE80211_NUM_BANDS]; |
| 6727 | u32 nla_rate; |
| 6728 | int err; |
| 6729 | |
| 6730 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
| 6731 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 6732 | return -EOPNOTSUPP; |
| 6733 | |
| 6734 | if (!rdev->ops->set_mcast_rate) |
| 6735 | return -EOPNOTSUPP; |
| 6736 | |
| 6737 | memset(mcast_rate, 0, sizeof(mcast_rate)); |
| 6738 | |
| 6739 | if (!info->attrs[NL80211_ATTR_MCAST_RATE]) |
| 6740 | return -EINVAL; |
| 6741 | |
| 6742 | nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]); |
| 6743 | if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate)) |
| 6744 | return -EINVAL; |
| 6745 | |
| 6746 | err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate); |
| 6747 | |
| 6748 | return err; |
| 6749 | } |
| 6750 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 6751 | static struct sk_buff * |
| 6752 | __cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev, |
| 6753 | int approxlen, u32 portid, u32 seq, |
| 6754 | enum nl80211_commands cmd, |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 6755 | enum nl80211_attrs attr, |
| 6756 | const struct nl80211_vendor_cmd_info *info, |
| 6757 | gfp_t gfp) |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 6758 | { |
| 6759 | struct sk_buff *skb; |
| 6760 | void *hdr; |
| 6761 | struct nlattr *data; |
| 6762 | |
| 6763 | skb = nlmsg_new(approxlen + 100, gfp); |
| 6764 | if (!skb) |
| 6765 | return NULL; |
| 6766 | |
| 6767 | hdr = nl80211hdr_put(skb, portid, seq, 0, cmd); |
| 6768 | if (!hdr) { |
| 6769 | kfree_skb(skb); |
| 6770 | return NULL; |
| 6771 | } |
| 6772 | |
| 6773 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 6774 | goto nla_put_failure; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 6775 | |
| 6776 | if (info) { |
| 6777 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID, |
| 6778 | info->vendor_id)) |
| 6779 | goto nla_put_failure; |
| 6780 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD, |
| 6781 | info->subcmd)) |
| 6782 | goto nla_put_failure; |
| 6783 | } |
| 6784 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 6785 | data = nla_nest_start(skb, attr); |
| 6786 | |
| 6787 | ((void **)skb->cb)[0] = rdev; |
| 6788 | ((void **)skb->cb)[1] = hdr; |
| 6789 | ((void **)skb->cb)[2] = data; |
| 6790 | |
| 6791 | return skb; |
| 6792 | |
| 6793 | nla_put_failure: |
| 6794 | kfree_skb(skb); |
| 6795 | return NULL; |
| 6796 | } |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 6797 | |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame^] | 6798 | struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy, |
| 6799 | enum nl80211_commands cmd, |
| 6800 | enum nl80211_attrs attr, |
| 6801 | int vendor_event_idx, |
| 6802 | int approxlen, gfp_t gfp) |
| 6803 | { |
| 6804 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 6805 | const struct nl80211_vendor_cmd_info *info; |
| 6806 | |
| 6807 | switch (cmd) { |
| 6808 | case NL80211_CMD_TESTMODE: |
| 6809 | if (WARN_ON(vendor_event_idx != -1)) |
| 6810 | return NULL; |
| 6811 | info = NULL; |
| 6812 | break; |
| 6813 | case NL80211_CMD_VENDOR: |
| 6814 | if (WARN_ON(vendor_event_idx < 0 || |
| 6815 | vendor_event_idx >= wiphy->n_vendor_events)) |
| 6816 | return NULL; |
| 6817 | info = &wiphy->vendor_events[vendor_event_idx]; |
| 6818 | break; |
| 6819 | default: |
| 6820 | WARN_ON(1); |
| 6821 | return NULL; |
| 6822 | } |
| 6823 | |
| 6824 | return __cfg80211_alloc_vendor_skb(rdev, approxlen, 0, 0, |
| 6825 | cmd, attr, info, gfp); |
| 6826 | } |
| 6827 | EXPORT_SYMBOL(__cfg80211_alloc_event_skb); |
| 6828 | |
| 6829 | void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp) |
| 6830 | { |
| 6831 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 6832 | void *hdr = ((void **)skb->cb)[1]; |
| 6833 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 6834 | enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE; |
| 6835 | |
| 6836 | nla_nest_end(skb, data); |
| 6837 | genlmsg_end(skb, hdr); |
| 6838 | |
| 6839 | if (data->nla_type == NL80211_ATTR_VENDOR_DATA) |
| 6840 | mcgrp = NL80211_MCGRP_VENDOR; |
| 6841 | |
| 6842 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0, |
| 6843 | mcgrp, gfp); |
| 6844 | } |
| 6845 | EXPORT_SYMBOL(__cfg80211_send_event_skb); |
| 6846 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6847 | #ifdef CONFIG_NL80211_TESTMODE |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6848 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
| 6849 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6850 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 6851 | struct wireless_dev *wdev = |
| 6852 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6853 | int err; |
| 6854 | |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 6855 | if (!rdev->ops->testmode_cmd) |
| 6856 | return -EOPNOTSUPP; |
| 6857 | |
| 6858 | if (IS_ERR(wdev)) { |
| 6859 | err = PTR_ERR(wdev); |
| 6860 | if (err != -EINVAL) |
| 6861 | return err; |
| 6862 | wdev = NULL; |
| 6863 | } else if (wdev->wiphy != &rdev->wiphy) { |
| 6864 | return -EINVAL; |
| 6865 | } |
| 6866 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6867 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
| 6868 | return -EINVAL; |
| 6869 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 6870 | rdev->cur_cmd_info = info; |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 6871 | err = rdev_testmode_cmd(rdev, wdev, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6872 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
| 6873 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 6874 | rdev->cur_cmd_info = NULL; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6875 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6876 | return err; |
| 6877 | } |
| 6878 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6879 | static int nl80211_testmode_dump(struct sk_buff *skb, |
| 6880 | struct netlink_callback *cb) |
| 6881 | { |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6882 | struct cfg80211_registered_device *rdev; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6883 | int err; |
| 6884 | long phy_idx; |
| 6885 | void *data = NULL; |
| 6886 | int data_len = 0; |
| 6887 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6888 | rtnl_lock(); |
| 6889 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6890 | if (cb->args[0]) { |
| 6891 | /* |
| 6892 | * 0 is a valid index, but not valid for args[0], |
| 6893 | * so we need to offset by 1. |
| 6894 | */ |
| 6895 | phy_idx = cb->args[0] - 1; |
| 6896 | } else { |
| 6897 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 6898 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 6899 | nl80211_policy); |
| 6900 | if (err) |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6901 | goto out_err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6902 | |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 6903 | rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), |
| 6904 | nl80211_fam.attrbuf); |
| 6905 | if (IS_ERR(rdev)) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6906 | err = PTR_ERR(rdev); |
| 6907 | goto out_err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6908 | } |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 6909 | phy_idx = rdev->wiphy_idx; |
| 6910 | rdev = NULL; |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 6911 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6912 | if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]) |
| 6913 | cb->args[1] = |
| 6914 | (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]; |
| 6915 | } |
| 6916 | |
| 6917 | if (cb->args[1]) { |
| 6918 | data = nla_data((void *)cb->args[1]); |
| 6919 | data_len = nla_len((void *)cb->args[1]); |
| 6920 | } |
| 6921 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6922 | rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
| 6923 | if (!rdev) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6924 | err = -ENOENT; |
| 6925 | goto out_err; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6926 | } |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6927 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6928 | if (!rdev->ops->testmode_dump) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6929 | err = -EOPNOTSUPP; |
| 6930 | goto out_err; |
| 6931 | } |
| 6932 | |
| 6933 | while (1) { |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6934 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6935 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 6936 | NL80211_CMD_TESTMODE); |
| 6937 | struct nlattr *tmdata; |
| 6938 | |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 6939 | if (!hdr) |
| 6940 | break; |
| 6941 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6942 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6943 | genlmsg_cancel(skb, hdr); |
| 6944 | break; |
| 6945 | } |
| 6946 | |
| 6947 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 6948 | if (!tmdata) { |
| 6949 | genlmsg_cancel(skb, hdr); |
| 6950 | break; |
| 6951 | } |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6952 | err = rdev_testmode_dump(rdev, skb, cb, data, data_len); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6953 | nla_nest_end(skb, tmdata); |
| 6954 | |
| 6955 | if (err == -ENOBUFS || err == -ENOENT) { |
| 6956 | genlmsg_cancel(skb, hdr); |
| 6957 | break; |
| 6958 | } else if (err) { |
| 6959 | genlmsg_cancel(skb, hdr); |
| 6960 | goto out_err; |
| 6961 | } |
| 6962 | |
| 6963 | genlmsg_end(skb, hdr); |
| 6964 | } |
| 6965 | |
| 6966 | err = skb->len; |
| 6967 | /* see above */ |
| 6968 | cb->args[0] = phy_idx + 1; |
| 6969 | out_err: |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6970 | rtnl_unlock(); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6971 | return err; |
| 6972 | } |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6973 | #endif |
| 6974 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6975 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
| 6976 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6977 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6978 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6979 | struct cfg80211_connect_params connect; |
| 6980 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6981 | struct cfg80211_cached_keys *connkeys = NULL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6982 | int err; |
| 6983 | |
| 6984 | memset(&connect, 0, sizeof(connect)); |
| 6985 | |
| 6986 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6987 | return -EINVAL; |
| 6988 | |
| 6989 | if (!info->attrs[NL80211_ATTR_SSID] || |
| 6990 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 6991 | return -EINVAL; |
| 6992 | |
| 6993 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 6994 | connect.auth_type = |
| 6995 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 6996 | if (!nl80211_valid_auth_type(rdev, connect.auth_type, |
| 6997 | NL80211_CMD_CONNECT)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6998 | return -EINVAL; |
| 6999 | } else |
| 7000 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 7001 | |
| 7002 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; |
| 7003 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 7004 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 7005 | NL80211_MAX_NR_CIPHER_SUITES); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7006 | if (err) |
| 7007 | return err; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7008 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7009 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7010 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7011 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7012 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 7013 | wiphy = &rdev->wiphy; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7014 | |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 7015 | connect.bg_scan_period = -1; |
| 7016 | if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] && |
| 7017 | (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) { |
| 7018 | connect.bg_scan_period = |
| 7019 | nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]); |
| 7020 | } |
| 7021 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7022 | if (info->attrs[NL80211_ATTR_MAC]) |
| 7023 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 7024 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 7025 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 7026 | |
| 7027 | if (info->attrs[NL80211_ATTR_IE]) { |
| 7028 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 7029 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 7030 | } |
| 7031 | |
Jouni Malinen | cee00a9 | 2013-01-15 17:15:57 +0200 | [diff] [blame] | 7032 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
| 7033 | connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
| 7034 | if (connect.mfp != NL80211_MFP_REQUIRED && |
| 7035 | connect.mfp != NL80211_MFP_NO) |
| 7036 | return -EINVAL; |
| 7037 | } else { |
| 7038 | connect.mfp = NL80211_MFP_NO; |
| 7039 | } |
| 7040 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7041 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 7042 | connect.channel = |
| 7043 | ieee80211_get_channel(wiphy, |
| 7044 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
| 7045 | if (!connect.channel || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7046 | connect.channel->flags & IEEE80211_CHAN_DISABLED) |
| 7047 | return -EINVAL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7048 | } |
| 7049 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7050 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
| 7051 | connkeys = nl80211_parse_connkeys(rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 7052 | info->attrs[NL80211_ATTR_KEYS], NULL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7053 | if (IS_ERR(connkeys)) |
| 7054 | return PTR_ERR(connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7055 | } |
| 7056 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 7057 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
| 7058 | connect.flags |= ASSOC_REQ_DISABLE_HT; |
| 7059 | |
| 7060 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 7061 | memcpy(&connect.ht_capa_mask, |
| 7062 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 7063 | sizeof(connect.ht_capa_mask)); |
| 7064 | |
| 7065 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 7066 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) { |
| 7067 | kfree(connkeys); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 7068 | return -EINVAL; |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 7069 | } |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 7070 | memcpy(&connect.ht_capa, |
| 7071 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 7072 | sizeof(connect.ht_capa)); |
| 7073 | } |
| 7074 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 7075 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
| 7076 | connect.flags |= ASSOC_REQ_DISABLE_VHT; |
| 7077 | |
| 7078 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
| 7079 | memcpy(&connect.vht_capa_mask, |
| 7080 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), |
| 7081 | sizeof(connect.vht_capa_mask)); |
| 7082 | |
| 7083 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { |
| 7084 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) { |
| 7085 | kfree(connkeys); |
| 7086 | return -EINVAL; |
| 7087 | } |
| 7088 | memcpy(&connect.vht_capa, |
| 7089 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), |
| 7090 | sizeof(connect.vht_capa)); |
| 7091 | } |
| 7092 | |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7093 | wdev_lock(dev->ieee80211_ptr); |
| 7094 | err = cfg80211_connect(rdev, dev, &connect, connkeys, NULL); |
| 7095 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7096 | if (err) |
| 7097 | kfree(connkeys); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7098 | return err; |
| 7099 | } |
| 7100 | |
| 7101 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) |
| 7102 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7103 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7104 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7105 | u16 reason; |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7106 | int ret; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7107 | |
| 7108 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 7109 | reason = WLAN_REASON_DEAUTH_LEAVING; |
| 7110 | else |
| 7111 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 7112 | |
| 7113 | if (reason == 0) |
| 7114 | return -EINVAL; |
| 7115 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7116 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7117 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7118 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7119 | |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7120 | wdev_lock(dev->ieee80211_ptr); |
| 7121 | ret = cfg80211_disconnect(rdev, dev, reason, true); |
| 7122 | wdev_unlock(dev->ieee80211_ptr); |
| 7123 | return ret; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7124 | } |
| 7125 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7126 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
| 7127 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7128 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7129 | struct net *net; |
| 7130 | int err; |
| 7131 | u32 pid; |
| 7132 | |
| 7133 | if (!info->attrs[NL80211_ATTR_PID]) |
| 7134 | return -EINVAL; |
| 7135 | |
| 7136 | pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); |
| 7137 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7138 | net = get_net_ns_by_pid(pid); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7139 | if (IS_ERR(net)) |
| 7140 | return PTR_ERR(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7141 | |
| 7142 | err = 0; |
| 7143 | |
| 7144 | /* check if anything to do */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7145 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
| 7146 | err = cfg80211_switch_netns(rdev, net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7147 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7148 | put_net(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7149 | return err; |
| 7150 | } |
| 7151 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7152 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 7153 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7154 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7155 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
| 7156 | struct cfg80211_pmksa *pmksa) = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7157 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7158 | struct cfg80211_pmksa pmksa; |
| 7159 | |
| 7160 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); |
| 7161 | |
| 7162 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 7163 | return -EINVAL; |
| 7164 | |
| 7165 | if (!info->attrs[NL80211_ATTR_PMKID]) |
| 7166 | return -EINVAL; |
| 7167 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7168 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
| 7169 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 7170 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7171 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7172 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7173 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7174 | |
| 7175 | switch (info->genlhdr->cmd) { |
| 7176 | case NL80211_CMD_SET_PMKSA: |
| 7177 | rdev_ops = rdev->ops->set_pmksa; |
| 7178 | break; |
| 7179 | case NL80211_CMD_DEL_PMKSA: |
| 7180 | rdev_ops = rdev->ops->del_pmksa; |
| 7181 | break; |
| 7182 | default: |
| 7183 | WARN_ON(1); |
| 7184 | break; |
| 7185 | } |
| 7186 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7187 | if (!rdev_ops) |
| 7188 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7189 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7190 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7191 | } |
| 7192 | |
| 7193 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 7194 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7195 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7196 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7197 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7198 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7199 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7200 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7201 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7202 | if (!rdev->ops->flush_pmksa) |
| 7203 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7204 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7205 | return rdev_flush_pmksa(rdev, dev); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7206 | } |
| 7207 | |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7208 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) |
| 7209 | { |
| 7210 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7211 | struct net_device *dev = info->user_ptr[1]; |
| 7212 | u8 action_code, dialog_token; |
| 7213 | u16 status_code; |
| 7214 | u8 *peer; |
| 7215 | |
| 7216 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 7217 | !rdev->ops->tdls_mgmt) |
| 7218 | return -EOPNOTSUPP; |
| 7219 | |
| 7220 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || |
| 7221 | !info->attrs[NL80211_ATTR_STATUS_CODE] || |
| 7222 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || |
| 7223 | !info->attrs[NL80211_ATTR_IE] || |
| 7224 | !info->attrs[NL80211_ATTR_MAC]) |
| 7225 | return -EINVAL; |
| 7226 | |
| 7227 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 7228 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); |
| 7229 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); |
| 7230 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); |
| 7231 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7232 | return rdev_tdls_mgmt(rdev, dev, peer, action_code, |
| 7233 | dialog_token, status_code, |
| 7234 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 7235 | nla_len(info->attrs[NL80211_ATTR_IE])); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7236 | } |
| 7237 | |
| 7238 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) |
| 7239 | { |
| 7240 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7241 | struct net_device *dev = info->user_ptr[1]; |
| 7242 | enum nl80211_tdls_operation operation; |
| 7243 | u8 *peer; |
| 7244 | |
| 7245 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 7246 | !rdev->ops->tdls_oper) |
| 7247 | return -EOPNOTSUPP; |
| 7248 | |
| 7249 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || |
| 7250 | !info->attrs[NL80211_ATTR_MAC]) |
| 7251 | return -EINVAL; |
| 7252 | |
| 7253 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); |
| 7254 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 7255 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7256 | return rdev_tdls_oper(rdev, dev, peer, operation); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7257 | } |
| 7258 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7259 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
| 7260 | struct genl_info *info) |
| 7261 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7262 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7263 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7264 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7265 | struct sk_buff *msg; |
| 7266 | void *hdr; |
| 7267 | u64 cookie; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7268 | u32 duration; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7269 | int err; |
| 7270 | |
| 7271 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 7272 | !info->attrs[NL80211_ATTR_DURATION]) |
| 7273 | return -EINVAL; |
| 7274 | |
| 7275 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
| 7276 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 7277 | if (!rdev->ops->remain_on_channel || |
| 7278 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7279 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7280 | |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 7281 | /* |
| 7282 | * We should be on that channel for at least a minimum amount of |
| 7283 | * time (10ms) but no longer than the driver supports. |
| 7284 | */ |
| 7285 | if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 7286 | duration > rdev->wiphy.max_remain_on_channel_duration) |
| 7287 | return -EINVAL; |
| 7288 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7289 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 7290 | if (err) |
| 7291 | return err; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7292 | |
| 7293 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7294 | if (!msg) |
| 7295 | return -ENOMEM; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7296 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7297 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7298 | NL80211_CMD_REMAIN_ON_CHANNEL); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 7299 | if (!hdr) { |
| 7300 | err = -ENOBUFS; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7301 | goto free_msg; |
| 7302 | } |
| 7303 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7304 | err = rdev_remain_on_channel(rdev, wdev, chandef.chan, |
| 7305 | duration, &cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7306 | |
| 7307 | if (err) |
| 7308 | goto free_msg; |
| 7309 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7310 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 7311 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7312 | |
| 7313 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7314 | |
| 7315 | return genlmsg_reply(msg, info); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7316 | |
| 7317 | nla_put_failure: |
| 7318 | err = -ENOBUFS; |
| 7319 | free_msg: |
| 7320 | nlmsg_free(msg); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7321 | return err; |
| 7322 | } |
| 7323 | |
| 7324 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, |
| 7325 | struct genl_info *info) |
| 7326 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7327 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7328 | struct wireless_dev *wdev = info->user_ptr[1]; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7329 | u64 cookie; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7330 | |
| 7331 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 7332 | return -EINVAL; |
| 7333 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7334 | if (!rdev->ops->cancel_remain_on_channel) |
| 7335 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7336 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7337 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 7338 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7339 | return rdev_cancel_remain_on_channel(rdev, wdev, cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7340 | } |
| 7341 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7342 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
| 7343 | u8 *rates, u8 rates_len) |
| 7344 | { |
| 7345 | u8 i; |
| 7346 | u32 mask = 0; |
| 7347 | |
| 7348 | for (i = 0; i < rates_len; i++) { |
| 7349 | int rate = (rates[i] & 0x7f) * 5; |
| 7350 | int ridx; |
| 7351 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { |
| 7352 | struct ieee80211_rate *srate = |
| 7353 | &sband->bitrates[ridx]; |
| 7354 | if (rate == srate->bitrate) { |
| 7355 | mask |= 1 << ridx; |
| 7356 | break; |
| 7357 | } |
| 7358 | } |
| 7359 | if (ridx == sband->n_bitrates) |
| 7360 | return 0; /* rate not found */ |
| 7361 | } |
| 7362 | |
| 7363 | return mask; |
| 7364 | } |
| 7365 | |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7366 | static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, |
| 7367 | u8 *rates, u8 rates_len, |
| 7368 | u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) |
| 7369 | { |
| 7370 | u8 i; |
| 7371 | |
| 7372 | memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); |
| 7373 | |
| 7374 | for (i = 0; i < rates_len; i++) { |
| 7375 | int ridx, rbit; |
| 7376 | |
| 7377 | ridx = rates[i] / 8; |
| 7378 | rbit = BIT(rates[i] % 8); |
| 7379 | |
| 7380 | /* check validity */ |
Dan Carpenter | 910570b5 | 2012-02-01 10:42:11 +0300 | [diff] [blame] | 7381 | if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7382 | return false; |
| 7383 | |
| 7384 | /* check availability */ |
| 7385 | if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) |
| 7386 | mcs[ridx] |= rbit; |
| 7387 | else |
| 7388 | return false; |
| 7389 | } |
| 7390 | |
| 7391 | return true; |
| 7392 | } |
| 7393 | |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 7394 | static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map) |
| 7395 | { |
| 7396 | u16 mcs_mask = 0; |
| 7397 | |
| 7398 | switch (vht_mcs_map) { |
| 7399 | case IEEE80211_VHT_MCS_NOT_SUPPORTED: |
| 7400 | break; |
| 7401 | case IEEE80211_VHT_MCS_SUPPORT_0_7: |
| 7402 | mcs_mask = 0x00FF; |
| 7403 | break; |
| 7404 | case IEEE80211_VHT_MCS_SUPPORT_0_8: |
| 7405 | mcs_mask = 0x01FF; |
| 7406 | break; |
| 7407 | case IEEE80211_VHT_MCS_SUPPORT_0_9: |
| 7408 | mcs_mask = 0x03FF; |
| 7409 | break; |
| 7410 | default: |
| 7411 | break; |
| 7412 | } |
| 7413 | |
| 7414 | return mcs_mask; |
| 7415 | } |
| 7416 | |
| 7417 | static void vht_build_mcs_mask(u16 vht_mcs_map, |
| 7418 | u16 vht_mcs_mask[NL80211_VHT_NSS_MAX]) |
| 7419 | { |
| 7420 | u8 nss; |
| 7421 | |
| 7422 | for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) { |
| 7423 | vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03); |
| 7424 | vht_mcs_map >>= 2; |
| 7425 | } |
| 7426 | } |
| 7427 | |
| 7428 | static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband, |
| 7429 | struct nl80211_txrate_vht *txrate, |
| 7430 | u16 mcs[NL80211_VHT_NSS_MAX]) |
| 7431 | { |
| 7432 | u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); |
| 7433 | u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {}; |
| 7434 | u8 i; |
| 7435 | |
| 7436 | if (!sband->vht_cap.vht_supported) |
| 7437 | return false; |
| 7438 | |
| 7439 | memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX); |
| 7440 | |
| 7441 | /* Build vht_mcs_mask from VHT capabilities */ |
| 7442 | vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask); |
| 7443 | |
| 7444 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) { |
| 7445 | if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i]) |
| 7446 | mcs[i] = txrate->mcs[i]; |
| 7447 | else |
| 7448 | return false; |
| 7449 | } |
| 7450 | |
| 7451 | return true; |
| 7452 | } |
| 7453 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 7454 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7455 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
| 7456 | .len = NL80211_MAX_SUPP_RATES }, |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 7457 | [NL80211_TXRATE_HT] = { .type = NLA_BINARY, |
| 7458 | .len = NL80211_MAX_SUPP_HT_RATES }, |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 7459 | [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)}, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7460 | }; |
| 7461 | |
| 7462 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, |
| 7463 | struct genl_info *info) |
| 7464 | { |
| 7465 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7466 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7467 | struct cfg80211_bitrate_mask mask; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7468 | int rem, i; |
| 7469 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7470 | struct nlattr *tx_rates; |
| 7471 | struct ieee80211_supported_band *sband; |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 7472 | u16 vht_tx_mcs_map; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7473 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7474 | if (!rdev->ops->set_bitrate_mask) |
| 7475 | return -EOPNOTSUPP; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7476 | |
| 7477 | memset(&mask, 0, sizeof(mask)); |
| 7478 | /* Default to all rates enabled */ |
| 7479 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) { |
| 7480 | sband = rdev->wiphy.bands[i]; |
Janusz Dziedzic | 7869303 | 2013-12-03 09:50:44 +0100 | [diff] [blame] | 7481 | |
| 7482 | if (!sband) |
| 7483 | continue; |
| 7484 | |
| 7485 | mask.control[i].legacy = (1 << sband->n_bitrates) - 1; |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 7486 | memcpy(mask.control[i].ht_mcs, |
Janusz Dziedzic | 7869303 | 2013-12-03 09:50:44 +0100 | [diff] [blame] | 7487 | sband->ht_cap.mcs.rx_mask, |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 7488 | sizeof(mask.control[i].ht_mcs)); |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 7489 | |
| 7490 | if (!sband->vht_cap.vht_supported) |
| 7491 | continue; |
| 7492 | |
| 7493 | vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); |
| 7494 | 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] | 7495 | } |
| 7496 | |
Janusz Dziedzic | b9243ab | 2013-12-05 10:02:14 +0100 | [diff] [blame] | 7497 | /* if no rates are given set it back to the defaults */ |
| 7498 | if (!info->attrs[NL80211_ATTR_TX_RATES]) |
| 7499 | goto out; |
| 7500 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7501 | /* |
| 7502 | * The nested attribute uses enum nl80211_band as the index. This maps |
| 7503 | * directly to the enum ieee80211_band values used in cfg80211. |
| 7504 | */ |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7505 | BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7506 | nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) |
| 7507 | { |
| 7508 | enum ieee80211_band band = nla_type(tx_rates); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7509 | if (band < 0 || band >= IEEE80211_NUM_BANDS) |
| 7510 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7511 | sband = rdev->wiphy.bands[band]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7512 | if (sband == NULL) |
| 7513 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7514 | nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), |
| 7515 | nla_len(tx_rates), nl80211_txattr_policy); |
| 7516 | if (tb[NL80211_TXRATE_LEGACY]) { |
| 7517 | mask.control[band].legacy = rateset_to_mask( |
| 7518 | sband, |
| 7519 | nla_data(tb[NL80211_TXRATE_LEGACY]), |
| 7520 | nla_len(tb[NL80211_TXRATE_LEGACY])); |
Bala Shanmugam | 218d2e2 | 2012-04-20 19:12:58 +0530 | [diff] [blame] | 7521 | if ((mask.control[band].legacy == 0) && |
| 7522 | nla_len(tb[NL80211_TXRATE_LEGACY])) |
| 7523 | return -EINVAL; |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7524 | } |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 7525 | if (tb[NL80211_TXRATE_HT]) { |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7526 | if (!ht_rateset_to_mask( |
| 7527 | sband, |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 7528 | nla_data(tb[NL80211_TXRATE_HT]), |
| 7529 | nla_len(tb[NL80211_TXRATE_HT]), |
| 7530 | mask.control[band].ht_mcs)) |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7531 | return -EINVAL; |
| 7532 | } |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 7533 | if (tb[NL80211_TXRATE_VHT]) { |
| 7534 | if (!vht_set_mcs_mask( |
| 7535 | sband, |
| 7536 | nla_data(tb[NL80211_TXRATE_VHT]), |
| 7537 | mask.control[band].vht_mcs)) |
| 7538 | return -EINVAL; |
| 7539 | } |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7540 | |
| 7541 | if (mask.control[band].legacy == 0) { |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 7542 | /* don't allow empty legacy rates if HT or VHT |
| 7543 | * are not even supported. |
| 7544 | */ |
| 7545 | if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported || |
| 7546 | rdev->wiphy.bands[band]->vht_cap.vht_supported)) |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7547 | return -EINVAL; |
| 7548 | |
| 7549 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 7550 | if (mask.control[band].ht_mcs[i]) |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 7551 | goto out; |
| 7552 | |
| 7553 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) |
| 7554 | if (mask.control[band].vht_mcs[i]) |
| 7555 | goto out; |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7556 | |
| 7557 | /* legacy and mcs rates may not be both empty */ |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 7558 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7559 | } |
| 7560 | } |
| 7561 | |
Janusz Dziedzic | b9243ab | 2013-12-05 10:02:14 +0100 | [diff] [blame] | 7562 | out: |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7563 | return rdev_set_bitrate_mask(rdev, dev, NULL, &mask); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7564 | } |
| 7565 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7566 | 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] | 7567 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7568 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7569 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7570 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7571 | |
| 7572 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) |
| 7573 | return -EINVAL; |
| 7574 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7575 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
| 7576 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7577 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7578 | switch (wdev->iftype) { |
| 7579 | case NL80211_IFTYPE_STATION: |
| 7580 | case NL80211_IFTYPE_ADHOC: |
| 7581 | case NL80211_IFTYPE_P2P_CLIENT: |
| 7582 | case NL80211_IFTYPE_AP: |
| 7583 | case NL80211_IFTYPE_AP_VLAN: |
| 7584 | case NL80211_IFTYPE_MESH_POINT: |
| 7585 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7586 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7587 | break; |
| 7588 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7589 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7590 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7591 | |
| 7592 | /* not much point in registering if we can't reply */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7593 | if (!rdev->ops->mgmt_tx) |
| 7594 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7595 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7596 | return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7597 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
| 7598 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7599 | } |
| 7600 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7601 | 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] | 7602 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7603 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7604 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7605 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7606 | int err; |
Johannes Berg | d64d373 | 2011-11-10 09:44:46 +0100 | [diff] [blame] | 7607 | void *hdr = NULL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7608 | u64 cookie; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7609 | struct sk_buff *msg = NULL; |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7610 | struct cfg80211_mgmt_tx_params params = { |
| 7611 | .dont_wait_for_ack = |
| 7612 | info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK], |
| 7613 | }; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7614 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7615 | if (!info->attrs[NL80211_ATTR_FRAME]) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7616 | return -EINVAL; |
| 7617 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7618 | if (!rdev->ops->mgmt_tx) |
| 7619 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7620 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7621 | switch (wdev->iftype) { |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 7622 | case NL80211_IFTYPE_P2P_DEVICE: |
| 7623 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 7624 | return -EINVAL; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7625 | case NL80211_IFTYPE_STATION: |
| 7626 | case NL80211_IFTYPE_ADHOC: |
| 7627 | case NL80211_IFTYPE_P2P_CLIENT: |
| 7628 | case NL80211_IFTYPE_AP: |
| 7629 | case NL80211_IFTYPE_AP_VLAN: |
| 7630 | case NL80211_IFTYPE_MESH_POINT: |
| 7631 | case NL80211_IFTYPE_P2P_GO: |
| 7632 | break; |
| 7633 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7634 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7635 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7636 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7637 | if (info->attrs[NL80211_ATTR_DURATION]) { |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 7638 | if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7639 | return -EINVAL; |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7640 | params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 7641 | |
| 7642 | /* |
| 7643 | * We should wait on the channel for at least a minimum amount |
| 7644 | * of time (10ms) but no longer than the driver supports. |
| 7645 | */ |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7646 | if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 7647 | params.wait > rdev->wiphy.max_remain_on_channel_duration) |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 7648 | return -EINVAL; |
| 7649 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7650 | } |
| 7651 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7652 | params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7653 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7654 | if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 7655 | return -EINVAL; |
| 7656 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7657 | 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] | 7658 | |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 7659 | /* get the channel if any has been specified, otherwise pass NULL to |
| 7660 | * the driver. The latter will use the current one |
| 7661 | */ |
| 7662 | chandef.chan = NULL; |
| 7663 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 7664 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 7665 | if (err) |
| 7666 | return err; |
| 7667 | } |
| 7668 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7669 | if (!chandef.chan && params.offchan) |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 7670 | return -EINVAL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7671 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7672 | if (!params.dont_wait_for_ack) { |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7673 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 7674 | if (!msg) |
| 7675 | return -ENOMEM; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7676 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7677 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7678 | NL80211_CMD_FRAME); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 7679 | if (!hdr) { |
| 7680 | err = -ENOBUFS; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7681 | goto free_msg; |
| 7682 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7683 | } |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7684 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7685 | params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]); |
| 7686 | params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]); |
| 7687 | params.chan = chandef.chan; |
| 7688 | err = cfg80211_mlme_mgmt_tx(rdev, wdev, ¶ms, &cookie); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7689 | if (err) |
| 7690 | goto free_msg; |
| 7691 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7692 | if (msg) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7693 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 7694 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7695 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7696 | genlmsg_end(msg, hdr); |
| 7697 | return genlmsg_reply(msg, info); |
| 7698 | } |
| 7699 | |
| 7700 | return 0; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7701 | |
| 7702 | nla_put_failure: |
| 7703 | err = -ENOBUFS; |
| 7704 | free_msg: |
| 7705 | nlmsg_free(msg); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7706 | return err; |
| 7707 | } |
| 7708 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7709 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
| 7710 | { |
| 7711 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7712 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7713 | u64 cookie; |
| 7714 | |
| 7715 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 7716 | return -EINVAL; |
| 7717 | |
| 7718 | if (!rdev->ops->mgmt_tx_cancel_wait) |
| 7719 | return -EOPNOTSUPP; |
| 7720 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7721 | switch (wdev->iftype) { |
| 7722 | case NL80211_IFTYPE_STATION: |
| 7723 | case NL80211_IFTYPE_ADHOC: |
| 7724 | case NL80211_IFTYPE_P2P_CLIENT: |
| 7725 | case NL80211_IFTYPE_AP: |
| 7726 | case NL80211_IFTYPE_AP_VLAN: |
| 7727 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7728 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7729 | break; |
| 7730 | default: |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7731 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7732 | } |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7733 | |
| 7734 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 7735 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7736 | return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie); |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7737 | } |
| 7738 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7739 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
| 7740 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7741 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7742 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7743 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7744 | u8 ps_state; |
| 7745 | bool state; |
| 7746 | int err; |
| 7747 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7748 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
| 7749 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7750 | |
| 7751 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); |
| 7752 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7753 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
| 7754 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7755 | |
| 7756 | wdev = dev->ieee80211_ptr; |
| 7757 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7758 | if (!rdev->ops->set_power_mgmt) |
| 7759 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7760 | |
| 7761 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; |
| 7762 | |
| 7763 | if (state == wdev->ps) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7764 | return 0; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7765 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7766 | err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7767 | if (!err) |
| 7768 | wdev->ps = state; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7769 | return err; |
| 7770 | } |
| 7771 | |
| 7772 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) |
| 7773 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7774 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7775 | enum nl80211_ps_state ps_state; |
| 7776 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7777 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7778 | struct sk_buff *msg; |
| 7779 | void *hdr; |
| 7780 | int err; |
| 7781 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7782 | wdev = dev->ieee80211_ptr; |
| 7783 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7784 | if (!rdev->ops->set_power_mgmt) |
| 7785 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7786 | |
| 7787 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7788 | if (!msg) |
| 7789 | return -ENOMEM; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7790 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7791 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7792 | NL80211_CMD_GET_POWER_SAVE); |
| 7793 | if (!hdr) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7794 | err = -ENOBUFS; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7795 | goto free_msg; |
| 7796 | } |
| 7797 | |
| 7798 | if (wdev->ps) |
| 7799 | ps_state = NL80211_PS_ENABLED; |
| 7800 | else |
| 7801 | ps_state = NL80211_PS_DISABLED; |
| 7802 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7803 | if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) |
| 7804 | goto nla_put_failure; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7805 | |
| 7806 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7807 | return genlmsg_reply(msg, info); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7808 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7809 | nla_put_failure: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7810 | err = -ENOBUFS; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7811 | free_msg: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7812 | nlmsg_free(msg); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7813 | return err; |
| 7814 | } |
| 7815 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7816 | static struct nla_policy |
| 7817 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = { |
| 7818 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, |
| 7819 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, |
| 7820 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7821 | [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 }, |
| 7822 | [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 }, |
| 7823 | [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7824 | }; |
| 7825 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7826 | static int nl80211_set_cqm_txe(struct genl_info *info, |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 7827 | u32 rate, u32 pkts, u32 intvl) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7828 | { |
| 7829 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7830 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 7831 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7832 | |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 7833 | if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7834 | return -EINVAL; |
| 7835 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7836 | if (!rdev->ops->set_cqm_txe_config) |
| 7837 | return -EOPNOTSUPP; |
| 7838 | |
| 7839 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
| 7840 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7841 | return -EOPNOTSUPP; |
| 7842 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7843 | return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7844 | } |
| 7845 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7846 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
| 7847 | s32 threshold, u32 hysteresis) |
| 7848 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7849 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7850 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 7851 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7852 | |
| 7853 | if (threshold > 0) |
| 7854 | return -EINVAL; |
| 7855 | |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 7856 | /* disabling - hysteresis should also be zero then */ |
| 7857 | if (threshold == 0) |
| 7858 | hysteresis = 0; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7859 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7860 | if (!rdev->ops->set_cqm_rssi_config) |
| 7861 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7862 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7863 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7864 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7865 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7866 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7867 | return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7868 | } |
| 7869 | |
| 7870 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) |
| 7871 | { |
| 7872 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; |
| 7873 | struct nlattr *cqm; |
| 7874 | int err; |
| 7875 | |
| 7876 | cqm = info->attrs[NL80211_ATTR_CQM]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 7877 | if (!cqm) |
| 7878 | return -EINVAL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7879 | |
| 7880 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, |
| 7881 | nl80211_attr_cqm_policy); |
| 7882 | if (err) |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 7883 | return err; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7884 | |
| 7885 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && |
| 7886 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 7887 | s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
| 7888 | u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7889 | |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 7890 | return nl80211_set_cqm_rssi(info, threshold, hysteresis); |
| 7891 | } |
| 7892 | |
| 7893 | if (attrs[NL80211_ATTR_CQM_TXE_RATE] && |
| 7894 | attrs[NL80211_ATTR_CQM_TXE_PKTS] && |
| 7895 | attrs[NL80211_ATTR_CQM_TXE_INTVL]) { |
| 7896 | u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]); |
| 7897 | u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]); |
| 7898 | u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]); |
| 7899 | |
| 7900 | return nl80211_set_cqm_txe(info, rate, pkts, intvl); |
| 7901 | } |
| 7902 | |
| 7903 | return -EINVAL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7904 | } |
| 7905 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7906 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
| 7907 | { |
| 7908 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7909 | struct net_device *dev = info->user_ptr[1]; |
| 7910 | struct mesh_config cfg; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7911 | struct mesh_setup setup; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7912 | int err; |
| 7913 | |
| 7914 | /* start with default */ |
| 7915 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7916 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7917 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 7918 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7919 | /* and parse parameters if given */ |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 7920 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7921 | if (err) |
| 7922 | return err; |
| 7923 | } |
| 7924 | |
| 7925 | if (!info->attrs[NL80211_ATTR_MESH_ID] || |
| 7926 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) |
| 7927 | return -EINVAL; |
| 7928 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7929 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
| 7930 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 7931 | |
Chun-Yeow Yeoh | 4bb6234 | 2011-11-24 17:15:20 -0800 | [diff] [blame] | 7932 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 7933 | !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, |
| 7934 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 7935 | return -EINVAL; |
| 7936 | |
Marco Porsch | 9bdbf04 | 2013-01-07 16:04:51 +0100 | [diff] [blame] | 7937 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 7938 | setup.beacon_interval = |
| 7939 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 7940 | if (setup.beacon_interval < 10 || |
| 7941 | setup.beacon_interval > 10000) |
| 7942 | return -EINVAL; |
| 7943 | } |
| 7944 | |
| 7945 | if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) { |
| 7946 | setup.dtim_period = |
| 7947 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 7948 | if (setup.dtim_period < 1 || setup.dtim_period > 100) |
| 7949 | return -EINVAL; |
| 7950 | } |
| 7951 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7952 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
| 7953 | /* parse additional setup parameters if given */ |
| 7954 | err = nl80211_parse_mesh_setup(info, &setup); |
| 7955 | if (err) |
| 7956 | return err; |
| 7957 | } |
| 7958 | |
Thomas Pedersen | d37bb18 | 2013-03-04 13:06:13 -0800 | [diff] [blame] | 7959 | if (setup.user_mpm) |
| 7960 | cfg.auto_open_plinks = false; |
| 7961 | |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 7962 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7963 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
| 7964 | if (err) |
| 7965 | return err; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 7966 | } else { |
| 7967 | /* cfg80211_join_mesh() will sort it out */ |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7968 | setup.chandef.chan = NULL; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 7969 | } |
| 7970 | |
Ashok Nagarajan | ffb3cf3 | 2013-06-03 10:33:36 -0700 | [diff] [blame] | 7971 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 7972 | u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 7973 | int n_rates = |
| 7974 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 7975 | struct ieee80211_supported_band *sband; |
| 7976 | |
| 7977 | if (!setup.chandef.chan) |
| 7978 | return -EINVAL; |
| 7979 | |
| 7980 | sband = rdev->wiphy.bands[setup.chandef.chan->band]; |
| 7981 | |
| 7982 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 7983 | &setup.basic_rates); |
| 7984 | if (err) |
| 7985 | return err; |
| 7986 | } |
| 7987 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7988 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7989 | } |
| 7990 | |
| 7991 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) |
| 7992 | { |
| 7993 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7994 | struct net_device *dev = info->user_ptr[1]; |
| 7995 | |
| 7996 | return cfg80211_leave_mesh(rdev, dev); |
| 7997 | } |
| 7998 | |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 7999 | #ifdef CONFIG_PM |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8000 | static int nl80211_send_wowlan_patterns(struct sk_buff *msg, |
| 8001 | struct cfg80211_registered_device *rdev) |
| 8002 | { |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8003 | struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config; |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8004 | struct nlattr *nl_pats, *nl_pat; |
| 8005 | int i, pat_len; |
| 8006 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8007 | if (!wowlan->n_patterns) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8008 | return 0; |
| 8009 | |
| 8010 | nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN); |
| 8011 | if (!nl_pats) |
| 8012 | return -ENOBUFS; |
| 8013 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8014 | for (i = 0; i < wowlan->n_patterns; i++) { |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8015 | nl_pat = nla_nest_start(msg, i + 1); |
| 8016 | if (!nl_pat) |
| 8017 | return -ENOBUFS; |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8018 | pat_len = wowlan->patterns[i].pattern_len; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8019 | 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] | 8020 | wowlan->patterns[i].mask) || |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8021 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
| 8022 | wowlan->patterns[i].pattern) || |
| 8023 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8024 | wowlan->patterns[i].pkt_offset)) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8025 | return -ENOBUFS; |
| 8026 | nla_nest_end(msg, nl_pat); |
| 8027 | } |
| 8028 | nla_nest_end(msg, nl_pats); |
| 8029 | |
| 8030 | return 0; |
| 8031 | } |
| 8032 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8033 | static int nl80211_send_wowlan_tcp(struct sk_buff *msg, |
| 8034 | struct cfg80211_wowlan_tcp *tcp) |
| 8035 | { |
| 8036 | struct nlattr *nl_tcp; |
| 8037 | |
| 8038 | if (!tcp) |
| 8039 | return 0; |
| 8040 | |
| 8041 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); |
| 8042 | if (!nl_tcp) |
| 8043 | return -ENOBUFS; |
| 8044 | |
| 8045 | if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) || |
| 8046 | nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) || |
| 8047 | nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) || |
| 8048 | nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) || |
| 8049 | nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) || |
| 8050 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 8051 | tcp->payload_len, tcp->payload) || |
| 8052 | nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, |
| 8053 | tcp->data_interval) || |
| 8054 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, |
| 8055 | tcp->wake_len, tcp->wake_data) || |
| 8056 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK, |
| 8057 | DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask)) |
| 8058 | return -ENOBUFS; |
| 8059 | |
| 8060 | if (tcp->payload_seq.len && |
| 8061 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ, |
| 8062 | sizeof(tcp->payload_seq), &tcp->payload_seq)) |
| 8063 | return -ENOBUFS; |
| 8064 | |
| 8065 | if (tcp->payload_tok.len && |
| 8066 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, |
| 8067 | sizeof(tcp->payload_tok) + tcp->tokens_size, |
| 8068 | &tcp->payload_tok)) |
| 8069 | return -ENOBUFS; |
| 8070 | |
Johannes Berg | e248ad3 | 2013-05-16 10:24:28 +0200 | [diff] [blame] | 8071 | nla_nest_end(msg, nl_tcp); |
| 8072 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8073 | return 0; |
| 8074 | } |
| 8075 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8076 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 8077 | { |
| 8078 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8079 | struct sk_buff *msg; |
| 8080 | void *hdr; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8081 | u32 size = NLMSG_DEFAULT_SIZE; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8082 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8083 | if (!rdev->wiphy.wowlan) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8084 | return -EOPNOTSUPP; |
| 8085 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8086 | if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) { |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8087 | /* adjust size to have room for all the data */ |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8088 | size += rdev->wiphy.wowlan_config->tcp->tokens_size + |
| 8089 | rdev->wiphy.wowlan_config->tcp->payload_len + |
| 8090 | rdev->wiphy.wowlan_config->tcp->wake_len + |
| 8091 | rdev->wiphy.wowlan_config->tcp->wake_len / 8; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8092 | } |
| 8093 | |
| 8094 | msg = nlmsg_new(size, GFP_KERNEL); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8095 | if (!msg) |
| 8096 | return -ENOMEM; |
| 8097 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8098 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8099 | NL80211_CMD_GET_WOWLAN); |
| 8100 | if (!hdr) |
| 8101 | goto nla_put_failure; |
| 8102 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8103 | if (rdev->wiphy.wowlan_config) { |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8104 | struct nlattr *nl_wowlan; |
| 8105 | |
| 8106 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
| 8107 | if (!nl_wowlan) |
| 8108 | goto nla_put_failure; |
| 8109 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8110 | if ((rdev->wiphy.wowlan_config->any && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8111 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8112 | (rdev->wiphy.wowlan_config->disconnect && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8113 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8114 | (rdev->wiphy.wowlan_config->magic_pkt && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8115 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8116 | (rdev->wiphy.wowlan_config->gtk_rekey_failure && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8117 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8118 | (rdev->wiphy.wowlan_config->eap_identity_req && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8119 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8120 | (rdev->wiphy.wowlan_config->four_way_handshake && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8121 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8122 | (rdev->wiphy.wowlan_config->rfkill_release && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8123 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 8124 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8125 | |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8126 | if (nl80211_send_wowlan_patterns(msg, rdev)) |
| 8127 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8128 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8129 | if (nl80211_send_wowlan_tcp(msg, |
| 8130 | rdev->wiphy.wowlan_config->tcp)) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8131 | goto nla_put_failure; |
| 8132 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8133 | nla_nest_end(msg, nl_wowlan); |
| 8134 | } |
| 8135 | |
| 8136 | genlmsg_end(msg, hdr); |
| 8137 | return genlmsg_reply(msg, info); |
| 8138 | |
| 8139 | nla_put_failure: |
| 8140 | nlmsg_free(msg); |
| 8141 | return -ENOBUFS; |
| 8142 | } |
| 8143 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8144 | static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev, |
| 8145 | struct nlattr *attr, |
| 8146 | struct cfg80211_wowlan *trig) |
| 8147 | { |
| 8148 | struct nlattr *tb[NUM_NL80211_WOWLAN_TCP]; |
| 8149 | struct cfg80211_wowlan_tcp *cfg; |
| 8150 | struct nl80211_wowlan_tcp_data_token *tok = NULL; |
| 8151 | struct nl80211_wowlan_tcp_data_seq *seq = NULL; |
| 8152 | u32 size; |
| 8153 | u32 data_size, wake_size, tokens_size = 0, wake_mask_size; |
| 8154 | int err, port; |
| 8155 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8156 | if (!rdev->wiphy.wowlan->tcp) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8157 | return -EINVAL; |
| 8158 | |
| 8159 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP, |
| 8160 | nla_data(attr), nla_len(attr), |
| 8161 | nl80211_wowlan_tcp_policy); |
| 8162 | if (err) |
| 8163 | return err; |
| 8164 | |
| 8165 | if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] || |
| 8166 | !tb[NL80211_WOWLAN_TCP_DST_IPV4] || |
| 8167 | !tb[NL80211_WOWLAN_TCP_DST_MAC] || |
| 8168 | !tb[NL80211_WOWLAN_TCP_DST_PORT] || |
| 8169 | !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] || |
| 8170 | !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] || |
| 8171 | !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] || |
| 8172 | !tb[NL80211_WOWLAN_TCP_WAKE_MASK]) |
| 8173 | return -EINVAL; |
| 8174 | |
| 8175 | data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8176 | if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8177 | return -EINVAL; |
| 8178 | |
| 8179 | if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) > |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8180 | rdev->wiphy.wowlan->tcp->data_interval_max || |
Johannes Berg | 723d568 | 2013-02-26 13:56:40 +0100 | [diff] [blame] | 8181 | nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8182 | return -EINVAL; |
| 8183 | |
| 8184 | wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8185 | if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8186 | return -EINVAL; |
| 8187 | |
| 8188 | wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]); |
| 8189 | if (wake_mask_size != DIV_ROUND_UP(wake_size, 8)) |
| 8190 | return -EINVAL; |
| 8191 | |
| 8192 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) { |
| 8193 | u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 8194 | |
| 8195 | tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 8196 | tokens_size = tokln - sizeof(*tok); |
| 8197 | |
| 8198 | if (!tok->len || tokens_size % tok->len) |
| 8199 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8200 | if (!rdev->wiphy.wowlan->tcp->tok) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8201 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8202 | if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8203 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8204 | if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8205 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8206 | if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8207 | return -EINVAL; |
| 8208 | if (tok->offset + tok->len > data_size) |
| 8209 | return -EINVAL; |
| 8210 | } |
| 8211 | |
| 8212 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) { |
| 8213 | seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8214 | if (!rdev->wiphy.wowlan->tcp->seq) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8215 | return -EINVAL; |
| 8216 | if (seq->len == 0 || seq->len > 4) |
| 8217 | return -EINVAL; |
| 8218 | if (seq->len + seq->offset > data_size) |
| 8219 | return -EINVAL; |
| 8220 | } |
| 8221 | |
| 8222 | size = sizeof(*cfg); |
| 8223 | size += data_size; |
| 8224 | size += wake_size + wake_mask_size; |
| 8225 | size += tokens_size; |
| 8226 | |
| 8227 | cfg = kzalloc(size, GFP_KERNEL); |
| 8228 | if (!cfg) |
| 8229 | return -ENOMEM; |
| 8230 | cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]); |
| 8231 | cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]); |
| 8232 | memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]), |
| 8233 | ETH_ALEN); |
| 8234 | if (tb[NL80211_WOWLAN_TCP_SRC_PORT]) |
| 8235 | port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]); |
| 8236 | else |
| 8237 | port = 0; |
| 8238 | #ifdef CONFIG_INET |
| 8239 | /* allocate a socket and port for it and use it */ |
| 8240 | err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM, |
| 8241 | IPPROTO_TCP, &cfg->sock, 1); |
| 8242 | if (err) { |
| 8243 | kfree(cfg); |
| 8244 | return err; |
| 8245 | } |
| 8246 | if (inet_csk_get_port(cfg->sock->sk, port)) { |
| 8247 | sock_release(cfg->sock); |
| 8248 | kfree(cfg); |
| 8249 | return -EADDRINUSE; |
| 8250 | } |
| 8251 | cfg->src_port = inet_sk(cfg->sock->sk)->inet_num; |
| 8252 | #else |
| 8253 | if (!port) { |
| 8254 | kfree(cfg); |
| 8255 | return -EINVAL; |
| 8256 | } |
| 8257 | cfg->src_port = port; |
| 8258 | #endif |
| 8259 | |
| 8260 | cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]); |
| 8261 | cfg->payload_len = data_size; |
| 8262 | cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size; |
| 8263 | memcpy((void *)cfg->payload, |
| 8264 | nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]), |
| 8265 | data_size); |
| 8266 | if (seq) |
| 8267 | cfg->payload_seq = *seq; |
| 8268 | cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]); |
| 8269 | cfg->wake_len = wake_size; |
| 8270 | cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size; |
| 8271 | memcpy((void *)cfg->wake_data, |
| 8272 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]), |
| 8273 | wake_size); |
| 8274 | cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size + |
| 8275 | data_size + wake_size; |
| 8276 | memcpy((void *)cfg->wake_mask, |
| 8277 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]), |
| 8278 | wake_mask_size); |
| 8279 | if (tok) { |
| 8280 | cfg->tokens_size = tokens_size; |
| 8281 | memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size); |
| 8282 | } |
| 8283 | |
| 8284 | trig->tcp = cfg; |
| 8285 | |
| 8286 | return 0; |
| 8287 | } |
| 8288 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8289 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 8290 | { |
| 8291 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8292 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8293 | struct cfg80211_wowlan new_triggers = {}; |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8294 | struct cfg80211_wowlan *ntrig; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8295 | const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8296 | int err, i; |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8297 | bool prev_enabled = rdev->wiphy.wowlan_config; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8298 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8299 | if (!wowlan) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8300 | return -EOPNOTSUPP; |
| 8301 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8302 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) { |
| 8303 | cfg80211_rdev_free_wowlan(rdev); |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8304 | rdev->wiphy.wowlan_config = NULL; |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8305 | goto set_wakeup; |
| 8306 | } |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8307 | |
| 8308 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG, |
| 8309 | nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 8310 | nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 8311 | nl80211_wowlan_policy); |
| 8312 | if (err) |
| 8313 | return err; |
| 8314 | |
| 8315 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { |
| 8316 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) |
| 8317 | return -EINVAL; |
| 8318 | new_triggers.any = true; |
| 8319 | } |
| 8320 | |
| 8321 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { |
| 8322 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) |
| 8323 | return -EINVAL; |
| 8324 | new_triggers.disconnect = true; |
| 8325 | } |
| 8326 | |
| 8327 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { |
| 8328 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) |
| 8329 | return -EINVAL; |
| 8330 | new_triggers.magic_pkt = true; |
| 8331 | } |
| 8332 | |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 8333 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
| 8334 | return -EINVAL; |
| 8335 | |
| 8336 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { |
| 8337 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) |
| 8338 | return -EINVAL; |
| 8339 | new_triggers.gtk_rekey_failure = true; |
| 8340 | } |
| 8341 | |
| 8342 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { |
| 8343 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) |
| 8344 | return -EINVAL; |
| 8345 | new_triggers.eap_identity_req = true; |
| 8346 | } |
| 8347 | |
| 8348 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { |
| 8349 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) |
| 8350 | return -EINVAL; |
| 8351 | new_triggers.four_way_handshake = true; |
| 8352 | } |
| 8353 | |
| 8354 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { |
| 8355 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) |
| 8356 | return -EINVAL; |
| 8357 | new_triggers.rfkill_release = true; |
| 8358 | } |
| 8359 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8360 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
| 8361 | struct nlattr *pat; |
| 8362 | int n_patterns = 0; |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8363 | int rem, pat_len, mask_len, pkt_offset; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8364 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8365 | |
| 8366 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 8367 | rem) |
| 8368 | n_patterns++; |
| 8369 | if (n_patterns > wowlan->n_patterns) |
| 8370 | return -EINVAL; |
| 8371 | |
| 8372 | new_triggers.patterns = kcalloc(n_patterns, |
| 8373 | sizeof(new_triggers.patterns[0]), |
| 8374 | GFP_KERNEL); |
| 8375 | if (!new_triggers.patterns) |
| 8376 | return -ENOMEM; |
| 8377 | |
| 8378 | new_triggers.n_patterns = n_patterns; |
| 8379 | i = 0; |
| 8380 | |
| 8381 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 8382 | rem) { |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8383 | nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat), |
| 8384 | nla_len(pat), NULL); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8385 | err = -EINVAL; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8386 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
| 8387 | !pat_tb[NL80211_PKTPAT_PATTERN]) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8388 | goto error; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8389 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8390 | mask_len = DIV_ROUND_UP(pat_len, 8); |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8391 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8392 | goto error; |
| 8393 | if (pat_len > wowlan->pattern_max_len || |
| 8394 | pat_len < wowlan->pattern_min_len) |
| 8395 | goto error; |
| 8396 | |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8397 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8398 | pkt_offset = 0; |
| 8399 | else |
| 8400 | pkt_offset = nla_get_u32( |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8401 | pat_tb[NL80211_PKTPAT_OFFSET]); |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8402 | if (pkt_offset > wowlan->max_pkt_offset) |
| 8403 | goto error; |
| 8404 | new_triggers.patterns[i].pkt_offset = pkt_offset; |
| 8405 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8406 | new_triggers.patterns[i].mask = |
| 8407 | kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 8408 | if (!new_triggers.patterns[i].mask) { |
| 8409 | err = -ENOMEM; |
| 8410 | goto error; |
| 8411 | } |
| 8412 | new_triggers.patterns[i].pattern = |
| 8413 | new_triggers.patterns[i].mask + mask_len; |
| 8414 | memcpy(new_triggers.patterns[i].mask, |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8415 | nla_data(pat_tb[NL80211_PKTPAT_MASK]), |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8416 | mask_len); |
| 8417 | new_triggers.patterns[i].pattern_len = pat_len; |
| 8418 | memcpy(new_triggers.patterns[i].pattern, |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8419 | nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8420 | pat_len); |
| 8421 | i++; |
| 8422 | } |
| 8423 | } |
| 8424 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8425 | if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) { |
| 8426 | err = nl80211_parse_wowlan_tcp( |
| 8427 | rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION], |
| 8428 | &new_triggers); |
| 8429 | if (err) |
| 8430 | goto error; |
| 8431 | } |
| 8432 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8433 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL); |
| 8434 | if (!ntrig) { |
| 8435 | err = -ENOMEM; |
| 8436 | goto error; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8437 | } |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8438 | cfg80211_rdev_free_wowlan(rdev); |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8439 | rdev->wiphy.wowlan_config = ntrig; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8440 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8441 | set_wakeup: |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8442 | if (rdev->ops->set_wakeup && |
| 8443 | prev_enabled != !!rdev->wiphy.wowlan_config) |
| 8444 | rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config); |
Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame] | 8445 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8446 | return 0; |
| 8447 | error: |
| 8448 | for (i = 0; i < new_triggers.n_patterns; i++) |
| 8449 | kfree(new_triggers.patterns[i].mask); |
| 8450 | kfree(new_triggers.patterns); |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8451 | if (new_triggers.tcp && new_triggers.tcp->sock) |
| 8452 | sock_release(new_triggers.tcp->sock); |
| 8453 | kfree(new_triggers.tcp); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8454 | return err; |
| 8455 | } |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 8456 | #endif |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8457 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 8458 | static int nl80211_send_coalesce_rules(struct sk_buff *msg, |
| 8459 | struct cfg80211_registered_device *rdev) |
| 8460 | { |
| 8461 | struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules; |
| 8462 | int i, j, pat_len; |
| 8463 | struct cfg80211_coalesce_rules *rule; |
| 8464 | |
| 8465 | if (!rdev->coalesce->n_rules) |
| 8466 | return 0; |
| 8467 | |
| 8468 | nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE); |
| 8469 | if (!nl_rules) |
| 8470 | return -ENOBUFS; |
| 8471 | |
| 8472 | for (i = 0; i < rdev->coalesce->n_rules; i++) { |
| 8473 | nl_rule = nla_nest_start(msg, i + 1); |
| 8474 | if (!nl_rule) |
| 8475 | return -ENOBUFS; |
| 8476 | |
| 8477 | rule = &rdev->coalesce->rules[i]; |
| 8478 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY, |
| 8479 | rule->delay)) |
| 8480 | return -ENOBUFS; |
| 8481 | |
| 8482 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION, |
| 8483 | rule->condition)) |
| 8484 | return -ENOBUFS; |
| 8485 | |
| 8486 | nl_pats = nla_nest_start(msg, |
| 8487 | NL80211_ATTR_COALESCE_RULE_PKT_PATTERN); |
| 8488 | if (!nl_pats) |
| 8489 | return -ENOBUFS; |
| 8490 | |
| 8491 | for (j = 0; j < rule->n_patterns; j++) { |
| 8492 | nl_pat = nla_nest_start(msg, j + 1); |
| 8493 | if (!nl_pat) |
| 8494 | return -ENOBUFS; |
| 8495 | pat_len = rule->patterns[j].pattern_len; |
| 8496 | if (nla_put(msg, NL80211_PKTPAT_MASK, |
| 8497 | DIV_ROUND_UP(pat_len, 8), |
| 8498 | rule->patterns[j].mask) || |
| 8499 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
| 8500 | rule->patterns[j].pattern) || |
| 8501 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, |
| 8502 | rule->patterns[j].pkt_offset)) |
| 8503 | return -ENOBUFS; |
| 8504 | nla_nest_end(msg, nl_pat); |
| 8505 | } |
| 8506 | nla_nest_end(msg, nl_pats); |
| 8507 | nla_nest_end(msg, nl_rule); |
| 8508 | } |
| 8509 | nla_nest_end(msg, nl_rules); |
| 8510 | |
| 8511 | return 0; |
| 8512 | } |
| 8513 | |
| 8514 | static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info) |
| 8515 | { |
| 8516 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8517 | struct sk_buff *msg; |
| 8518 | void *hdr; |
| 8519 | |
| 8520 | if (!rdev->wiphy.coalesce) |
| 8521 | return -EOPNOTSUPP; |
| 8522 | |
| 8523 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 8524 | if (!msg) |
| 8525 | return -ENOMEM; |
| 8526 | |
| 8527 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 8528 | NL80211_CMD_GET_COALESCE); |
| 8529 | if (!hdr) |
| 8530 | goto nla_put_failure; |
| 8531 | |
| 8532 | if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev)) |
| 8533 | goto nla_put_failure; |
| 8534 | |
| 8535 | genlmsg_end(msg, hdr); |
| 8536 | return genlmsg_reply(msg, info); |
| 8537 | |
| 8538 | nla_put_failure: |
| 8539 | nlmsg_free(msg); |
| 8540 | return -ENOBUFS; |
| 8541 | } |
| 8542 | |
| 8543 | void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev) |
| 8544 | { |
| 8545 | struct cfg80211_coalesce *coalesce = rdev->coalesce; |
| 8546 | int i, j; |
| 8547 | struct cfg80211_coalesce_rules *rule; |
| 8548 | |
| 8549 | if (!coalesce) |
| 8550 | return; |
| 8551 | |
| 8552 | for (i = 0; i < coalesce->n_rules; i++) { |
| 8553 | rule = &coalesce->rules[i]; |
| 8554 | for (j = 0; j < rule->n_patterns; j++) |
| 8555 | kfree(rule->patterns[j].mask); |
| 8556 | kfree(rule->patterns); |
| 8557 | } |
| 8558 | kfree(coalesce->rules); |
| 8559 | kfree(coalesce); |
| 8560 | rdev->coalesce = NULL; |
| 8561 | } |
| 8562 | |
| 8563 | static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev, |
| 8564 | struct nlattr *rule, |
| 8565 | struct cfg80211_coalesce_rules *new_rule) |
| 8566 | { |
| 8567 | int err, i; |
| 8568 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; |
| 8569 | struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat; |
| 8570 | int rem, pat_len, mask_len, pkt_offset, n_patterns = 0; |
| 8571 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
| 8572 | |
| 8573 | err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule), |
| 8574 | nla_len(rule), nl80211_coalesce_policy); |
| 8575 | if (err) |
| 8576 | return err; |
| 8577 | |
| 8578 | if (tb[NL80211_ATTR_COALESCE_RULE_DELAY]) |
| 8579 | new_rule->delay = |
| 8580 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]); |
| 8581 | if (new_rule->delay > coalesce->max_delay) |
| 8582 | return -EINVAL; |
| 8583 | |
| 8584 | if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION]) |
| 8585 | new_rule->condition = |
| 8586 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]); |
| 8587 | if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH && |
| 8588 | new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH) |
| 8589 | return -EINVAL; |
| 8590 | |
| 8591 | if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN]) |
| 8592 | return -EINVAL; |
| 8593 | |
| 8594 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], |
| 8595 | rem) |
| 8596 | n_patterns++; |
| 8597 | if (n_patterns > coalesce->n_patterns) |
| 8598 | return -EINVAL; |
| 8599 | |
| 8600 | new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]), |
| 8601 | GFP_KERNEL); |
| 8602 | if (!new_rule->patterns) |
| 8603 | return -ENOMEM; |
| 8604 | |
| 8605 | new_rule->n_patterns = n_patterns; |
| 8606 | i = 0; |
| 8607 | |
| 8608 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], |
| 8609 | rem) { |
| 8610 | nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat), |
| 8611 | nla_len(pat), NULL); |
| 8612 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
| 8613 | !pat_tb[NL80211_PKTPAT_PATTERN]) |
| 8614 | return -EINVAL; |
| 8615 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
| 8616 | mask_len = DIV_ROUND_UP(pat_len, 8); |
| 8617 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
| 8618 | return -EINVAL; |
| 8619 | if (pat_len > coalesce->pattern_max_len || |
| 8620 | pat_len < coalesce->pattern_min_len) |
| 8621 | return -EINVAL; |
| 8622 | |
| 8623 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
| 8624 | pkt_offset = 0; |
| 8625 | else |
| 8626 | pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]); |
| 8627 | if (pkt_offset > coalesce->max_pkt_offset) |
| 8628 | return -EINVAL; |
| 8629 | new_rule->patterns[i].pkt_offset = pkt_offset; |
| 8630 | |
| 8631 | new_rule->patterns[i].mask = |
| 8632 | kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 8633 | if (!new_rule->patterns[i].mask) |
| 8634 | return -ENOMEM; |
| 8635 | new_rule->patterns[i].pattern = |
| 8636 | new_rule->patterns[i].mask + mask_len; |
| 8637 | memcpy(new_rule->patterns[i].mask, |
| 8638 | nla_data(pat_tb[NL80211_PKTPAT_MASK]), mask_len); |
| 8639 | new_rule->patterns[i].pattern_len = pat_len; |
| 8640 | memcpy(new_rule->patterns[i].pattern, |
| 8641 | nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), pat_len); |
| 8642 | i++; |
| 8643 | } |
| 8644 | |
| 8645 | return 0; |
| 8646 | } |
| 8647 | |
| 8648 | static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info) |
| 8649 | { |
| 8650 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8651 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; |
| 8652 | struct cfg80211_coalesce new_coalesce = {}; |
| 8653 | struct cfg80211_coalesce *n_coalesce; |
| 8654 | int err, rem_rule, n_rules = 0, i, j; |
| 8655 | struct nlattr *rule; |
| 8656 | struct cfg80211_coalesce_rules *tmp_rule; |
| 8657 | |
| 8658 | if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce) |
| 8659 | return -EOPNOTSUPP; |
| 8660 | |
| 8661 | if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) { |
| 8662 | cfg80211_rdev_free_coalesce(rdev); |
| 8663 | rdev->ops->set_coalesce(&rdev->wiphy, NULL); |
| 8664 | return 0; |
| 8665 | } |
| 8666 | |
| 8667 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], |
| 8668 | rem_rule) |
| 8669 | n_rules++; |
| 8670 | if (n_rules > coalesce->n_rules) |
| 8671 | return -EINVAL; |
| 8672 | |
| 8673 | new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]), |
| 8674 | GFP_KERNEL); |
| 8675 | if (!new_coalesce.rules) |
| 8676 | return -ENOMEM; |
| 8677 | |
| 8678 | new_coalesce.n_rules = n_rules; |
| 8679 | i = 0; |
| 8680 | |
| 8681 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], |
| 8682 | rem_rule) { |
| 8683 | err = nl80211_parse_coalesce_rule(rdev, rule, |
| 8684 | &new_coalesce.rules[i]); |
| 8685 | if (err) |
| 8686 | goto error; |
| 8687 | |
| 8688 | i++; |
| 8689 | } |
| 8690 | |
| 8691 | err = rdev->ops->set_coalesce(&rdev->wiphy, &new_coalesce); |
| 8692 | if (err) |
| 8693 | goto error; |
| 8694 | |
| 8695 | n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL); |
| 8696 | if (!n_coalesce) { |
| 8697 | err = -ENOMEM; |
| 8698 | goto error; |
| 8699 | } |
| 8700 | cfg80211_rdev_free_coalesce(rdev); |
| 8701 | rdev->coalesce = n_coalesce; |
| 8702 | |
| 8703 | return 0; |
| 8704 | error: |
| 8705 | for (i = 0; i < new_coalesce.n_rules; i++) { |
| 8706 | tmp_rule = &new_coalesce.rules[i]; |
| 8707 | for (j = 0; j < tmp_rule->n_patterns; j++) |
| 8708 | kfree(tmp_rule->patterns[j].mask); |
| 8709 | kfree(tmp_rule->patterns); |
| 8710 | } |
| 8711 | kfree(new_coalesce.rules); |
| 8712 | |
| 8713 | return err; |
| 8714 | } |
| 8715 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 8716 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
| 8717 | { |
| 8718 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8719 | struct net_device *dev = info->user_ptr[1]; |
| 8720 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 8721 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; |
| 8722 | struct cfg80211_gtk_rekey_data rekey_data; |
| 8723 | int err; |
| 8724 | |
| 8725 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) |
| 8726 | return -EINVAL; |
| 8727 | |
| 8728 | err = nla_parse(tb, MAX_NL80211_REKEY_DATA, |
| 8729 | nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 8730 | nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 8731 | nl80211_rekey_policy); |
| 8732 | if (err) |
| 8733 | return err; |
| 8734 | |
| 8735 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) |
| 8736 | return -ERANGE; |
| 8737 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) |
| 8738 | return -ERANGE; |
| 8739 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) |
| 8740 | return -ERANGE; |
| 8741 | |
| 8742 | memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]), |
| 8743 | NL80211_KEK_LEN); |
| 8744 | memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]), |
| 8745 | NL80211_KCK_LEN); |
| 8746 | memcpy(rekey_data.replay_ctr, |
| 8747 | nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]), |
| 8748 | NL80211_REPLAY_CTR_LEN); |
| 8749 | |
| 8750 | wdev_lock(wdev); |
| 8751 | if (!wdev->current_bss) { |
| 8752 | err = -ENOTCONN; |
| 8753 | goto out; |
| 8754 | } |
| 8755 | |
| 8756 | if (!rdev->ops->set_rekey_data) { |
| 8757 | err = -EOPNOTSUPP; |
| 8758 | goto out; |
| 8759 | } |
| 8760 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8761 | err = rdev_set_rekey_data(rdev, dev, &rekey_data); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 8762 | out: |
| 8763 | wdev_unlock(wdev); |
| 8764 | return err; |
| 8765 | } |
| 8766 | |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8767 | static int nl80211_register_unexpected_frame(struct sk_buff *skb, |
| 8768 | struct genl_info *info) |
| 8769 | { |
| 8770 | struct net_device *dev = info->user_ptr[1]; |
| 8771 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 8772 | |
| 8773 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 8774 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 8775 | return -EINVAL; |
| 8776 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8777 | if (wdev->ap_unexpected_nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8778 | return -EBUSY; |
| 8779 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8780 | wdev->ap_unexpected_nlportid = info->snd_portid; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8781 | return 0; |
| 8782 | } |
| 8783 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8784 | static int nl80211_probe_client(struct sk_buff *skb, |
| 8785 | struct genl_info *info) |
| 8786 | { |
| 8787 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8788 | struct net_device *dev = info->user_ptr[1]; |
| 8789 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 8790 | struct sk_buff *msg; |
| 8791 | void *hdr; |
| 8792 | const u8 *addr; |
| 8793 | u64 cookie; |
| 8794 | int err; |
| 8795 | |
| 8796 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 8797 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 8798 | return -EOPNOTSUPP; |
| 8799 | |
| 8800 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 8801 | return -EINVAL; |
| 8802 | |
| 8803 | if (!rdev->ops->probe_client) |
| 8804 | return -EOPNOTSUPP; |
| 8805 | |
| 8806 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 8807 | if (!msg) |
| 8808 | return -ENOMEM; |
| 8809 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8810 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8811 | NL80211_CMD_PROBE_CLIENT); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 8812 | if (!hdr) { |
| 8813 | err = -ENOBUFS; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8814 | goto free_msg; |
| 8815 | } |
| 8816 | |
| 8817 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 8818 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8819 | err = rdev_probe_client(rdev, dev, addr, &cookie); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8820 | if (err) |
| 8821 | goto free_msg; |
| 8822 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8823 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 8824 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8825 | |
| 8826 | genlmsg_end(msg, hdr); |
| 8827 | |
| 8828 | return genlmsg_reply(msg, info); |
| 8829 | |
| 8830 | nla_put_failure: |
| 8831 | err = -ENOBUFS; |
| 8832 | free_msg: |
| 8833 | nlmsg_free(msg); |
| 8834 | return err; |
| 8835 | } |
| 8836 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8837 | static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) |
| 8838 | { |
| 8839 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 8840 | struct cfg80211_beacon_registration *reg, *nreg; |
| 8841 | int rv; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8842 | |
| 8843 | if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) |
| 8844 | return -EOPNOTSUPP; |
| 8845 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 8846 | nreg = kzalloc(sizeof(*nreg), GFP_KERNEL); |
| 8847 | if (!nreg) |
| 8848 | return -ENOMEM; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8849 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 8850 | /* First, check if already registered. */ |
| 8851 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 8852 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 8853 | if (reg->nlportid == info->snd_portid) { |
| 8854 | rv = -EALREADY; |
| 8855 | goto out_err; |
| 8856 | } |
| 8857 | } |
| 8858 | /* Add it to the list */ |
| 8859 | nreg->nlportid = info->snd_portid; |
| 8860 | list_add(&nreg->list, &rdev->beacon_registrations); |
| 8861 | |
| 8862 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8863 | |
| 8864 | return 0; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 8865 | out_err: |
| 8866 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 8867 | kfree(nreg); |
| 8868 | return rv; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8869 | } |
| 8870 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8871 | static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 8872 | { |
| 8873 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8874 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 8875 | int err; |
| 8876 | |
| 8877 | if (!rdev->ops->start_p2p_device) |
| 8878 | return -EOPNOTSUPP; |
| 8879 | |
| 8880 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 8881 | return -EOPNOTSUPP; |
| 8882 | |
| 8883 | if (wdev->p2p_started) |
| 8884 | return 0; |
| 8885 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8886 | err = cfg80211_can_add_interface(rdev, wdev->iftype); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8887 | if (err) |
| 8888 | return err; |
| 8889 | |
Johannes Berg | eeb126e | 2012-10-23 15:16:50 +0200 | [diff] [blame] | 8890 | err = rdev_start_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8891 | if (err) |
| 8892 | return err; |
| 8893 | |
| 8894 | wdev->p2p_started = true; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8895 | rdev->opencount++; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8896 | |
| 8897 | return 0; |
| 8898 | } |
| 8899 | |
| 8900 | static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 8901 | { |
| 8902 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8903 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 8904 | |
| 8905 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 8906 | return -EOPNOTSUPP; |
| 8907 | |
| 8908 | if (!rdev->ops->stop_p2p_device) |
| 8909 | return -EOPNOTSUPP; |
| 8910 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 8911 | cfg80211_stop_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8912 | |
| 8913 | return 0; |
| 8914 | } |
| 8915 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 8916 | static int nl80211_get_protocol_features(struct sk_buff *skb, |
| 8917 | struct genl_info *info) |
| 8918 | { |
| 8919 | void *hdr; |
| 8920 | struct sk_buff *msg; |
| 8921 | |
| 8922 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 8923 | if (!msg) |
| 8924 | return -ENOMEM; |
| 8925 | |
| 8926 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 8927 | NL80211_CMD_GET_PROTOCOL_FEATURES); |
| 8928 | if (!hdr) |
| 8929 | goto nla_put_failure; |
| 8930 | |
| 8931 | if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES, |
| 8932 | NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)) |
| 8933 | goto nla_put_failure; |
| 8934 | |
| 8935 | genlmsg_end(msg, hdr); |
| 8936 | return genlmsg_reply(msg, info); |
| 8937 | |
| 8938 | nla_put_failure: |
| 8939 | kfree_skb(msg); |
| 8940 | return -ENOBUFS; |
| 8941 | } |
| 8942 | |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 8943 | static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info) |
| 8944 | { |
| 8945 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8946 | struct cfg80211_update_ft_ies_params ft_params; |
| 8947 | struct net_device *dev = info->user_ptr[1]; |
| 8948 | |
| 8949 | if (!rdev->ops->update_ft_ies) |
| 8950 | return -EOPNOTSUPP; |
| 8951 | |
| 8952 | if (!info->attrs[NL80211_ATTR_MDID] || |
| 8953 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 8954 | return -EINVAL; |
| 8955 | |
| 8956 | memset(&ft_params, 0, sizeof(ft_params)); |
| 8957 | ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]); |
| 8958 | ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 8959 | ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 8960 | |
| 8961 | return rdev_update_ft_ies(rdev, dev, &ft_params); |
| 8962 | } |
| 8963 | |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 8964 | static int nl80211_crit_protocol_start(struct sk_buff *skb, |
| 8965 | struct genl_info *info) |
| 8966 | { |
| 8967 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8968 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 8969 | enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC; |
| 8970 | u16 duration; |
| 8971 | int ret; |
| 8972 | |
| 8973 | if (!rdev->ops->crit_proto_start) |
| 8974 | return -EOPNOTSUPP; |
| 8975 | |
| 8976 | if (WARN_ON(!rdev->ops->crit_proto_stop)) |
| 8977 | return -EINVAL; |
| 8978 | |
| 8979 | if (rdev->crit_proto_nlportid) |
| 8980 | return -EBUSY; |
| 8981 | |
| 8982 | /* determine protocol if provided */ |
| 8983 | if (info->attrs[NL80211_ATTR_CRIT_PROT_ID]) |
| 8984 | proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]); |
| 8985 | |
| 8986 | if (proto >= NUM_NL80211_CRIT_PROTO) |
| 8987 | return -EINVAL; |
| 8988 | |
| 8989 | /* timeout must be provided */ |
| 8990 | if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]) |
| 8991 | return -EINVAL; |
| 8992 | |
| 8993 | duration = |
| 8994 | nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]); |
| 8995 | |
| 8996 | if (duration > NL80211_CRIT_PROTO_MAX_DURATION) |
| 8997 | return -ERANGE; |
| 8998 | |
| 8999 | ret = rdev_crit_proto_start(rdev, wdev, proto, duration); |
| 9000 | if (!ret) |
| 9001 | rdev->crit_proto_nlportid = info->snd_portid; |
| 9002 | |
| 9003 | return ret; |
| 9004 | } |
| 9005 | |
| 9006 | static int nl80211_crit_protocol_stop(struct sk_buff *skb, |
| 9007 | struct genl_info *info) |
| 9008 | { |
| 9009 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9010 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 9011 | |
| 9012 | if (!rdev->ops->crit_proto_stop) |
| 9013 | return -EOPNOTSUPP; |
| 9014 | |
| 9015 | if (rdev->crit_proto_nlportid) { |
| 9016 | rdev->crit_proto_nlportid = 0; |
| 9017 | rdev_crit_proto_stop(rdev, wdev); |
| 9018 | } |
| 9019 | return 0; |
| 9020 | } |
| 9021 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 9022 | static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info) |
| 9023 | { |
| 9024 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9025 | struct wireless_dev *wdev = |
| 9026 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); |
| 9027 | int i, err; |
| 9028 | u32 vid, subcmd; |
| 9029 | |
| 9030 | if (!rdev->wiphy.vendor_commands) |
| 9031 | return -EOPNOTSUPP; |
| 9032 | |
| 9033 | if (IS_ERR(wdev)) { |
| 9034 | err = PTR_ERR(wdev); |
| 9035 | if (err != -EINVAL) |
| 9036 | return err; |
| 9037 | wdev = NULL; |
| 9038 | } else if (wdev->wiphy != &rdev->wiphy) { |
| 9039 | return -EINVAL; |
| 9040 | } |
| 9041 | |
| 9042 | if (!info->attrs[NL80211_ATTR_VENDOR_ID] || |
| 9043 | !info->attrs[NL80211_ATTR_VENDOR_SUBCMD]) |
| 9044 | return -EINVAL; |
| 9045 | |
| 9046 | vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]); |
| 9047 | subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]); |
| 9048 | for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { |
| 9049 | const struct wiphy_vendor_command *vcmd; |
| 9050 | void *data = NULL; |
| 9051 | int len = 0; |
| 9052 | |
| 9053 | vcmd = &rdev->wiphy.vendor_commands[i]; |
| 9054 | |
| 9055 | if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd) |
| 9056 | continue; |
| 9057 | |
| 9058 | if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV | |
| 9059 | WIPHY_VENDOR_CMD_NEED_NETDEV)) { |
| 9060 | if (!wdev) |
| 9061 | return -EINVAL; |
| 9062 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV && |
| 9063 | !wdev->netdev) |
| 9064 | return -EINVAL; |
| 9065 | |
| 9066 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) { |
| 9067 | if (wdev->netdev && |
| 9068 | !netif_running(wdev->netdev)) |
| 9069 | return -ENETDOWN; |
| 9070 | if (!wdev->netdev && !wdev->p2p_started) |
| 9071 | return -ENETDOWN; |
| 9072 | } |
| 9073 | } else { |
| 9074 | wdev = NULL; |
| 9075 | } |
| 9076 | |
| 9077 | if (info->attrs[NL80211_ATTR_VENDOR_DATA]) { |
| 9078 | data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]); |
| 9079 | len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]); |
| 9080 | } |
| 9081 | |
| 9082 | rdev->cur_cmd_info = info; |
| 9083 | err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev, |
| 9084 | data, len); |
| 9085 | rdev->cur_cmd_info = NULL; |
| 9086 | return err; |
| 9087 | } |
| 9088 | |
| 9089 | return -EOPNOTSUPP; |
| 9090 | } |
| 9091 | |
| 9092 | struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy, |
| 9093 | enum nl80211_commands cmd, |
| 9094 | enum nl80211_attrs attr, |
| 9095 | int approxlen) |
| 9096 | { |
| 9097 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 9098 | |
| 9099 | if (WARN_ON(!rdev->cur_cmd_info)) |
| 9100 | return NULL; |
| 9101 | |
| 9102 | return __cfg80211_alloc_vendor_skb(rdev, approxlen, |
| 9103 | rdev->cur_cmd_info->snd_portid, |
| 9104 | rdev->cur_cmd_info->snd_seq, |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 9105 | cmd, attr, NULL, GFP_KERNEL); |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 9106 | } |
| 9107 | EXPORT_SYMBOL(__cfg80211_alloc_reply_skb); |
| 9108 | |
| 9109 | int cfg80211_vendor_cmd_reply(struct sk_buff *skb) |
| 9110 | { |
| 9111 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 9112 | void *hdr = ((void **)skb->cb)[1]; |
| 9113 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 9114 | |
| 9115 | if (WARN_ON(!rdev->cur_cmd_info)) { |
| 9116 | kfree_skb(skb); |
| 9117 | return -EINVAL; |
| 9118 | } |
| 9119 | |
| 9120 | nla_nest_end(skb, data); |
| 9121 | genlmsg_end(skb, hdr); |
| 9122 | return genlmsg_reply(skb, rdev->cur_cmd_info); |
| 9123 | } |
| 9124 | EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply); |
| 9125 | |
| 9126 | |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 9127 | static int nl80211_set_qos_map(struct sk_buff *skb, |
| 9128 | struct genl_info *info) |
| 9129 | { |
| 9130 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9131 | struct cfg80211_qos_map *qos_map = NULL; |
| 9132 | struct net_device *dev = info->user_ptr[1]; |
| 9133 | u8 *pos, len, num_des, des_len, des; |
| 9134 | int ret; |
| 9135 | |
| 9136 | if (!rdev->ops->set_qos_map) |
| 9137 | return -EOPNOTSUPP; |
| 9138 | |
| 9139 | if (info->attrs[NL80211_ATTR_QOS_MAP]) { |
| 9140 | pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]); |
| 9141 | len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]); |
| 9142 | |
| 9143 | if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN || |
| 9144 | len > IEEE80211_QOS_MAP_LEN_MAX) |
| 9145 | return -EINVAL; |
| 9146 | |
| 9147 | qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL); |
| 9148 | if (!qos_map) |
| 9149 | return -ENOMEM; |
| 9150 | |
| 9151 | num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1; |
| 9152 | if (num_des) { |
| 9153 | des_len = num_des * |
| 9154 | sizeof(struct cfg80211_dscp_exception); |
| 9155 | memcpy(qos_map->dscp_exception, pos, des_len); |
| 9156 | qos_map->num_des = num_des; |
| 9157 | for (des = 0; des < num_des; des++) { |
| 9158 | if (qos_map->dscp_exception[des].up > 7) { |
| 9159 | kfree(qos_map); |
| 9160 | return -EINVAL; |
| 9161 | } |
| 9162 | } |
| 9163 | pos += des_len; |
| 9164 | } |
| 9165 | memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN); |
| 9166 | } |
| 9167 | |
| 9168 | wdev_lock(dev->ieee80211_ptr); |
| 9169 | ret = nl80211_key_allowed(dev->ieee80211_ptr); |
| 9170 | if (!ret) |
| 9171 | ret = rdev_set_qos_map(rdev, dev, qos_map); |
| 9172 | wdev_unlock(dev->ieee80211_ptr); |
| 9173 | |
| 9174 | kfree(qos_map); |
| 9175 | return ret; |
| 9176 | } |
| 9177 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9178 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
| 9179 | #define NL80211_FLAG_NEED_NETDEV 0x02 |
| 9180 | #define NL80211_FLAG_NEED_RTNL 0x04 |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9181 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
| 9182 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ |
| 9183 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 9184 | #define NL80211_FLAG_NEED_WDEV 0x10 |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9185 | /* 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] | 9186 | #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\ |
| 9187 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9188 | |
Johannes Berg | f84f771 | 2013-11-14 17:14:45 +0100 | [diff] [blame] | 9189 | 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] | 9190 | struct genl_info *info) |
| 9191 | { |
| 9192 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 9193 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9194 | struct net_device *dev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9195 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
| 9196 | |
| 9197 | if (rtnl) |
| 9198 | rtnl_lock(); |
| 9199 | |
| 9200 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 9201 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9202 | if (IS_ERR(rdev)) { |
| 9203 | if (rtnl) |
| 9204 | rtnl_unlock(); |
| 9205 | return PTR_ERR(rdev); |
| 9206 | } |
| 9207 | info->user_ptr[0] = rdev; |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 9208 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV || |
| 9209 | ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 9210 | ASSERT_RTNL(); |
| 9211 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 9212 | wdev = __cfg80211_wdev_from_attrs(genl_info_net(info), |
| 9213 | info->attrs); |
| 9214 | if (IS_ERR(wdev)) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9215 | if (rtnl) |
| 9216 | rtnl_unlock(); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 9217 | return PTR_ERR(wdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9218 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 9219 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 9220 | dev = wdev->netdev; |
| 9221 | rdev = wiphy_to_dev(wdev->wiphy); |
| 9222 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 9223 | if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
| 9224 | if (!dev) { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 9225 | if (rtnl) |
| 9226 | rtnl_unlock(); |
| 9227 | return -EINVAL; |
| 9228 | } |
| 9229 | |
| 9230 | info->user_ptr[1] = dev; |
| 9231 | } else { |
| 9232 | info->user_ptr[1] = wdev; |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9233 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 9234 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 9235 | if (dev) { |
| 9236 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && |
| 9237 | !netif_running(dev)) { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 9238 | if (rtnl) |
| 9239 | rtnl_unlock(); |
| 9240 | return -ENETDOWN; |
| 9241 | } |
| 9242 | |
| 9243 | dev_hold(dev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9244 | } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) { |
| 9245 | if (!wdev->p2p_started) { |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9246 | if (rtnl) |
| 9247 | rtnl_unlock(); |
| 9248 | return -ENETDOWN; |
| 9249 | } |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 9250 | } |
| 9251 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9252 | info->user_ptr[0] = rdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9253 | } |
| 9254 | |
| 9255 | return 0; |
| 9256 | } |
| 9257 | |
Johannes Berg | f84f771 | 2013-11-14 17:14:45 +0100 | [diff] [blame] | 9258 | 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] | 9259 | struct genl_info *info) |
| 9260 | { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 9261 | if (info->user_ptr[1]) { |
| 9262 | if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
| 9263 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 9264 | |
| 9265 | if (wdev->netdev) |
| 9266 | dev_put(wdev->netdev); |
| 9267 | } else { |
| 9268 | dev_put(info->user_ptr[1]); |
| 9269 | } |
| 9270 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9271 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
| 9272 | rtnl_unlock(); |
| 9273 | } |
| 9274 | |
Johannes Berg | 4534de8 | 2013-11-14 17:14:46 +0100 | [diff] [blame] | 9275 | static const struct genl_ops nl80211_ops[] = { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9276 | { |
| 9277 | .cmd = NL80211_CMD_GET_WIPHY, |
| 9278 | .doit = nl80211_get_wiphy, |
| 9279 | .dumpit = nl80211_dump_wiphy, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 9280 | .done = nl80211_dump_wiphy_done, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9281 | .policy = nl80211_policy, |
| 9282 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 9283 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9284 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9285 | }, |
| 9286 | { |
| 9287 | .cmd = NL80211_CMD_SET_WIPHY, |
| 9288 | .doit = nl80211_set_wiphy, |
| 9289 | .policy = nl80211_policy, |
| 9290 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9291 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9292 | }, |
| 9293 | { |
| 9294 | .cmd = NL80211_CMD_GET_INTERFACE, |
| 9295 | .doit = nl80211_get_interface, |
| 9296 | .dumpit = nl80211_dump_interface, |
| 9297 | .policy = nl80211_policy, |
| 9298 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 9299 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 9300 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9301 | }, |
| 9302 | { |
| 9303 | .cmd = NL80211_CMD_SET_INTERFACE, |
| 9304 | .doit = nl80211_set_interface, |
| 9305 | .policy = nl80211_policy, |
| 9306 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9307 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9308 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9309 | }, |
| 9310 | { |
| 9311 | .cmd = NL80211_CMD_NEW_INTERFACE, |
| 9312 | .doit = nl80211_new_interface, |
| 9313 | .policy = nl80211_policy, |
| 9314 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9315 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9316 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9317 | }, |
| 9318 | { |
| 9319 | .cmd = NL80211_CMD_DEL_INTERFACE, |
| 9320 | .doit = nl80211_del_interface, |
| 9321 | .policy = nl80211_policy, |
| 9322 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 9323 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9324 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9325 | }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 9326 | { |
| 9327 | .cmd = NL80211_CMD_GET_KEY, |
| 9328 | .doit = nl80211_get_key, |
| 9329 | .policy = nl80211_policy, |
| 9330 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9331 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9332 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 9333 | }, |
| 9334 | { |
| 9335 | .cmd = NL80211_CMD_SET_KEY, |
| 9336 | .doit = nl80211_set_key, |
| 9337 | .policy = nl80211_policy, |
| 9338 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9339 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9340 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 9341 | }, |
| 9342 | { |
| 9343 | .cmd = NL80211_CMD_NEW_KEY, |
| 9344 | .doit = nl80211_new_key, |
| 9345 | .policy = nl80211_policy, |
| 9346 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9347 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9348 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 9349 | }, |
| 9350 | { |
| 9351 | .cmd = NL80211_CMD_DEL_KEY, |
| 9352 | .doit = nl80211_del_key, |
| 9353 | .policy = nl80211_policy, |
| 9354 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9355 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9356 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 9357 | }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 9358 | { |
| 9359 | .cmd = NL80211_CMD_SET_BEACON, |
| 9360 | .policy = nl80211_policy, |
| 9361 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 9362 | .doit = nl80211_set_beacon, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9363 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9364 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 9365 | }, |
| 9366 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 9367 | .cmd = NL80211_CMD_START_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 9368 | .policy = nl80211_policy, |
| 9369 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 9370 | .doit = nl80211_start_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9371 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9372 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 9373 | }, |
| 9374 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 9375 | .cmd = NL80211_CMD_STOP_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 9376 | .policy = nl80211_policy, |
| 9377 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 9378 | .doit = nl80211_stop_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9379 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9380 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 9381 | }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 9382 | { |
| 9383 | .cmd = NL80211_CMD_GET_STATION, |
| 9384 | .doit = nl80211_get_station, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9385 | .dumpit = nl80211_dump_station, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 9386 | .policy = nl80211_policy, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9387 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9388 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 9389 | }, |
| 9390 | { |
| 9391 | .cmd = NL80211_CMD_SET_STATION, |
| 9392 | .doit = nl80211_set_station, |
| 9393 | .policy = nl80211_policy, |
| 9394 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9395 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9396 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 9397 | }, |
| 9398 | { |
| 9399 | .cmd = NL80211_CMD_NEW_STATION, |
| 9400 | .doit = nl80211_new_station, |
| 9401 | .policy = nl80211_policy, |
| 9402 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9403 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9404 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 9405 | }, |
| 9406 | { |
| 9407 | .cmd = NL80211_CMD_DEL_STATION, |
| 9408 | .doit = nl80211_del_station, |
| 9409 | .policy = nl80211_policy, |
| 9410 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9411 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9412 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 9413 | }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9414 | { |
| 9415 | .cmd = NL80211_CMD_GET_MPATH, |
| 9416 | .doit = nl80211_get_mpath, |
| 9417 | .dumpit = nl80211_dump_mpath, |
| 9418 | .policy = nl80211_policy, |
| 9419 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9420 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9421 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9422 | }, |
| 9423 | { |
| 9424 | .cmd = NL80211_CMD_SET_MPATH, |
| 9425 | .doit = nl80211_set_mpath, |
| 9426 | .policy = nl80211_policy, |
| 9427 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9428 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9429 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9430 | }, |
| 9431 | { |
| 9432 | .cmd = NL80211_CMD_NEW_MPATH, |
| 9433 | .doit = nl80211_new_mpath, |
| 9434 | .policy = nl80211_policy, |
| 9435 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9436 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9437 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9438 | }, |
| 9439 | { |
| 9440 | .cmd = NL80211_CMD_DEL_MPATH, |
| 9441 | .doit = nl80211_del_mpath, |
| 9442 | .policy = nl80211_policy, |
| 9443 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9444 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9445 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9446 | }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 9447 | { |
| 9448 | .cmd = NL80211_CMD_SET_BSS, |
| 9449 | .doit = nl80211_set_bss, |
| 9450 | .policy = nl80211_policy, |
| 9451 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9452 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9453 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 9454 | }, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 9455 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 9456 | .cmd = NL80211_CMD_GET_REG, |
| 9457 | .doit = nl80211_get_reg, |
| 9458 | .policy = nl80211_policy, |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 9459 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 9460 | /* can be retrieved by unprivileged users */ |
| 9461 | }, |
| 9462 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 9463 | .cmd = NL80211_CMD_SET_REG, |
| 9464 | .doit = nl80211_set_reg, |
| 9465 | .policy = nl80211_policy, |
| 9466 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 9467 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 9468 | }, |
| 9469 | { |
| 9470 | .cmd = NL80211_CMD_REQ_SET_REG, |
| 9471 | .doit = nl80211_req_set_reg, |
| 9472 | .policy = nl80211_policy, |
| 9473 | .flags = GENL_ADMIN_PERM, |
| 9474 | }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 9475 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 9476 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
| 9477 | .doit = nl80211_get_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 9478 | .policy = nl80211_policy, |
| 9479 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9480 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9481 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 9482 | }, |
| 9483 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 9484 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
| 9485 | .doit = nl80211_update_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 9486 | .policy = nl80211_policy, |
| 9487 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 9488 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9489 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 9490 | }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 9491 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9492 | .cmd = NL80211_CMD_TRIGGER_SCAN, |
| 9493 | .doit = nl80211_trigger_scan, |
| 9494 | .policy = nl80211_policy, |
| 9495 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9496 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9497 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9498 | }, |
| 9499 | { |
| 9500 | .cmd = NL80211_CMD_GET_SCAN, |
| 9501 | .policy = nl80211_policy, |
| 9502 | .dumpit = nl80211_dump_scan, |
| 9503 | }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9504 | { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9505 | .cmd = NL80211_CMD_START_SCHED_SCAN, |
| 9506 | .doit = nl80211_start_sched_scan, |
| 9507 | .policy = nl80211_policy, |
| 9508 | .flags = GENL_ADMIN_PERM, |
| 9509 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9510 | NL80211_FLAG_NEED_RTNL, |
| 9511 | }, |
| 9512 | { |
| 9513 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, |
| 9514 | .doit = nl80211_stop_sched_scan, |
| 9515 | .policy = nl80211_policy, |
| 9516 | .flags = GENL_ADMIN_PERM, |
| 9517 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9518 | NL80211_FLAG_NEED_RTNL, |
| 9519 | }, |
| 9520 | { |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9521 | .cmd = NL80211_CMD_AUTHENTICATE, |
| 9522 | .doit = nl80211_authenticate, |
| 9523 | .policy = nl80211_policy, |
| 9524 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9525 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9526 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9527 | }, |
| 9528 | { |
| 9529 | .cmd = NL80211_CMD_ASSOCIATE, |
| 9530 | .doit = nl80211_associate, |
| 9531 | .policy = nl80211_policy, |
| 9532 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9533 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9534 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9535 | }, |
| 9536 | { |
| 9537 | .cmd = NL80211_CMD_DEAUTHENTICATE, |
| 9538 | .doit = nl80211_deauthenticate, |
| 9539 | .policy = nl80211_policy, |
| 9540 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9541 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9542 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9543 | }, |
| 9544 | { |
| 9545 | .cmd = NL80211_CMD_DISASSOCIATE, |
| 9546 | .doit = nl80211_disassociate, |
| 9547 | .policy = nl80211_policy, |
| 9548 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9549 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9550 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9551 | }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9552 | { |
| 9553 | .cmd = NL80211_CMD_JOIN_IBSS, |
| 9554 | .doit = nl80211_join_ibss, |
| 9555 | .policy = nl80211_policy, |
| 9556 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9557 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9558 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9559 | }, |
| 9560 | { |
| 9561 | .cmd = NL80211_CMD_LEAVE_IBSS, |
| 9562 | .doit = nl80211_leave_ibss, |
| 9563 | .policy = nl80211_policy, |
| 9564 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9565 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9566 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9567 | }, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 9568 | #ifdef CONFIG_NL80211_TESTMODE |
| 9569 | { |
| 9570 | .cmd = NL80211_CMD_TESTMODE, |
| 9571 | .doit = nl80211_testmode_do, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 9572 | .dumpit = nl80211_testmode_dump, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 9573 | .policy = nl80211_policy, |
| 9574 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9575 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9576 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 9577 | }, |
| 9578 | #endif |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9579 | { |
| 9580 | .cmd = NL80211_CMD_CONNECT, |
| 9581 | .doit = nl80211_connect, |
| 9582 | .policy = nl80211_policy, |
| 9583 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9584 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9585 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9586 | }, |
| 9587 | { |
| 9588 | .cmd = NL80211_CMD_DISCONNECT, |
| 9589 | .doit = nl80211_disconnect, |
| 9590 | .policy = nl80211_policy, |
| 9591 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9592 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9593 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9594 | }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9595 | { |
| 9596 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, |
| 9597 | .doit = nl80211_wiphy_netns, |
| 9598 | .policy = nl80211_policy, |
| 9599 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9600 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9601 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9602 | }, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 9603 | { |
| 9604 | .cmd = NL80211_CMD_GET_SURVEY, |
| 9605 | .policy = nl80211_policy, |
| 9606 | .dumpit = nl80211_dump_survey, |
| 9607 | }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9608 | { |
| 9609 | .cmd = NL80211_CMD_SET_PMKSA, |
| 9610 | .doit = nl80211_setdel_pmksa, |
| 9611 | .policy = nl80211_policy, |
| 9612 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9613 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9614 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9615 | }, |
| 9616 | { |
| 9617 | .cmd = NL80211_CMD_DEL_PMKSA, |
| 9618 | .doit = nl80211_setdel_pmksa, |
| 9619 | .policy = nl80211_policy, |
| 9620 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9621 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9622 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9623 | }, |
| 9624 | { |
| 9625 | .cmd = NL80211_CMD_FLUSH_PMKSA, |
| 9626 | .doit = nl80211_flush_pmksa, |
| 9627 | .policy = nl80211_policy, |
| 9628 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9629 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9630 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9631 | }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9632 | { |
| 9633 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, |
| 9634 | .doit = nl80211_remain_on_channel, |
| 9635 | .policy = nl80211_policy, |
| 9636 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9637 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9638 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9639 | }, |
| 9640 | { |
| 9641 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
| 9642 | .doit = nl80211_cancel_remain_on_channel, |
| 9643 | .policy = nl80211_policy, |
| 9644 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9645 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9646 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9647 | }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 9648 | { |
| 9649 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, |
| 9650 | .doit = nl80211_set_tx_bitrate_mask, |
| 9651 | .policy = nl80211_policy, |
| 9652 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9653 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9654 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 9655 | }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9656 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9657 | .cmd = NL80211_CMD_REGISTER_FRAME, |
| 9658 | .doit = nl80211_register_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9659 | .policy = nl80211_policy, |
| 9660 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9661 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9662 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9663 | }, |
| 9664 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9665 | .cmd = NL80211_CMD_FRAME, |
| 9666 | .doit = nl80211_tx_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9667 | .policy = nl80211_policy, |
| 9668 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9669 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9670 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9671 | }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9672 | { |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 9673 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, |
| 9674 | .doit = nl80211_tx_mgmt_cancel_wait, |
| 9675 | .policy = nl80211_policy, |
| 9676 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9677 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 9678 | NL80211_FLAG_NEED_RTNL, |
| 9679 | }, |
| 9680 | { |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9681 | .cmd = NL80211_CMD_SET_POWER_SAVE, |
| 9682 | .doit = nl80211_set_power_save, |
| 9683 | .policy = nl80211_policy, |
| 9684 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9685 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9686 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9687 | }, |
| 9688 | { |
| 9689 | .cmd = NL80211_CMD_GET_POWER_SAVE, |
| 9690 | .doit = nl80211_get_power_save, |
| 9691 | .policy = nl80211_policy, |
| 9692 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9693 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9694 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9695 | }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9696 | { |
| 9697 | .cmd = NL80211_CMD_SET_CQM, |
| 9698 | .doit = nl80211_set_cqm, |
| 9699 | .policy = nl80211_policy, |
| 9700 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9701 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9702 | NL80211_FLAG_NEED_RTNL, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9703 | }, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 9704 | { |
| 9705 | .cmd = NL80211_CMD_SET_CHANNEL, |
| 9706 | .doit = nl80211_set_channel, |
| 9707 | .policy = nl80211_policy, |
| 9708 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9709 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9710 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 9711 | }, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 9712 | { |
| 9713 | .cmd = NL80211_CMD_SET_WDS_PEER, |
| 9714 | .doit = nl80211_set_wds_peer, |
| 9715 | .policy = nl80211_policy, |
| 9716 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 9717 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9718 | NL80211_FLAG_NEED_RTNL, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 9719 | }, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 9720 | { |
| 9721 | .cmd = NL80211_CMD_JOIN_MESH, |
| 9722 | .doit = nl80211_join_mesh, |
| 9723 | .policy = nl80211_policy, |
| 9724 | .flags = GENL_ADMIN_PERM, |
| 9725 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9726 | NL80211_FLAG_NEED_RTNL, |
| 9727 | }, |
| 9728 | { |
| 9729 | .cmd = NL80211_CMD_LEAVE_MESH, |
| 9730 | .doit = nl80211_leave_mesh, |
| 9731 | .policy = nl80211_policy, |
| 9732 | .flags = GENL_ADMIN_PERM, |
| 9733 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9734 | NL80211_FLAG_NEED_RTNL, |
| 9735 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 9736 | #ifdef CONFIG_PM |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9737 | { |
| 9738 | .cmd = NL80211_CMD_GET_WOWLAN, |
| 9739 | .doit = nl80211_get_wowlan, |
| 9740 | .policy = nl80211_policy, |
| 9741 | /* can be retrieved by unprivileged users */ |
| 9742 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9743 | NL80211_FLAG_NEED_RTNL, |
| 9744 | }, |
| 9745 | { |
| 9746 | .cmd = NL80211_CMD_SET_WOWLAN, |
| 9747 | .doit = nl80211_set_wowlan, |
| 9748 | .policy = nl80211_policy, |
| 9749 | .flags = GENL_ADMIN_PERM, |
| 9750 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9751 | NL80211_FLAG_NEED_RTNL, |
| 9752 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 9753 | #endif |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 9754 | { |
| 9755 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, |
| 9756 | .doit = nl80211_set_rekey_data, |
| 9757 | .policy = nl80211_policy, |
| 9758 | .flags = GENL_ADMIN_PERM, |
| 9759 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9760 | NL80211_FLAG_NEED_RTNL, |
| 9761 | }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 9762 | { |
| 9763 | .cmd = NL80211_CMD_TDLS_MGMT, |
| 9764 | .doit = nl80211_tdls_mgmt, |
| 9765 | .policy = nl80211_policy, |
| 9766 | .flags = GENL_ADMIN_PERM, |
| 9767 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9768 | NL80211_FLAG_NEED_RTNL, |
| 9769 | }, |
| 9770 | { |
| 9771 | .cmd = NL80211_CMD_TDLS_OPER, |
| 9772 | .doit = nl80211_tdls_oper, |
| 9773 | .policy = nl80211_policy, |
| 9774 | .flags = GENL_ADMIN_PERM, |
| 9775 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9776 | NL80211_FLAG_NEED_RTNL, |
| 9777 | }, |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9778 | { |
| 9779 | .cmd = NL80211_CMD_UNEXPECTED_FRAME, |
| 9780 | .doit = nl80211_register_unexpected_frame, |
| 9781 | .policy = nl80211_policy, |
| 9782 | .flags = GENL_ADMIN_PERM, |
| 9783 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9784 | NL80211_FLAG_NEED_RTNL, |
| 9785 | }, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9786 | { |
| 9787 | .cmd = NL80211_CMD_PROBE_CLIENT, |
| 9788 | .doit = nl80211_probe_client, |
| 9789 | .policy = nl80211_policy, |
| 9790 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9791 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9792 | NL80211_FLAG_NEED_RTNL, |
| 9793 | }, |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9794 | { |
| 9795 | .cmd = NL80211_CMD_REGISTER_BEACONS, |
| 9796 | .doit = nl80211_register_beacons, |
| 9797 | .policy = nl80211_policy, |
| 9798 | .flags = GENL_ADMIN_PERM, |
| 9799 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9800 | NL80211_FLAG_NEED_RTNL, |
| 9801 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 9802 | { |
| 9803 | .cmd = NL80211_CMD_SET_NOACK_MAP, |
| 9804 | .doit = nl80211_set_noack_map, |
| 9805 | .policy = nl80211_policy, |
| 9806 | .flags = GENL_ADMIN_PERM, |
| 9807 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9808 | NL80211_FLAG_NEED_RTNL, |
| 9809 | }, |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9810 | { |
| 9811 | .cmd = NL80211_CMD_START_P2P_DEVICE, |
| 9812 | .doit = nl80211_start_p2p_device, |
| 9813 | .policy = nl80211_policy, |
| 9814 | .flags = GENL_ADMIN_PERM, |
| 9815 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 9816 | NL80211_FLAG_NEED_RTNL, |
| 9817 | }, |
| 9818 | { |
| 9819 | .cmd = NL80211_CMD_STOP_P2P_DEVICE, |
| 9820 | .doit = nl80211_stop_p2p_device, |
| 9821 | .policy = nl80211_policy, |
| 9822 | .flags = GENL_ADMIN_PERM, |
| 9823 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 9824 | NL80211_FLAG_NEED_RTNL, |
| 9825 | }, |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 9826 | { |
| 9827 | .cmd = NL80211_CMD_SET_MCAST_RATE, |
| 9828 | .doit = nl80211_set_mcast_rate, |
| 9829 | .policy = nl80211_policy, |
| 9830 | .flags = GENL_ADMIN_PERM, |
| 9831 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9832 | NL80211_FLAG_NEED_RTNL, |
| 9833 | }, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 9834 | { |
| 9835 | .cmd = NL80211_CMD_SET_MAC_ACL, |
| 9836 | .doit = nl80211_set_mac_acl, |
| 9837 | .policy = nl80211_policy, |
| 9838 | .flags = GENL_ADMIN_PERM, |
| 9839 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9840 | NL80211_FLAG_NEED_RTNL, |
| 9841 | }, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 9842 | { |
| 9843 | .cmd = NL80211_CMD_RADAR_DETECT, |
| 9844 | .doit = nl80211_start_radar_detection, |
| 9845 | .policy = nl80211_policy, |
| 9846 | .flags = GENL_ADMIN_PERM, |
| 9847 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9848 | NL80211_FLAG_NEED_RTNL, |
| 9849 | }, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 9850 | { |
| 9851 | .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES, |
| 9852 | .doit = nl80211_get_protocol_features, |
| 9853 | .policy = nl80211_policy, |
| 9854 | }, |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 9855 | { |
| 9856 | .cmd = NL80211_CMD_UPDATE_FT_IES, |
| 9857 | .doit = nl80211_update_ft_ies, |
| 9858 | .policy = nl80211_policy, |
| 9859 | .flags = GENL_ADMIN_PERM, |
| 9860 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9861 | NL80211_FLAG_NEED_RTNL, |
| 9862 | }, |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 9863 | { |
| 9864 | .cmd = NL80211_CMD_CRIT_PROTOCOL_START, |
| 9865 | .doit = nl80211_crit_protocol_start, |
| 9866 | .policy = nl80211_policy, |
| 9867 | .flags = GENL_ADMIN_PERM, |
| 9868 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 9869 | NL80211_FLAG_NEED_RTNL, |
| 9870 | }, |
| 9871 | { |
| 9872 | .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP, |
| 9873 | .doit = nl80211_crit_protocol_stop, |
| 9874 | .policy = nl80211_policy, |
| 9875 | .flags = GENL_ADMIN_PERM, |
| 9876 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 9877 | NL80211_FLAG_NEED_RTNL, |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 9878 | }, |
| 9879 | { |
| 9880 | .cmd = NL80211_CMD_GET_COALESCE, |
| 9881 | .doit = nl80211_get_coalesce, |
| 9882 | .policy = nl80211_policy, |
| 9883 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9884 | NL80211_FLAG_NEED_RTNL, |
| 9885 | }, |
| 9886 | { |
| 9887 | .cmd = NL80211_CMD_SET_COALESCE, |
| 9888 | .doit = nl80211_set_coalesce, |
| 9889 | .policy = nl80211_policy, |
| 9890 | .flags = GENL_ADMIN_PERM, |
| 9891 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9892 | NL80211_FLAG_NEED_RTNL, |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 9893 | }, |
| 9894 | { |
| 9895 | .cmd = NL80211_CMD_CHANNEL_SWITCH, |
| 9896 | .doit = nl80211_channel_switch, |
| 9897 | .policy = nl80211_policy, |
| 9898 | .flags = GENL_ADMIN_PERM, |
| 9899 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9900 | NL80211_FLAG_NEED_RTNL, |
| 9901 | }, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 9902 | { |
| 9903 | .cmd = NL80211_CMD_VENDOR, |
| 9904 | .doit = nl80211_vendor_cmd, |
| 9905 | .policy = nl80211_policy, |
| 9906 | .flags = GENL_ADMIN_PERM, |
| 9907 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9908 | NL80211_FLAG_NEED_RTNL, |
| 9909 | }, |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 9910 | { |
| 9911 | .cmd = NL80211_CMD_SET_QOS_MAP, |
| 9912 | .doit = nl80211_set_qos_map, |
| 9913 | .policy = nl80211_policy, |
| 9914 | .flags = GENL_ADMIN_PERM, |
| 9915 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9916 | NL80211_FLAG_NEED_RTNL, |
| 9917 | }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9918 | }; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9919 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9920 | /* notification functions */ |
| 9921 | |
| 9922 | void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev) |
| 9923 | { |
| 9924 | struct sk_buff *msg; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 9925 | struct nl80211_dump_wiphy_state state = {}; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9926 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 9927 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9928 | if (!msg) |
| 9929 | return; |
| 9930 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 9931 | if (nl80211_send_wiphy(rdev, msg, 0, 0, 0, &state) < 0) { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9932 | nlmsg_free(msg); |
| 9933 | return; |
| 9934 | } |
| 9935 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 9936 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 9937 | NL80211_MCGRP_CONFIG, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9938 | } |
| 9939 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 9940 | static int nl80211_add_scan_req(struct sk_buff *msg, |
| 9941 | struct cfg80211_registered_device *rdev) |
| 9942 | { |
| 9943 | struct cfg80211_scan_request *req = rdev->scan_req; |
| 9944 | struct nlattr *nest; |
| 9945 | int i; |
| 9946 | |
| 9947 | if (WARN_ON(!req)) |
| 9948 | return 0; |
| 9949 | |
| 9950 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); |
| 9951 | if (!nest) |
| 9952 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9953 | for (i = 0; i < req->n_ssids; i++) { |
| 9954 | if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) |
| 9955 | goto nla_put_failure; |
| 9956 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 9957 | nla_nest_end(msg, nest); |
| 9958 | |
| 9959 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 9960 | if (!nest) |
| 9961 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9962 | for (i = 0; i < req->n_channels; i++) { |
| 9963 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) |
| 9964 | goto nla_put_failure; |
| 9965 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 9966 | nla_nest_end(msg, nest); |
| 9967 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9968 | if (req->ie && |
| 9969 | nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie)) |
| 9970 | goto nla_put_failure; |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 9971 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 9972 | if (req->flags && |
| 9973 | nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags)) |
| 9974 | goto nla_put_failure; |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 9975 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 9976 | return 0; |
| 9977 | nla_put_failure: |
| 9978 | return -ENOBUFS; |
| 9979 | } |
| 9980 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9981 | static int nl80211_send_scan_msg(struct sk_buff *msg, |
| 9982 | struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9983 | struct wireless_dev *wdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9984 | u32 portid, u32 seq, int flags, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9985 | u32 cmd) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9986 | { |
| 9987 | void *hdr; |
| 9988 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9989 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9990 | if (!hdr) |
| 9991 | return -1; |
| 9992 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9993 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9994 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 9995 | wdev->netdev->ifindex)) || |
| 9996 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9997 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9998 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 9999 | /* ignore errors and send incomplete event anyway */ |
| 10000 | nl80211_add_scan_req(msg, rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10001 | |
| 10002 | return genlmsg_end(msg, hdr); |
| 10003 | |
| 10004 | nla_put_failure: |
| 10005 | genlmsg_cancel(msg, hdr); |
| 10006 | return -EMSGSIZE; |
| 10007 | } |
| 10008 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 10009 | static int |
| 10010 | nl80211_send_sched_scan_msg(struct sk_buff *msg, |
| 10011 | struct cfg80211_registered_device *rdev, |
| 10012 | struct net_device *netdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10013 | u32 portid, u32 seq, int flags, u32 cmd) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 10014 | { |
| 10015 | void *hdr; |
| 10016 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10017 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 10018 | if (!hdr) |
| 10019 | return -1; |
| 10020 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10021 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10022 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 10023 | goto nla_put_failure; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 10024 | |
| 10025 | return genlmsg_end(msg, hdr); |
| 10026 | |
| 10027 | nla_put_failure: |
| 10028 | genlmsg_cancel(msg, hdr); |
| 10029 | return -EMSGSIZE; |
| 10030 | } |
| 10031 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 10032 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 10033 | struct wireless_dev *wdev) |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 10034 | { |
| 10035 | struct sk_buff *msg; |
| 10036 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10037 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 10038 | if (!msg) |
| 10039 | return; |
| 10040 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 10041 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 10042 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
| 10043 | nlmsg_free(msg); |
| 10044 | return; |
| 10045 | } |
| 10046 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10047 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10048 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 10049 | } |
| 10050 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10051 | void nl80211_send_scan_done(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 10052 | struct wireless_dev *wdev) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10053 | { |
| 10054 | struct sk_buff *msg; |
| 10055 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 10056 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10057 | if (!msg) |
| 10058 | return; |
| 10059 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 10060 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 10061 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10062 | nlmsg_free(msg); |
| 10063 | return; |
| 10064 | } |
| 10065 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10066 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10067 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10068 | } |
| 10069 | |
| 10070 | void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 10071 | struct wireless_dev *wdev) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10072 | { |
| 10073 | struct sk_buff *msg; |
| 10074 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 10075 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10076 | if (!msg) |
| 10077 | return; |
| 10078 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 10079 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 10080 | NL80211_CMD_SCAN_ABORTED) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10081 | nlmsg_free(msg); |
| 10082 | return; |
| 10083 | } |
| 10084 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10085 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10086 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10087 | } |
| 10088 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 10089 | void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev, |
| 10090 | struct net_device *netdev) |
| 10091 | { |
| 10092 | struct sk_buff *msg; |
| 10093 | |
| 10094 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 10095 | if (!msg) |
| 10096 | return; |
| 10097 | |
| 10098 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 10099 | NL80211_CMD_SCHED_SCAN_RESULTS) < 0) { |
| 10100 | nlmsg_free(msg); |
| 10101 | return; |
| 10102 | } |
| 10103 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10104 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10105 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 10106 | } |
| 10107 | |
| 10108 | void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev, |
| 10109 | struct net_device *netdev, u32 cmd) |
| 10110 | { |
| 10111 | struct sk_buff *msg; |
| 10112 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10113 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 10114 | if (!msg) |
| 10115 | return; |
| 10116 | |
| 10117 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) { |
| 10118 | nlmsg_free(msg); |
| 10119 | return; |
| 10120 | } |
| 10121 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10122 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10123 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 10124 | } |
| 10125 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 10126 | /* |
| 10127 | * This can happen on global regulatory changes or device specific settings |
| 10128 | * based on custom world regulatory domains. |
| 10129 | */ |
| 10130 | void nl80211_send_reg_change_event(struct regulatory_request *request) |
| 10131 | { |
| 10132 | struct sk_buff *msg; |
| 10133 | void *hdr; |
| 10134 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 10135 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 10136 | if (!msg) |
| 10137 | return; |
| 10138 | |
| 10139 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE); |
| 10140 | if (!hdr) { |
| 10141 | nlmsg_free(msg); |
| 10142 | return; |
| 10143 | } |
| 10144 | |
| 10145 | /* Userspace can always count this one always being set */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10146 | if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator)) |
| 10147 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 10148 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10149 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') { |
| 10150 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 10151 | NL80211_REGDOM_TYPE_WORLD)) |
| 10152 | goto nla_put_failure; |
| 10153 | } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') { |
| 10154 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 10155 | NL80211_REGDOM_TYPE_CUSTOM_WORLD)) |
| 10156 | goto nla_put_failure; |
| 10157 | } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || |
| 10158 | request->intersect) { |
| 10159 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 10160 | NL80211_REGDOM_TYPE_INTERSECTION)) |
| 10161 | goto nla_put_failure; |
| 10162 | } else { |
| 10163 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 10164 | NL80211_REGDOM_TYPE_COUNTRY) || |
| 10165 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, |
| 10166 | request->alpha2)) |
| 10167 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 10168 | } |
| 10169 | |
Johannes Berg | f417376 | 2012-12-03 18:23:37 +0100 | [diff] [blame] | 10170 | if (request->wiphy_idx != WIPHY_IDX_INVALID && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10171 | nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) |
| 10172 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 10173 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10174 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 10175 | |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 10176 | rcu_read_lock(); |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10177 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10178 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 10179 | rcu_read_unlock(); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 10180 | |
| 10181 | return; |
| 10182 | |
| 10183 | nla_put_failure: |
| 10184 | genlmsg_cancel(msg, hdr); |
| 10185 | nlmsg_free(msg); |
| 10186 | } |
| 10187 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10188 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
| 10189 | struct net_device *netdev, |
| 10190 | const u8 *buf, size_t len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10191 | enum nl80211_commands cmd, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10192 | { |
| 10193 | struct sk_buff *msg; |
| 10194 | void *hdr; |
| 10195 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10196 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10197 | if (!msg) |
| 10198 | return; |
| 10199 | |
| 10200 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 10201 | if (!hdr) { |
| 10202 | nlmsg_free(msg); |
| 10203 | return; |
| 10204 | } |
| 10205 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10206 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10207 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10208 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) |
| 10209 | goto nla_put_failure; |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10210 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10211 | genlmsg_end(msg, hdr); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10212 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10213 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10214 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10215 | return; |
| 10216 | |
| 10217 | nla_put_failure: |
| 10218 | genlmsg_cancel(msg, hdr); |
| 10219 | nlmsg_free(msg); |
| 10220 | } |
| 10221 | |
| 10222 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10223 | struct net_device *netdev, const u8 *buf, |
| 10224 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10225 | { |
| 10226 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10227 | NL80211_CMD_AUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10228 | } |
| 10229 | |
| 10230 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, |
| 10231 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10232 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10233 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10234 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 10235 | NL80211_CMD_ASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10236 | } |
| 10237 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 10238 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10239 | struct net_device *netdev, const u8 *buf, |
| 10240 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10241 | { |
| 10242 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10243 | NL80211_CMD_DEAUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10244 | } |
| 10245 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 10246 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
| 10247 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10248 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10249 | { |
| 10250 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10251 | NL80211_CMD_DISASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10252 | } |
| 10253 | |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 10254 | void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf, |
| 10255 | size_t len) |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 10256 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10257 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10258 | struct wiphy *wiphy = wdev->wiphy; |
| 10259 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 10260 | const struct ieee80211_mgmt *mgmt = (void *)buf; |
| 10261 | u32 cmd; |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 10262 | |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 10263 | if (WARN_ON(len < 2)) |
| 10264 | return; |
| 10265 | |
| 10266 | if (ieee80211_is_deauth(mgmt->frame_control)) |
| 10267 | cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE; |
| 10268 | else |
| 10269 | cmd = NL80211_CMD_UNPROT_DISASSOCIATE; |
| 10270 | |
| 10271 | trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len); |
| 10272 | nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC); |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 10273 | } |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 10274 | EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt); |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 10275 | |
Luis R. Rodriguez | 1b06bb4 | 2009-05-02 00:34:48 -0400 | [diff] [blame] | 10276 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
| 10277 | struct net_device *netdev, int cmd, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10278 | const u8 *addr, gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10279 | { |
| 10280 | struct sk_buff *msg; |
| 10281 | void *hdr; |
| 10282 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10283 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10284 | if (!msg) |
| 10285 | return; |
| 10286 | |
| 10287 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 10288 | if (!hdr) { |
| 10289 | nlmsg_free(msg); |
| 10290 | return; |
| 10291 | } |
| 10292 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10293 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10294 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10295 | nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || |
| 10296 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 10297 | goto nla_put_failure; |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10298 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10299 | genlmsg_end(msg, hdr); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10300 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10301 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10302 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10303 | return; |
| 10304 | |
| 10305 | nla_put_failure: |
| 10306 | genlmsg_cancel(msg, hdr); |
| 10307 | nlmsg_free(msg); |
| 10308 | } |
| 10309 | |
| 10310 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10311 | struct net_device *netdev, const u8 *addr, |
| 10312 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10313 | { |
| 10314 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10315 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10316 | } |
| 10317 | |
| 10318 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10319 | struct net_device *netdev, const u8 *addr, |
| 10320 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10321 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10322 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
| 10323 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10324 | } |
| 10325 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10326 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
| 10327 | struct net_device *netdev, const u8 *bssid, |
| 10328 | const u8 *req_ie, size_t req_ie_len, |
| 10329 | const u8 *resp_ie, size_t resp_ie_len, |
| 10330 | u16 status, gfp_t gfp) |
| 10331 | { |
| 10332 | struct sk_buff *msg; |
| 10333 | void *hdr; |
| 10334 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10335 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10336 | if (!msg) |
| 10337 | return; |
| 10338 | |
| 10339 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); |
| 10340 | if (!hdr) { |
| 10341 | nlmsg_free(msg); |
| 10342 | return; |
| 10343 | } |
| 10344 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10345 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10346 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10347 | (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) || |
| 10348 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) || |
| 10349 | (req_ie && |
| 10350 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 10351 | (resp_ie && |
| 10352 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 10353 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10354 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10355 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10356 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10357 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10358 | NL80211_MCGRP_MLME, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10359 | return; |
| 10360 | |
| 10361 | nla_put_failure: |
| 10362 | genlmsg_cancel(msg, hdr); |
| 10363 | nlmsg_free(msg); |
| 10364 | |
| 10365 | } |
| 10366 | |
| 10367 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, |
| 10368 | struct net_device *netdev, const u8 *bssid, |
| 10369 | const u8 *req_ie, size_t req_ie_len, |
| 10370 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) |
| 10371 | { |
| 10372 | struct sk_buff *msg; |
| 10373 | void *hdr; |
| 10374 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10375 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10376 | if (!msg) |
| 10377 | return; |
| 10378 | |
| 10379 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); |
| 10380 | if (!hdr) { |
| 10381 | nlmsg_free(msg); |
| 10382 | return; |
| 10383 | } |
| 10384 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10385 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10386 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10387 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) || |
| 10388 | (req_ie && |
| 10389 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 10390 | (resp_ie && |
| 10391 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 10392 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10393 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10394 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10395 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10396 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10397 | NL80211_MCGRP_MLME, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10398 | return; |
| 10399 | |
| 10400 | nla_put_failure: |
| 10401 | genlmsg_cancel(msg, hdr); |
| 10402 | nlmsg_free(msg); |
| 10403 | |
| 10404 | } |
| 10405 | |
| 10406 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, |
| 10407 | struct net_device *netdev, u16 reason, |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 10408 | const u8 *ie, size_t ie_len, bool from_ap) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10409 | { |
| 10410 | struct sk_buff *msg; |
| 10411 | void *hdr; |
| 10412 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10413 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10414 | if (!msg) |
| 10415 | return; |
| 10416 | |
| 10417 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); |
| 10418 | if (!hdr) { |
| 10419 | nlmsg_free(msg); |
| 10420 | return; |
| 10421 | } |
| 10422 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10423 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10424 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10425 | (from_ap && reason && |
| 10426 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) || |
| 10427 | (from_ap && |
| 10428 | nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) || |
| 10429 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) |
| 10430 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10431 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10432 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10433 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10434 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10435 | NL80211_MCGRP_MLME, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10436 | return; |
| 10437 | |
| 10438 | nla_put_failure: |
| 10439 | genlmsg_cancel(msg, hdr); |
| 10440 | nlmsg_free(msg); |
| 10441 | |
| 10442 | } |
| 10443 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10444 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
| 10445 | struct net_device *netdev, const u8 *bssid, |
| 10446 | gfp_t gfp) |
| 10447 | { |
| 10448 | struct sk_buff *msg; |
| 10449 | void *hdr; |
| 10450 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 10451 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10452 | if (!msg) |
| 10453 | return; |
| 10454 | |
| 10455 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); |
| 10456 | if (!hdr) { |
| 10457 | nlmsg_free(msg); |
| 10458 | return; |
| 10459 | } |
| 10460 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10461 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10462 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10463 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 10464 | goto nla_put_failure; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10465 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10466 | genlmsg_end(msg, hdr); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10467 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10468 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10469 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10470 | return; |
| 10471 | |
| 10472 | nla_put_failure: |
| 10473 | genlmsg_cancel(msg, hdr); |
| 10474 | nlmsg_free(msg); |
| 10475 | } |
| 10476 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10477 | void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr, |
| 10478 | const u8* ie, u8 ie_len, gfp_t gfp) |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10479 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10480 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10481 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10482 | struct sk_buff *msg; |
| 10483 | void *hdr; |
| 10484 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10485 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT)) |
| 10486 | return; |
| 10487 | |
| 10488 | trace_cfg80211_notify_new_peer_candidate(dev, addr); |
| 10489 | |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10490 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 10491 | if (!msg) |
| 10492 | return; |
| 10493 | |
| 10494 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); |
| 10495 | if (!hdr) { |
| 10496 | nlmsg_free(msg); |
| 10497 | return; |
| 10498 | } |
| 10499 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10500 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10501 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 10502 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10503 | (ie_len && ie && |
| 10504 | nla_put(msg, NL80211_ATTR_IE, ie_len , ie))) |
| 10505 | goto nla_put_failure; |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10506 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10507 | genlmsg_end(msg, hdr); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10508 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10509 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10510 | NL80211_MCGRP_MLME, gfp); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10511 | return; |
| 10512 | |
| 10513 | nla_put_failure: |
| 10514 | genlmsg_cancel(msg, hdr); |
| 10515 | nlmsg_free(msg); |
| 10516 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10517 | EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10518 | |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 10519 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
| 10520 | struct net_device *netdev, const u8 *addr, |
| 10521 | enum nl80211_key_type key_type, int key_id, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10522 | const u8 *tsc, gfp_t gfp) |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 10523 | { |
| 10524 | struct sk_buff *msg; |
| 10525 | void *hdr; |
| 10526 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10527 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 10528 | if (!msg) |
| 10529 | return; |
| 10530 | |
| 10531 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); |
| 10532 | if (!hdr) { |
| 10533 | nlmsg_free(msg); |
| 10534 | return; |
| 10535 | } |
| 10536 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10537 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10538 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10539 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
| 10540 | nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) || |
| 10541 | (key_id != -1 && |
| 10542 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) || |
| 10543 | (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc))) |
| 10544 | goto nla_put_failure; |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 10545 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10546 | genlmsg_end(msg, hdr); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 10547 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10548 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10549 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 10550 | return; |
| 10551 | |
| 10552 | nla_put_failure: |
| 10553 | genlmsg_cancel(msg, hdr); |
| 10554 | nlmsg_free(msg); |
| 10555 | } |
| 10556 | |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10557 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
| 10558 | struct ieee80211_channel *channel_before, |
| 10559 | struct ieee80211_channel *channel_after) |
| 10560 | { |
| 10561 | struct sk_buff *msg; |
| 10562 | void *hdr; |
| 10563 | struct nlattr *nl_freq; |
| 10564 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 10565 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10566 | if (!msg) |
| 10567 | return; |
| 10568 | |
| 10569 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); |
| 10570 | if (!hdr) { |
| 10571 | nlmsg_free(msg); |
| 10572 | return; |
| 10573 | } |
| 10574 | |
| 10575 | /* |
| 10576 | * Since we are applying the beacon hint to a wiphy we know its |
| 10577 | * wiphy_idx is valid |
| 10578 | */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10579 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 10580 | goto nla_put_failure; |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10581 | |
| 10582 | /* Before */ |
| 10583 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); |
| 10584 | if (!nl_freq) |
| 10585 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 10586 | if (nl80211_msg_put_channel(msg, channel_before, false)) |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10587 | goto nla_put_failure; |
| 10588 | nla_nest_end(msg, nl_freq); |
| 10589 | |
| 10590 | /* After */ |
| 10591 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); |
| 10592 | if (!nl_freq) |
| 10593 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 10594 | if (nl80211_msg_put_channel(msg, channel_after, false)) |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10595 | goto nla_put_failure; |
| 10596 | nla_nest_end(msg, nl_freq); |
| 10597 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10598 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10599 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 10600 | rcu_read_lock(); |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10601 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10602 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 10603 | rcu_read_unlock(); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10604 | |
| 10605 | return; |
| 10606 | |
| 10607 | nla_put_failure: |
| 10608 | genlmsg_cancel(msg, hdr); |
| 10609 | nlmsg_free(msg); |
| 10610 | } |
| 10611 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10612 | static void nl80211_send_remain_on_chan_event( |
| 10613 | int cmd, struct cfg80211_registered_device *rdev, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10614 | struct wireless_dev *wdev, u64 cookie, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10615 | struct ieee80211_channel *chan, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10616 | unsigned int duration, gfp_t gfp) |
| 10617 | { |
| 10618 | struct sk_buff *msg; |
| 10619 | void *hdr; |
| 10620 | |
| 10621 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 10622 | if (!msg) |
| 10623 | return; |
| 10624 | |
| 10625 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 10626 | if (!hdr) { |
| 10627 | nlmsg_free(msg); |
| 10628 | return; |
| 10629 | } |
| 10630 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10631 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10632 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 10633 | wdev->netdev->ifindex)) || |
Johannes Berg | 00f5335 | 2012-07-17 11:53:12 +0200 | [diff] [blame] | 10634 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10635 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) || |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 10636 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 10637 | NL80211_CHAN_NO_HT) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10638 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 10639 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10640 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10641 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL && |
| 10642 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) |
| 10643 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10644 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10645 | genlmsg_end(msg, hdr); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10646 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10647 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10648 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10649 | return; |
| 10650 | |
| 10651 | nla_put_failure: |
| 10652 | genlmsg_cancel(msg, hdr); |
| 10653 | nlmsg_free(msg); |
| 10654 | } |
| 10655 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10656 | void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie, |
| 10657 | struct ieee80211_channel *chan, |
| 10658 | unsigned int duration, gfp_t gfp) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10659 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10660 | struct wiphy *wiphy = wdev->wiphy; |
| 10661 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 10662 | |
| 10663 | trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10664 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10665 | rdev, wdev, cookie, chan, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 10666 | duration, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10667 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10668 | EXPORT_SYMBOL(cfg80211_ready_on_channel); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10669 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10670 | void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie, |
| 10671 | struct ieee80211_channel *chan, |
| 10672 | gfp_t gfp) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10673 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10674 | struct wiphy *wiphy = wdev->wiphy; |
| 10675 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 10676 | |
| 10677 | trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10678 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 10679 | rdev, wdev, cookie, chan, 0, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10680 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10681 | EXPORT_SYMBOL(cfg80211_remain_on_channel_expired); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10682 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10683 | void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr, |
| 10684 | struct station_info *sinfo, gfp_t gfp) |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 10685 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10686 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
| 10687 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 10688 | struct sk_buff *msg; |
| 10689 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10690 | trace_cfg80211_new_sta(dev, mac_addr, sinfo); |
| 10691 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10692 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 10693 | if (!msg) |
| 10694 | return; |
| 10695 | |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 10696 | if (nl80211_send_station(msg, 0, 0, 0, |
| 10697 | rdev, dev, mac_addr, sinfo) < 0) { |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 10698 | nlmsg_free(msg); |
| 10699 | return; |
| 10700 | } |
| 10701 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10702 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10703 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 10704 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10705 | EXPORT_SYMBOL(cfg80211_new_sta); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 10706 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10707 | 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] | 10708 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10709 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
| 10710 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 10711 | struct sk_buff *msg; |
| 10712 | void *hdr; |
| 10713 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10714 | trace_cfg80211_del_sta(dev, mac_addr); |
| 10715 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10716 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 10717 | if (!msg) |
| 10718 | return; |
| 10719 | |
| 10720 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION); |
| 10721 | if (!hdr) { |
| 10722 | nlmsg_free(msg); |
| 10723 | return; |
| 10724 | } |
| 10725 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10726 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 10727 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 10728 | goto nla_put_failure; |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 10729 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10730 | genlmsg_end(msg, hdr); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 10731 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10732 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10733 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 10734 | return; |
| 10735 | |
| 10736 | nla_put_failure: |
| 10737 | genlmsg_cancel(msg, hdr); |
| 10738 | nlmsg_free(msg); |
| 10739 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10740 | EXPORT_SYMBOL(cfg80211_del_sta); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 10741 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10742 | void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr, |
| 10743 | enum nl80211_connect_failed_reason reason, |
| 10744 | gfp_t gfp) |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 10745 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10746 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
| 10747 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 10748 | struct sk_buff *msg; |
| 10749 | void *hdr; |
| 10750 | |
| 10751 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 10752 | if (!msg) |
| 10753 | return; |
| 10754 | |
| 10755 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED); |
| 10756 | if (!hdr) { |
| 10757 | nlmsg_free(msg); |
| 10758 | return; |
| 10759 | } |
| 10760 | |
| 10761 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 10762 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 10763 | nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason)) |
| 10764 | goto nla_put_failure; |
| 10765 | |
| 10766 | genlmsg_end(msg, hdr); |
| 10767 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10768 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10769 | NL80211_MCGRP_MLME, gfp); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 10770 | return; |
| 10771 | |
| 10772 | nla_put_failure: |
| 10773 | genlmsg_cancel(msg, hdr); |
| 10774 | nlmsg_free(msg); |
| 10775 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10776 | EXPORT_SYMBOL(cfg80211_conn_failed); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 10777 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 10778 | static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, |
| 10779 | const u8 *addr, gfp_t gfp) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10780 | { |
| 10781 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10782 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 10783 | struct sk_buff *msg; |
| 10784 | void *hdr; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10785 | u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10786 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10787 | if (!nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10788 | return false; |
| 10789 | |
| 10790 | msg = nlmsg_new(100, gfp); |
| 10791 | if (!msg) |
| 10792 | return true; |
| 10793 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 10794 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10795 | if (!hdr) { |
| 10796 | nlmsg_free(msg); |
| 10797 | return true; |
| 10798 | } |
| 10799 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10800 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10801 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 10802 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 10803 | goto nla_put_failure; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10804 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 10805 | genlmsg_end(msg, hdr); |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10806 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10807 | return true; |
| 10808 | |
| 10809 | nla_put_failure: |
| 10810 | genlmsg_cancel(msg, hdr); |
| 10811 | nlmsg_free(msg); |
| 10812 | return true; |
| 10813 | } |
| 10814 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10815 | bool cfg80211_rx_spurious_frame(struct net_device *dev, |
| 10816 | const u8 *addr, gfp_t gfp) |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 10817 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10818 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10819 | bool ret; |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 10820 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10821 | trace_cfg80211_rx_spurious_frame(dev, addr); |
| 10822 | |
| 10823 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 10824 | wdev->iftype != NL80211_IFTYPE_P2P_GO)) { |
| 10825 | trace_cfg80211_return_bool(false); |
| 10826 | return false; |
| 10827 | } |
| 10828 | ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, |
| 10829 | addr, gfp); |
| 10830 | trace_cfg80211_return_bool(ret); |
| 10831 | return ret; |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 10832 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10833 | EXPORT_SYMBOL(cfg80211_rx_spurious_frame); |
| 10834 | |
| 10835 | bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev, |
| 10836 | const u8 *addr, gfp_t gfp) |
| 10837 | { |
| 10838 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10839 | bool ret; |
| 10840 | |
| 10841 | trace_cfg80211_rx_unexpected_4addr_frame(dev, addr); |
| 10842 | |
| 10843 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 10844 | wdev->iftype != NL80211_IFTYPE_P2P_GO && |
| 10845 | wdev->iftype != NL80211_IFTYPE_AP_VLAN)) { |
| 10846 | trace_cfg80211_return_bool(false); |
| 10847 | return false; |
| 10848 | } |
| 10849 | ret = __nl80211_unexpected_frame(dev, |
| 10850 | NL80211_CMD_UNEXPECTED_4ADDR_FRAME, |
| 10851 | addr, gfp); |
| 10852 | trace_cfg80211_return_bool(ret); |
| 10853 | return ret; |
| 10854 | } |
| 10855 | EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame); |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 10856 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 10857 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10858 | struct wireless_dev *wdev, u32 nlportid, |
Johannes Berg | 804483e | 2012-03-05 22:18:41 +0100 | [diff] [blame] | 10859 | int freq, int sig_dbm, |
Vladimir Kondratiev | 19504cf | 2013-08-15 14:51:28 +0300 | [diff] [blame] | 10860 | const u8 *buf, size_t len, u32 flags, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10861 | { |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10862 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10863 | struct sk_buff *msg; |
| 10864 | void *hdr; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10865 | |
| 10866 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 10867 | if (!msg) |
| 10868 | return -ENOMEM; |
| 10869 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 10870 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10871 | if (!hdr) { |
| 10872 | nlmsg_free(msg); |
| 10873 | return -ENOMEM; |
| 10874 | } |
| 10875 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10876 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10877 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 10878 | netdev->ifindex)) || |
Ilan Peer | a838490 | 2013-05-08 16:35:55 +0300 | [diff] [blame] | 10879 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10880 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
| 10881 | (sig_dbm && |
| 10882 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
Vladimir Kondratiev | 19504cf | 2013-08-15 14:51:28 +0300 | [diff] [blame] | 10883 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
| 10884 | (flags && |
| 10885 | nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10886 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10887 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10888 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10889 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10890 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10891 | |
| 10892 | nla_put_failure: |
| 10893 | genlmsg_cancel(msg, hdr); |
| 10894 | nlmsg_free(msg); |
| 10895 | return -ENOBUFS; |
| 10896 | } |
| 10897 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10898 | void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie, |
| 10899 | const u8 *buf, size_t len, bool ack, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10900 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10901 | struct wiphy *wiphy = wdev->wiphy; |
| 10902 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10903 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10904 | struct sk_buff *msg; |
| 10905 | void *hdr; |
| 10906 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10907 | trace_cfg80211_mgmt_tx_status(wdev, cookie, ack); |
| 10908 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10909 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 10910 | if (!msg) |
| 10911 | return; |
| 10912 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 10913 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10914 | if (!hdr) { |
| 10915 | nlmsg_free(msg); |
| 10916 | return; |
| 10917 | } |
| 10918 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10919 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10920 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 10921 | netdev->ifindex)) || |
Ilan Peer | a838490 | 2013-05-08 16:35:55 +0300 | [diff] [blame] | 10922 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10923 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
| 10924 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || |
| 10925 | (ack && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 10926 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10927 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10928 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10929 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10930 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10931 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10932 | return; |
| 10933 | |
| 10934 | nla_put_failure: |
| 10935 | genlmsg_cancel(msg, hdr); |
| 10936 | nlmsg_free(msg); |
| 10937 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10938 | EXPORT_SYMBOL(cfg80211_mgmt_tx_status); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10939 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10940 | void cfg80211_cqm_rssi_notify(struct net_device *dev, |
| 10941 | enum nl80211_cqm_rssi_threshold_event rssi_event, |
| 10942 | gfp_t gfp) |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10943 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10944 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10945 | struct wiphy *wiphy = wdev->wiphy; |
| 10946 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10947 | struct sk_buff *msg; |
| 10948 | struct nlattr *pinfoattr; |
| 10949 | void *hdr; |
| 10950 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10951 | trace_cfg80211_cqm_rssi_notify(dev, rssi_event); |
| 10952 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10953 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10954 | if (!msg) |
| 10955 | return; |
| 10956 | |
| 10957 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 10958 | if (!hdr) { |
| 10959 | nlmsg_free(msg); |
| 10960 | return; |
| 10961 | } |
| 10962 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10963 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10964 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10965 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10966 | |
| 10967 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 10968 | if (!pinfoattr) |
| 10969 | goto nla_put_failure; |
| 10970 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10971 | if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, |
| 10972 | rssi_event)) |
| 10973 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10974 | |
| 10975 | nla_nest_end(msg, pinfoattr); |
| 10976 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10977 | genlmsg_end(msg, hdr); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10978 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10979 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10980 | NL80211_MCGRP_MLME, gfp); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10981 | return; |
| 10982 | |
| 10983 | nla_put_failure: |
| 10984 | genlmsg_cancel(msg, hdr); |
| 10985 | nlmsg_free(msg); |
| 10986 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10987 | EXPORT_SYMBOL(cfg80211_cqm_rssi_notify); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10988 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10989 | static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
| 10990 | struct net_device *netdev, const u8 *bssid, |
| 10991 | const u8 *replay_ctr, gfp_t gfp) |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10992 | { |
| 10993 | struct sk_buff *msg; |
| 10994 | struct nlattr *rekey_attr; |
| 10995 | void *hdr; |
| 10996 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10997 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10998 | if (!msg) |
| 10999 | return; |
| 11000 | |
| 11001 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); |
| 11002 | if (!hdr) { |
| 11003 | nlmsg_free(msg); |
| 11004 | return; |
| 11005 | } |
| 11006 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11007 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11008 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 11009 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 11010 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 11011 | |
| 11012 | rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); |
| 11013 | if (!rekey_attr) |
| 11014 | goto nla_put_failure; |
| 11015 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11016 | if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
| 11017 | NL80211_REPLAY_CTR_LEN, replay_ctr)) |
| 11018 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 11019 | |
| 11020 | nla_nest_end(msg, rekey_attr); |
| 11021 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11022 | genlmsg_end(msg, hdr); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 11023 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11024 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11025 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 11026 | return; |
| 11027 | |
| 11028 | nla_put_failure: |
| 11029 | genlmsg_cancel(msg, hdr); |
| 11030 | nlmsg_free(msg); |
| 11031 | } |
| 11032 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11033 | void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid, |
| 11034 | const u8 *replay_ctr, gfp_t gfp) |
| 11035 | { |
| 11036 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11037 | struct wiphy *wiphy = wdev->wiphy; |
| 11038 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 11039 | |
| 11040 | trace_cfg80211_gtk_rekey_notify(dev, bssid); |
| 11041 | nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp); |
| 11042 | } |
| 11043 | EXPORT_SYMBOL(cfg80211_gtk_rekey_notify); |
| 11044 | |
| 11045 | static void |
| 11046 | nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, |
| 11047 | struct net_device *netdev, int index, |
| 11048 | const u8 *bssid, bool preauth, gfp_t gfp) |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 11049 | { |
| 11050 | struct sk_buff *msg; |
| 11051 | struct nlattr *attr; |
| 11052 | void *hdr; |
| 11053 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11054 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 11055 | if (!msg) |
| 11056 | return; |
| 11057 | |
| 11058 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); |
| 11059 | if (!hdr) { |
| 11060 | nlmsg_free(msg); |
| 11061 | return; |
| 11062 | } |
| 11063 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11064 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11065 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 11066 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 11067 | |
| 11068 | attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE); |
| 11069 | if (!attr) |
| 11070 | goto nla_put_failure; |
| 11071 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11072 | if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) || |
| 11073 | nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) || |
| 11074 | (preauth && |
| 11075 | nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH))) |
| 11076 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 11077 | |
| 11078 | nla_nest_end(msg, attr); |
| 11079 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11080 | genlmsg_end(msg, hdr); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 11081 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11082 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11083 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 11084 | return; |
| 11085 | |
| 11086 | nla_put_failure: |
| 11087 | genlmsg_cancel(msg, hdr); |
| 11088 | nlmsg_free(msg); |
| 11089 | } |
| 11090 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11091 | void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index, |
| 11092 | const u8 *bssid, bool preauth, gfp_t gfp) |
| 11093 | { |
| 11094 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11095 | struct wiphy *wiphy = wdev->wiphy; |
| 11096 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 11097 | |
| 11098 | trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth); |
| 11099 | nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp); |
| 11100 | } |
| 11101 | EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify); |
| 11102 | |
| 11103 | static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev, |
| 11104 | struct net_device *netdev, |
| 11105 | struct cfg80211_chan_def *chandef, |
| 11106 | gfp_t gfp) |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 11107 | { |
| 11108 | struct sk_buff *msg; |
| 11109 | void *hdr; |
| 11110 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11111 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 11112 | if (!msg) |
| 11113 | return; |
| 11114 | |
| 11115 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY); |
| 11116 | if (!hdr) { |
| 11117 | nlmsg_free(msg); |
| 11118 | return; |
| 11119 | } |
| 11120 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 11121 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 11122 | goto nla_put_failure; |
| 11123 | |
| 11124 | if (nl80211_send_chandef(msg, chandef)) |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 11125 | goto nla_put_failure; |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 11126 | |
| 11127 | genlmsg_end(msg, hdr); |
| 11128 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11129 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11130 | NL80211_MCGRP_MLME, gfp); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 11131 | return; |
| 11132 | |
| 11133 | nla_put_failure: |
| 11134 | genlmsg_cancel(msg, hdr); |
| 11135 | nlmsg_free(msg); |
| 11136 | } |
| 11137 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11138 | void cfg80211_ch_switch_notify(struct net_device *dev, |
| 11139 | struct cfg80211_chan_def *chandef) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 11140 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11141 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11142 | struct wiphy *wiphy = wdev->wiphy; |
| 11143 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 11144 | |
Simon Wunderlich | e487eae | 2013-11-21 18:19:51 +0100 | [diff] [blame] | 11145 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11146 | |
Simon Wunderlich | e487eae | 2013-11-21 18:19:51 +0100 | [diff] [blame] | 11147 | trace_cfg80211_ch_switch_notify(dev, chandef); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11148 | |
| 11149 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 11150 | wdev->iftype != NL80211_IFTYPE_P2P_GO && |
Chun-Yeow Yeoh | b8456a1 | 2013-10-17 15:55:02 -0700 | [diff] [blame] | 11151 | wdev->iftype != NL80211_IFTYPE_ADHOC && |
| 11152 | wdev->iftype != NL80211_IFTYPE_MESH_POINT)) |
Simon Wunderlich | e487eae | 2013-11-21 18:19:51 +0100 | [diff] [blame] | 11153 | return; |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11154 | |
| 11155 | wdev->channel = chandef->chan; |
| 11156 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11157 | } |
| 11158 | EXPORT_SYMBOL(cfg80211_ch_switch_notify); |
| 11159 | |
| 11160 | void cfg80211_cqm_txe_notify(struct net_device *dev, |
| 11161 | const u8 *peer, u32 num_packets, |
| 11162 | u32 rate, u32 intvl, gfp_t gfp) |
| 11163 | { |
| 11164 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11165 | struct wiphy *wiphy = wdev->wiphy; |
| 11166 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 11167 | struct sk_buff *msg; |
| 11168 | struct nlattr *pinfoattr; |
| 11169 | void *hdr; |
| 11170 | |
| 11171 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 11172 | if (!msg) |
| 11173 | return; |
| 11174 | |
| 11175 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 11176 | if (!hdr) { |
| 11177 | nlmsg_free(msg); |
| 11178 | return; |
| 11179 | } |
| 11180 | |
| 11181 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11182 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 11183 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
| 11184 | goto nla_put_failure; |
| 11185 | |
| 11186 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 11187 | if (!pinfoattr) |
| 11188 | goto nla_put_failure; |
| 11189 | |
| 11190 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets)) |
| 11191 | goto nla_put_failure; |
| 11192 | |
| 11193 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate)) |
| 11194 | goto nla_put_failure; |
| 11195 | |
| 11196 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl)) |
| 11197 | goto nla_put_failure; |
| 11198 | |
| 11199 | nla_nest_end(msg, pinfoattr); |
| 11200 | |
| 11201 | genlmsg_end(msg, hdr); |
| 11202 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11203 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11204 | NL80211_MCGRP_MLME, gfp); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 11205 | return; |
| 11206 | |
| 11207 | nla_put_failure: |
| 11208 | genlmsg_cancel(msg, hdr); |
| 11209 | nlmsg_free(msg); |
| 11210 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11211 | EXPORT_SYMBOL(cfg80211_cqm_txe_notify); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 11212 | |
| 11213 | void |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 11214 | nl80211_radar_notify(struct cfg80211_registered_device *rdev, |
Janusz Dziedzic | d2859df | 2013-11-06 13:55:51 +0100 | [diff] [blame] | 11215 | const struct cfg80211_chan_def *chandef, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 11216 | enum nl80211_radar_event event, |
| 11217 | struct net_device *netdev, gfp_t gfp) |
| 11218 | { |
| 11219 | struct sk_buff *msg; |
| 11220 | void *hdr; |
| 11221 | |
| 11222 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 11223 | if (!msg) |
| 11224 | return; |
| 11225 | |
| 11226 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT); |
| 11227 | if (!hdr) { |
| 11228 | nlmsg_free(msg); |
| 11229 | return; |
| 11230 | } |
| 11231 | |
| 11232 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 11233 | goto nla_put_failure; |
| 11234 | |
| 11235 | /* NOP and radar events don't need a netdev parameter */ |
| 11236 | if (netdev) { |
| 11237 | struct wireless_dev *wdev = netdev->ieee80211_ptr; |
| 11238 | |
| 11239 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 11240 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 11241 | goto nla_put_failure; |
| 11242 | } |
| 11243 | |
| 11244 | if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event)) |
| 11245 | goto nla_put_failure; |
| 11246 | |
| 11247 | if (nl80211_send_chandef(msg, chandef)) |
| 11248 | goto nla_put_failure; |
| 11249 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 11250 | genlmsg_end(msg, hdr); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 11251 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11252 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11253 | NL80211_MCGRP_MLME, gfp); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 11254 | return; |
| 11255 | |
| 11256 | nla_put_failure: |
| 11257 | genlmsg_cancel(msg, hdr); |
| 11258 | nlmsg_free(msg); |
| 11259 | } |
| 11260 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11261 | void cfg80211_cqm_pktloss_notify(struct net_device *dev, |
| 11262 | const u8 *peer, u32 num_packets, gfp_t gfp) |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 11263 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11264 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11265 | struct wiphy *wiphy = wdev->wiphy; |
| 11266 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 11267 | struct sk_buff *msg; |
| 11268 | struct nlattr *pinfoattr; |
| 11269 | void *hdr; |
| 11270 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11271 | trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets); |
| 11272 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11273 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 11274 | if (!msg) |
| 11275 | return; |
| 11276 | |
| 11277 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 11278 | if (!hdr) { |
| 11279 | nlmsg_free(msg); |
| 11280 | return; |
| 11281 | } |
| 11282 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11283 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11284 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11285 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
| 11286 | goto nla_put_failure; |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 11287 | |
| 11288 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 11289 | if (!pinfoattr) |
| 11290 | goto nla_put_failure; |
| 11291 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11292 | if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets)) |
| 11293 | goto nla_put_failure; |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 11294 | |
| 11295 | nla_nest_end(msg, pinfoattr); |
| 11296 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11297 | genlmsg_end(msg, hdr); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 11298 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11299 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11300 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 11301 | return; |
| 11302 | |
| 11303 | nla_put_failure: |
| 11304 | genlmsg_cancel(msg, hdr); |
| 11305 | nlmsg_free(msg); |
| 11306 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11307 | EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 11308 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11309 | void cfg80211_probe_status(struct net_device *dev, const u8 *addr, |
| 11310 | u64 cookie, bool acked, gfp_t gfp) |
| 11311 | { |
| 11312 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11313 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 11314 | struct sk_buff *msg; |
| 11315 | void *hdr; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11316 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 11317 | trace_cfg80211_probe_status(dev, addr, cookie, acked); |
| 11318 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11319 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 11320 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11321 | if (!msg) |
| 11322 | return; |
| 11323 | |
| 11324 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); |
| 11325 | if (!hdr) { |
| 11326 | nlmsg_free(msg); |
| 11327 | return; |
| 11328 | } |
| 11329 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11330 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11331 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 11332 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 11333 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || |
| 11334 | (acked && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 11335 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11336 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 11337 | genlmsg_end(msg, hdr); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11338 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11339 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11340 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11341 | return; |
| 11342 | |
| 11343 | nla_put_failure: |
| 11344 | genlmsg_cancel(msg, hdr); |
| 11345 | nlmsg_free(msg); |
| 11346 | } |
| 11347 | EXPORT_SYMBOL(cfg80211_probe_status); |
| 11348 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11349 | void cfg80211_report_obss_beacon(struct wiphy *wiphy, |
| 11350 | const u8 *frame, size_t len, |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11351 | int freq, int sig_dbm) |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11352 | { |
| 11353 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 11354 | struct sk_buff *msg; |
| 11355 | void *hdr; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11356 | struct cfg80211_beacon_registration *reg; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11357 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 11358 | trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm); |
| 11359 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11360 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 11361 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 11362 | msg = nlmsg_new(len + 100, GFP_ATOMIC); |
| 11363 | if (!msg) { |
| 11364 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 11365 | return; |
| 11366 | } |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11367 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11368 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
| 11369 | if (!hdr) |
| 11370 | goto nla_put_failure; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11371 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11372 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11373 | (freq && |
| 11374 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || |
| 11375 | (sig_dbm && |
| 11376 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
| 11377 | nla_put(msg, NL80211_ATTR_FRAME, len, frame)) |
| 11378 | goto nla_put_failure; |
| 11379 | |
| 11380 | genlmsg_end(msg, hdr); |
| 11381 | |
| 11382 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11383 | } |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11384 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11385 | return; |
| 11386 | |
| 11387 | nla_put_failure: |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11388 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 11389 | if (hdr) |
| 11390 | genlmsg_cancel(msg, hdr); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11391 | nlmsg_free(msg); |
| 11392 | } |
| 11393 | EXPORT_SYMBOL(cfg80211_report_obss_beacon); |
| 11394 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 11395 | #ifdef CONFIG_PM |
| 11396 | void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev, |
| 11397 | struct cfg80211_wowlan_wakeup *wakeup, |
| 11398 | gfp_t gfp) |
| 11399 | { |
| 11400 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 11401 | struct sk_buff *msg; |
| 11402 | void *hdr; |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 11403 | int size = 200; |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 11404 | |
| 11405 | trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup); |
| 11406 | |
| 11407 | if (wakeup) |
| 11408 | size += wakeup->packet_present_len; |
| 11409 | |
| 11410 | msg = nlmsg_new(size, gfp); |
| 11411 | if (!msg) |
| 11412 | return; |
| 11413 | |
| 11414 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN); |
| 11415 | if (!hdr) |
| 11416 | goto free_msg; |
| 11417 | |
| 11418 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11419 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 11420 | goto free_msg; |
| 11421 | |
| 11422 | if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 11423 | wdev->netdev->ifindex)) |
| 11424 | goto free_msg; |
| 11425 | |
| 11426 | if (wakeup) { |
| 11427 | struct nlattr *reasons; |
| 11428 | |
| 11429 | reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
Johannes Berg | 7fa322c | 2013-10-25 11:16:58 +0200 | [diff] [blame] | 11430 | if (!reasons) |
| 11431 | goto free_msg; |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 11432 | |
| 11433 | if (wakeup->disconnect && |
| 11434 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) |
| 11435 | goto free_msg; |
| 11436 | if (wakeup->magic_pkt && |
| 11437 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) |
| 11438 | goto free_msg; |
| 11439 | if (wakeup->gtk_rekey_failure && |
| 11440 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) |
| 11441 | goto free_msg; |
| 11442 | if (wakeup->eap_identity_req && |
| 11443 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) |
| 11444 | goto free_msg; |
| 11445 | if (wakeup->four_way_handshake && |
| 11446 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) |
| 11447 | goto free_msg; |
| 11448 | if (wakeup->rfkill_release && |
| 11449 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)) |
| 11450 | goto free_msg; |
| 11451 | |
| 11452 | if (wakeup->pattern_idx >= 0 && |
| 11453 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 11454 | wakeup->pattern_idx)) |
| 11455 | goto free_msg; |
| 11456 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 11457 | if (wakeup->tcp_match && |
| 11458 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH)) |
| 11459 | goto free_msg; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11460 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 11461 | if (wakeup->tcp_connlost && |
| 11462 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST)) |
| 11463 | goto free_msg; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11464 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 11465 | if (wakeup->tcp_nomoretokens && |
| 11466 | nla_put_flag(msg, |
| 11467 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS)) |
| 11468 | goto free_msg; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11469 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 11470 | if (wakeup->packet) { |
| 11471 | u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211; |
| 11472 | u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN; |
| 11473 | |
| 11474 | if (!wakeup->packet_80211) { |
| 11475 | pkt_attr = |
| 11476 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023; |
| 11477 | len_attr = |
| 11478 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN; |
| 11479 | } |
| 11480 | |
| 11481 | if (wakeup->packet_len && |
| 11482 | nla_put_u32(msg, len_attr, wakeup->packet_len)) |
| 11483 | goto free_msg; |
| 11484 | |
| 11485 | if (nla_put(msg, pkt_attr, wakeup->packet_present_len, |
| 11486 | wakeup->packet)) |
| 11487 | goto free_msg; |
| 11488 | } |
| 11489 | |
| 11490 | nla_nest_end(msg, reasons); |
| 11491 | } |
| 11492 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 11493 | genlmsg_end(msg, hdr); |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 11494 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11495 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11496 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 11497 | return; |
| 11498 | |
| 11499 | free_msg: |
| 11500 | nlmsg_free(msg); |
| 11501 | } |
| 11502 | EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup); |
| 11503 | #endif |
| 11504 | |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 11505 | void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer, |
| 11506 | enum nl80211_tdls_operation oper, |
| 11507 | u16 reason_code, gfp_t gfp) |
| 11508 | { |
| 11509 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11510 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 11511 | struct sk_buff *msg; |
| 11512 | void *hdr; |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 11513 | |
| 11514 | trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper, |
| 11515 | reason_code); |
| 11516 | |
| 11517 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 11518 | if (!msg) |
| 11519 | return; |
| 11520 | |
| 11521 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER); |
| 11522 | if (!hdr) { |
| 11523 | nlmsg_free(msg); |
| 11524 | return; |
| 11525 | } |
| 11526 | |
| 11527 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11528 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 11529 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) || |
| 11530 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) || |
| 11531 | (reason_code > 0 && |
| 11532 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) |
| 11533 | goto nla_put_failure; |
| 11534 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 11535 | genlmsg_end(msg, hdr); |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 11536 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11537 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11538 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 11539 | return; |
| 11540 | |
| 11541 | nla_put_failure: |
| 11542 | genlmsg_cancel(msg, hdr); |
| 11543 | nlmsg_free(msg); |
| 11544 | } |
| 11545 | EXPORT_SYMBOL(cfg80211_tdls_oper_request); |
| 11546 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11547 | static int nl80211_netlink_notify(struct notifier_block * nb, |
| 11548 | unsigned long state, |
| 11549 | void *_notify) |
| 11550 | { |
| 11551 | struct netlink_notify *notify = _notify; |
| 11552 | struct cfg80211_registered_device *rdev; |
| 11553 | struct wireless_dev *wdev; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11554 | struct cfg80211_beacon_registration *reg, *tmp; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11555 | |
| 11556 | if (state != NETLINK_URELEASE) |
| 11557 | return NOTIFY_DONE; |
| 11558 | |
| 11559 | rcu_read_lock(); |
| 11560 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11561 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 11562 | list_for_each_entry_rcu(wdev, &rdev->wdev_list, list) |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11563 | cfg80211_mlme_unregister_socket(wdev, notify->portid); |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11564 | |
| 11565 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 11566 | list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations, |
| 11567 | list) { |
| 11568 | if (reg->nlportid == notify->portid) { |
| 11569 | list_del(®->list); |
| 11570 | kfree(reg); |
| 11571 | break; |
| 11572 | } |
| 11573 | } |
| 11574 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11575 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11576 | |
| 11577 | rcu_read_unlock(); |
| 11578 | |
| 11579 | return NOTIFY_DONE; |
| 11580 | } |
| 11581 | |
| 11582 | static struct notifier_block nl80211_netlink_notifier = { |
| 11583 | .notifier_call = nl80211_netlink_notify, |
| 11584 | }; |
| 11585 | |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 11586 | void cfg80211_ft_event(struct net_device *netdev, |
| 11587 | struct cfg80211_ft_event_params *ft_event) |
| 11588 | { |
| 11589 | struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy; |
| 11590 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 11591 | struct sk_buff *msg; |
| 11592 | void *hdr; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 11593 | |
| 11594 | trace_cfg80211_ft_event(wiphy, netdev, ft_event); |
| 11595 | |
| 11596 | if (!ft_event->target_ap) |
| 11597 | return; |
| 11598 | |
| 11599 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 11600 | if (!msg) |
| 11601 | return; |
| 11602 | |
| 11603 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT); |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 11604 | if (!hdr) |
| 11605 | goto out; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 11606 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 11607 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11608 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 11609 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap)) |
| 11610 | goto out; |
| 11611 | |
| 11612 | if (ft_event->ies && |
| 11613 | nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies)) |
| 11614 | goto out; |
| 11615 | if (ft_event->ric_ies && |
| 11616 | nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len, |
| 11617 | ft_event->ric_ies)) |
| 11618 | goto out; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 11619 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 11620 | genlmsg_end(msg, hdr); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 11621 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11622 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11623 | NL80211_MCGRP_MLME, GFP_KERNEL); |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 11624 | return; |
| 11625 | out: |
| 11626 | nlmsg_free(msg); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 11627 | } |
| 11628 | EXPORT_SYMBOL(cfg80211_ft_event); |
| 11629 | |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 11630 | void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp) |
| 11631 | { |
| 11632 | struct cfg80211_registered_device *rdev; |
| 11633 | struct sk_buff *msg; |
| 11634 | void *hdr; |
| 11635 | u32 nlportid; |
| 11636 | |
| 11637 | rdev = wiphy_to_dev(wdev->wiphy); |
| 11638 | if (!rdev->crit_proto_nlportid) |
| 11639 | return; |
| 11640 | |
| 11641 | nlportid = rdev->crit_proto_nlportid; |
| 11642 | rdev->crit_proto_nlportid = 0; |
| 11643 | |
| 11644 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 11645 | if (!msg) |
| 11646 | return; |
| 11647 | |
| 11648 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP); |
| 11649 | if (!hdr) |
| 11650 | goto nla_put_failure; |
| 11651 | |
| 11652 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11653 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 11654 | goto nla_put_failure; |
| 11655 | |
| 11656 | genlmsg_end(msg, hdr); |
| 11657 | |
| 11658 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
| 11659 | return; |
| 11660 | |
| 11661 | nla_put_failure: |
| 11662 | if (hdr) |
| 11663 | genlmsg_cancel(msg, hdr); |
| 11664 | nlmsg_free(msg); |
| 11665 | |
| 11666 | } |
| 11667 | EXPORT_SYMBOL(cfg80211_crit_proto_stopped); |
| 11668 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11669 | /* initialisation/exit functions */ |
| 11670 | |
| 11671 | int nl80211_init(void) |
| 11672 | { |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 11673 | int err; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11674 | |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11675 | err = genl_register_family_with_ops_groups(&nl80211_fam, nl80211_ops, |
| 11676 | nl80211_mcgrps); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11677 | if (err) |
| 11678 | return err; |
| 11679 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11680 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
| 11681 | if (err) |
| 11682 | goto err_out; |
| 11683 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11684 | return 0; |
| 11685 | err_out: |
| 11686 | genl_unregister_family(&nl80211_fam); |
| 11687 | return err; |
| 11688 | } |
| 11689 | |
| 11690 | void nl80211_exit(void) |
| 11691 | { |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11692 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11693 | genl_unregister_family(&nl80211_fam); |
| 11694 | } |