Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1 | /* |
| 2 | * This is the new netlink-based wireless configuration interface. |
| 3 | * |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4 | * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <linux/if.h> |
| 8 | #include <linux/module.h> |
| 9 | #include <linux/err.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 10 | #include <linux/slab.h> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11 | #include <linux/list.h> |
| 12 | #include <linux/if_ether.h> |
| 13 | #include <linux/ieee80211.h> |
| 14 | #include <linux/nl80211.h> |
| 15 | #include <linux/rtnetlink.h> |
| 16 | #include <linux/netlink.h> |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 17 | #include <linux/etherdevice.h> |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 18 | #include <net/net_namespace.h> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 19 | #include <net/genetlink.h> |
| 20 | #include <net/cfg80211.h> |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 21 | #include <net/sock.h> |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 22 | #include <net/inet_connection_sock.h> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 23 | #include "core.h" |
| 24 | #include "nl80211.h" |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 25 | #include "reg.h" |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 26 | #include "rdev-ops.h" |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 27 | |
Jouni Malinen | 5fb628e | 2011-08-10 23:54:35 +0300 | [diff] [blame] | 28 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 29 | struct genl_info *info, |
| 30 | struct cfg80211_crypto_settings *settings, |
| 31 | int cipher_limit); |
| 32 | |
Johannes Berg | f84f771 | 2013-11-14 17:14:45 +0100 | [diff] [blame] | 33 | static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 34 | struct genl_info *info); |
Johannes Berg | f84f771 | 2013-11-14 17:14:45 +0100 | [diff] [blame] | 35 | static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 36 | struct genl_info *info); |
| 37 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 38 | /* the netlink family */ |
| 39 | static struct genl_family nl80211_fam = { |
Marcel Holtmann | fb4e156 | 2013-04-28 16:22:06 -0700 | [diff] [blame] | 40 | .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */ |
| 41 | .name = NL80211_GENL_NAME, /* have users key off the name instead */ |
| 42 | .hdrsize = 0, /* no private header */ |
| 43 | .version = 1, /* no particular meaning now */ |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 44 | .maxattr = NL80211_ATTR_MAX, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 45 | .netnsok = true, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 46 | .pre_doit = nl80211_pre_doit, |
| 47 | .post_doit = nl80211_post_doit, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 48 | }; |
| 49 | |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 50 | /* multicast groups */ |
| 51 | enum nl80211_multicast_groups { |
| 52 | NL80211_MCGRP_CONFIG, |
| 53 | NL80211_MCGRP_SCAN, |
| 54 | NL80211_MCGRP_REGULATORY, |
| 55 | NL80211_MCGRP_MLME, |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 56 | NL80211_MCGRP_VENDOR, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 57 | NL80211_MCGRP_TESTMODE /* keep last - ifdef! */ |
| 58 | }; |
| 59 | |
| 60 | static const struct genl_multicast_group nl80211_mcgrps[] = { |
| 61 | [NL80211_MCGRP_CONFIG] = { .name = "config", }, |
| 62 | [NL80211_MCGRP_SCAN] = { .name = "scan", }, |
| 63 | [NL80211_MCGRP_REGULATORY] = { .name = "regulatory", }, |
| 64 | [NL80211_MCGRP_MLME] = { .name = "mlme", }, |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 65 | [NL80211_MCGRP_VENDOR] = { .name = "vendor", }, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 66 | #ifdef CONFIG_NL80211_TESTMODE |
| 67 | [NL80211_MCGRP_TESTMODE] = { .name = "testmode", } |
| 68 | #endif |
| 69 | }; |
| 70 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 71 | /* returns ERR_PTR values */ |
| 72 | static struct wireless_dev * |
| 73 | __cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 74 | { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 75 | struct cfg80211_registered_device *rdev; |
| 76 | struct wireless_dev *result = NULL; |
| 77 | bool have_ifidx = attrs[NL80211_ATTR_IFINDEX]; |
| 78 | bool have_wdev_id = attrs[NL80211_ATTR_WDEV]; |
| 79 | u64 wdev_id; |
| 80 | int wiphy_idx = -1; |
| 81 | int ifidx = -1; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 82 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 83 | ASSERT_RTNL(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 84 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 85 | if (!have_ifidx && !have_wdev_id) |
| 86 | return ERR_PTR(-EINVAL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 87 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 88 | if (have_ifidx) |
| 89 | ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); |
| 90 | if (have_wdev_id) { |
| 91 | wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); |
| 92 | wiphy_idx = wdev_id >> 32; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 93 | } |
| 94 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 95 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 96 | struct wireless_dev *wdev; |
| 97 | |
| 98 | if (wiphy_net(&rdev->wiphy) != netns) |
| 99 | continue; |
| 100 | |
| 101 | if (have_wdev_id && rdev->wiphy_idx != wiphy_idx) |
| 102 | continue; |
| 103 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 104 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
| 105 | if (have_ifidx && wdev->netdev && |
| 106 | wdev->netdev->ifindex == ifidx) { |
| 107 | result = wdev; |
| 108 | break; |
| 109 | } |
| 110 | if (have_wdev_id && wdev->identifier == (u32)wdev_id) { |
| 111 | result = wdev; |
| 112 | break; |
| 113 | } |
| 114 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 115 | |
| 116 | if (result) |
| 117 | break; |
| 118 | } |
| 119 | |
| 120 | if (result) |
| 121 | return result; |
| 122 | return ERR_PTR(-ENODEV); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 123 | } |
| 124 | |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 125 | static struct cfg80211_registered_device * |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 126 | __cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs) |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 127 | { |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 128 | struct cfg80211_registered_device *rdev = NULL, *tmp; |
| 129 | struct net_device *netdev; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 130 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 131 | ASSERT_RTNL(); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 132 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 133 | if (!attrs[NL80211_ATTR_WIPHY] && |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 134 | !attrs[NL80211_ATTR_IFINDEX] && |
| 135 | !attrs[NL80211_ATTR_WDEV]) |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 136 | return ERR_PTR(-EINVAL); |
| 137 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 138 | if (attrs[NL80211_ATTR_WIPHY]) |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 139 | rdev = cfg80211_rdev_by_wiphy_idx( |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 140 | nla_get_u32(attrs[NL80211_ATTR_WIPHY])); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 141 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 142 | if (attrs[NL80211_ATTR_WDEV]) { |
| 143 | u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); |
| 144 | struct wireless_dev *wdev; |
| 145 | bool found = false; |
| 146 | |
| 147 | tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32); |
| 148 | if (tmp) { |
| 149 | /* make sure wdev exists */ |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 150 | list_for_each_entry(wdev, &tmp->wdev_list, list) { |
| 151 | if (wdev->identifier != (u32)wdev_id) |
| 152 | continue; |
| 153 | found = true; |
| 154 | break; |
| 155 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 156 | |
| 157 | if (!found) |
| 158 | tmp = NULL; |
| 159 | |
| 160 | if (rdev && tmp != rdev) |
| 161 | return ERR_PTR(-EINVAL); |
| 162 | rdev = tmp; |
| 163 | } |
| 164 | } |
| 165 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 166 | if (attrs[NL80211_ATTR_IFINDEX]) { |
| 167 | int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 168 | netdev = __dev_get_by_index(netns, ifindex); |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 169 | if (netdev) { |
| 170 | if (netdev->ieee80211_ptr) |
| 171 | tmp = wiphy_to_dev( |
| 172 | netdev->ieee80211_ptr->wiphy); |
| 173 | else |
| 174 | tmp = NULL; |
| 175 | |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 176 | /* not wireless device -- return error */ |
| 177 | if (!tmp) |
| 178 | return ERR_PTR(-EINVAL); |
| 179 | |
| 180 | /* mismatch -- return error */ |
| 181 | if (rdev && tmp != rdev) |
| 182 | return ERR_PTR(-EINVAL); |
| 183 | |
| 184 | rdev = tmp; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 185 | } |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 186 | } |
| 187 | |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 188 | if (!rdev) |
| 189 | return ERR_PTR(-ENODEV); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 190 | |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 191 | if (netns != wiphy_net(&rdev->wiphy)) |
| 192 | return ERR_PTR(-ENODEV); |
| 193 | |
| 194 | return rdev; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | /* |
| 198 | * This function returns a pointer to the driver |
| 199 | * that the genl_info item that is passed refers to. |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 200 | * |
| 201 | * The result of this can be a PTR_ERR and hence must |
| 202 | * be checked with IS_ERR() for errors. |
| 203 | */ |
| 204 | static struct cfg80211_registered_device * |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 205 | cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info) |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 206 | { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 207 | return __cfg80211_rdev_from_attrs(netns, info->attrs); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 208 | } |
| 209 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 210 | /* policy for the attributes */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 211 | static const struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] = { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 212 | [NL80211_ATTR_WIPHY] = { .type = NLA_U32 }, |
| 213 | [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING, |
David S. Miller | 079e24e | 2009-05-26 21:15:00 -0700 | [diff] [blame] | 214 | .len = 20-1 }, |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 215 | [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED }, |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 216 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 217 | [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 }, |
Sujith | 094d05d | 2008-12-12 11:57:43 +0530 | [diff] [blame] | 218 | [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 219 | [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 }, |
| 220 | [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 }, |
| 221 | [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 }, |
| 222 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 223 | [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 }, |
| 224 | [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 }, |
| 225 | [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 }, |
| 226 | [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 }, |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 227 | [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 228 | |
| 229 | [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 }, |
| 230 | [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 }, |
| 231 | [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 232 | |
Eliad Peller | e007b85 | 2011-11-24 18:13:56 +0200 | [diff] [blame] | 233 | [NL80211_ATTR_MAC] = { .len = ETH_ALEN }, |
| 234 | [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 235 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 236 | [NL80211_ATTR_KEY] = { .type = NLA_NESTED, }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 237 | [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY, |
| 238 | .len = WLAN_MAX_KEY_LEN }, |
| 239 | [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 }, |
| 240 | [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 }, |
| 241 | [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG }, |
Jouni Malinen | 8196226 | 2011-11-02 23:36:31 +0200 | [diff] [blame] | 242 | [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 243 | [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 244 | |
| 245 | [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 }, |
| 246 | [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 }, |
| 247 | [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY, |
| 248 | .len = IEEE80211_MAX_DATA_LEN }, |
| 249 | [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY, |
| 250 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 251 | [NL80211_ATTR_STA_AID] = { .type = NLA_U16 }, |
| 252 | [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED }, |
| 253 | [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 }, |
| 254 | [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY, |
| 255 | .len = NL80211_MAX_SUPP_RATES }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 256 | [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 257 | [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 }, |
Johannes Berg | 0a9542e | 2008-10-15 11:54:04 +0200 | [diff] [blame] | 258 | [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 259 | [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 260 | .len = IEEE80211_MAX_MESH_ID_LEN }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 261 | [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 262 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 263 | [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 }, |
| 264 | [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED }, |
| 265 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 266 | [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 }, |
| 267 | [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 }, |
| 268 | [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 }, |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 269 | [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY, |
| 270 | .len = NL80211_MAX_SUPP_RATES }, |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 271 | [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 }, |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 272 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 273 | [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 274 | [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 275 | |
Johannes Berg | 6c73941 | 2011-11-03 09:27:01 +0100 | [diff] [blame] | 276 | [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 277 | |
| 278 | [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 }, |
| 279 | [NL80211_ATTR_IE] = { .type = NLA_BINARY, |
| 280 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 281 | [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED }, |
| 282 | [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 283 | |
| 284 | [NL80211_ATTR_SSID] = { .type = NLA_BINARY, |
| 285 | .len = IEEE80211_MAX_SSID_LEN }, |
| 286 | [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 }, |
| 287 | [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 288 | [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG }, |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 289 | [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG }, |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 290 | [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 }, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 291 | [NL80211_ATTR_STA_FLAGS2] = { |
| 292 | .len = sizeof(struct nl80211_sta_flag_update), |
| 293 | }, |
Jouni Malinen | 3f77316c | 2009-05-11 21:57:57 +0300 | [diff] [blame] | 294 | [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG }, |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 295 | [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 }, |
| 296 | [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG }, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 297 | [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG }, |
| 298 | [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 }, |
| 299 | [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 300 | [NL80211_ATTR_PID] = { .type = NLA_U32 }, |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 301 | [NL80211_ATTR_4ADDR] = { .type = NLA_U8 }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 302 | [NL80211_ATTR_PMKID] = { .type = NLA_BINARY, |
| 303 | .len = WLAN_PMKID_LEN }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 304 | [NL80211_ATTR_DURATION] = { .type = NLA_U32 }, |
| 305 | [NL80211_ATTR_COOKIE] = { .type = NLA_U64 }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 306 | [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 307 | [NL80211_ATTR_FRAME] = { .type = NLA_BINARY, |
| 308 | .len = IEEE80211_MAX_DATA_LEN }, |
| 309 | [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 310 | [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 311 | [NL80211_ATTR_CQM] = { .type = NLA_NESTED, }, |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 312 | [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG }, |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 313 | [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 }, |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 314 | [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 }, |
| 315 | [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 }, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 316 | [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 }, |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 317 | [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 }, |
| 318 | [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 }, |
Felix Fietkau | 885a46d | 2010-11-11 15:07:22 +0100 | [diff] [blame] | 319 | [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 }, |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 320 | [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 321 | [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 322 | [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED }, |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 323 | [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 }, |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 324 | [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 }, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 325 | [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED }, |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 326 | [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED }, |
Jouni Malinen | 32e9de8 | 2011-08-10 23:53:31 +0300 | [diff] [blame] | 327 | [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 }, |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 328 | [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY, |
| 329 | .len = IEEE80211_MAX_DATA_LEN }, |
| 330 | [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY, |
| 331 | .len = IEEE80211_MAX_DATA_LEN }, |
Vivek Natarajan | f4b34b5 | 2011-08-29 14:23:03 +0530 | [diff] [blame] | 332 | [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG }, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 333 | [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED }, |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 334 | [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 335 | [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 }, |
| 336 | [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 }, |
| 337 | [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 }, |
| 338 | [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG }, |
| 339 | [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG }, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 340 | [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG }, |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 341 | [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY, |
| 342 | .len = IEEE80211_MAX_DATA_LEN }, |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 343 | [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 }, |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 344 | [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG }, |
| 345 | [NL80211_ATTR_HT_CAPABILITY_MASK] = { |
| 346 | .len = NL80211_HT_CAPABILITY_LEN |
| 347 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 348 | [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 }, |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 349 | [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 }, |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 350 | [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 }, |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 351 | [NL80211_ATTR_WDEV] = { .type = NLA_U64 }, |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 352 | [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 }, |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 353 | [NL80211_ATTR_SAE_DATA] = { .type = NLA_BINARY, }, |
Mahesh Palivela | f461be3e | 2012-10-11 08:04:52 +0000 | [diff] [blame] | 354 | [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN }, |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 355 | [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 }, |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 356 | [NL80211_ATTR_P2P_CTWINDOW] = { .type = NLA_U8 }, |
| 357 | [NL80211_ATTR_P2P_OPPPS] = { .type = NLA_U8 }, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 358 | [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 }, |
| 359 | [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED }, |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 360 | [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 }, |
| 361 | [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, }, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 362 | [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, }, |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 363 | [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG }, |
| 364 | [NL80211_ATTR_VHT_CAPABILITY_MASK] = { |
| 365 | .len = NL80211_VHT_CAPABILITY_LEN, |
| 366 | }, |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 367 | [NL80211_ATTR_MDID] = { .type = NLA_U16 }, |
| 368 | [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY, |
| 369 | .len = IEEE80211_MAX_DATA_LEN }, |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 370 | [NL80211_ATTR_PEER_AID] = { .type = NLA_U16 }, |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 371 | [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 }, |
| 372 | [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG }, |
| 373 | [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED }, |
| 374 | [NL80211_ATTR_CSA_C_OFF_BEACON] = { .type = NLA_U16 }, |
| 375 | [NL80211_ATTR_CSA_C_OFF_PRESP] = { .type = NLA_U16 }, |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 376 | [NL80211_ATTR_STA_SUPPORTED_CHANNELS] = { .type = NLA_BINARY }, |
| 377 | [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES] = { .type = NLA_BINARY }, |
Simon Wunderlich | 5336fa8 | 2013-10-07 18:41:05 +0200 | [diff] [blame] | 378 | [NL80211_ATTR_HANDLE_DFS] = { .type = NLA_FLAG }, |
Marek Kwaczynski | 60f4a7b | 2013-12-03 10:04:59 +0100 | [diff] [blame] | 379 | [NL80211_ATTR_OPMODE_NOTIF] = { .type = NLA_U8 }, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 380 | [NL80211_ATTR_VENDOR_ID] = { .type = NLA_U32 }, |
| 381 | [NL80211_ATTR_VENDOR_SUBCMD] = { .type = NLA_U32 }, |
| 382 | [NL80211_ATTR_VENDOR_DATA] = { .type = NLA_BINARY }, |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 383 | [NL80211_ATTR_QOS_MAP] = { .type = NLA_BINARY, |
| 384 | .len = IEEE80211_QOS_MAP_LEN_MAX }, |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 385 | [NL80211_ATTR_MAC_HINT] = { .len = ETH_ALEN }, |
| 386 | [NL80211_ATTR_WIPHY_FREQ_HINT] = { .type = NLA_U32 }, |
Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 387 | [NL80211_ATTR_TDLS_PEER_CAPABILITY] = { .type = NLA_U32 }, |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 388 | [NL80211_ATTR_IFACE_SOCKET_OWNER] = { .type = NLA_FLAG }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 389 | }; |
| 390 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 391 | /* policy for the key attributes */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 392 | static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 393 | [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 394 | [NL80211_KEY_IDX] = { .type = NLA_U8 }, |
| 395 | [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, |
Jouni Malinen | 8196226 | 2011-11-02 23:36:31 +0200 | [diff] [blame] | 396 | [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 397 | [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, |
| 398 | [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 399 | [NL80211_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 400 | [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
| 401 | }; |
| 402 | |
| 403 | /* policy for the key default flags */ |
| 404 | static const struct nla_policy |
| 405 | nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = { |
| 406 | [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG }, |
| 407 | [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 408 | }; |
| 409 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 410 | /* policy for WoWLAN attributes */ |
| 411 | static const struct nla_policy |
| 412 | nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = { |
| 413 | [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG }, |
| 414 | [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG }, |
| 415 | [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG }, |
| 416 | [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED }, |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 417 | [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG }, |
| 418 | [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG }, |
| 419 | [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG }, |
| 420 | [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG }, |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 421 | [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED }, |
| 422 | }; |
| 423 | |
| 424 | static const struct nla_policy |
| 425 | nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = { |
| 426 | [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 }, |
| 427 | [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 }, |
| 428 | [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN }, |
| 429 | [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 }, |
| 430 | [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 }, |
| 431 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 }, |
| 432 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = { |
| 433 | .len = sizeof(struct nl80211_wowlan_tcp_data_seq) |
| 434 | }, |
| 435 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = { |
| 436 | .len = sizeof(struct nl80211_wowlan_tcp_data_token) |
| 437 | }, |
| 438 | [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 }, |
| 439 | [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 }, |
| 440 | [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 441 | }; |
| 442 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 443 | /* policy for coalesce rule attributes */ |
| 444 | static const struct nla_policy |
| 445 | nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = { |
| 446 | [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 }, |
| 447 | [NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 }, |
| 448 | [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED }, |
| 449 | }; |
| 450 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 451 | /* policy for GTK rekey offload attributes */ |
| 452 | static const struct nla_policy |
| 453 | nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = { |
| 454 | [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN }, |
| 455 | [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN }, |
| 456 | [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN }, |
| 457 | }; |
| 458 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 459 | static const struct nla_policy |
| 460 | nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = { |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 461 | [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 462 | .len = IEEE80211_MAX_SSID_LEN }, |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 463 | [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 }, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 464 | }; |
| 465 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 466 | static int nl80211_prepare_wdev_dump(struct sk_buff *skb, |
| 467 | struct netlink_callback *cb, |
| 468 | struct cfg80211_registered_device **rdev, |
| 469 | struct wireless_dev **wdev) |
Holger Schurig | a043897 | 2009-11-11 11:30:02 +0100 | [diff] [blame] | 470 | { |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 471 | int err; |
| 472 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 473 | rtnl_lock(); |
| 474 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 475 | if (!cb->args[0]) { |
| 476 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 477 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 478 | nl80211_policy); |
| 479 | if (err) |
| 480 | goto out_unlock; |
| 481 | |
| 482 | *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk), |
| 483 | nl80211_fam.attrbuf); |
| 484 | if (IS_ERR(*wdev)) { |
| 485 | err = PTR_ERR(*wdev); |
| 486 | goto out_unlock; |
| 487 | } |
| 488 | *rdev = wiphy_to_dev((*wdev)->wiphy); |
Johannes Berg | c319d50 | 2013-07-30 22:34:28 +0200 | [diff] [blame] | 489 | /* 0 is the first index - add 1 to parse only once */ |
| 490 | cb->args[0] = (*rdev)->wiphy_idx + 1; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 491 | cb->args[1] = (*wdev)->identifier; |
| 492 | } else { |
Johannes Berg | c319d50 | 2013-07-30 22:34:28 +0200 | [diff] [blame] | 493 | /* subtract the 1 again here */ |
| 494 | struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1); |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 495 | struct wireless_dev *tmp; |
| 496 | |
| 497 | if (!wiphy) { |
| 498 | err = -ENODEV; |
| 499 | goto out_unlock; |
| 500 | } |
| 501 | *rdev = wiphy_to_dev(wiphy); |
| 502 | *wdev = NULL; |
| 503 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 504 | list_for_each_entry(tmp, &(*rdev)->wdev_list, list) { |
| 505 | if (tmp->identifier == cb->args[1]) { |
| 506 | *wdev = tmp; |
| 507 | break; |
| 508 | } |
| 509 | } |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 510 | |
| 511 | if (!*wdev) { |
| 512 | err = -ENODEV; |
| 513 | goto out_unlock; |
| 514 | } |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 515 | } |
| 516 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 517 | return 0; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 518 | out_unlock: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 519 | rtnl_unlock(); |
| 520 | return err; |
| 521 | } |
| 522 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 523 | static void nl80211_finish_wdev_dump(struct cfg80211_registered_device *rdev) |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 524 | { |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 525 | rtnl_unlock(); |
| 526 | } |
| 527 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 528 | /* IE validation */ |
| 529 | static bool is_valid_ie_attr(const struct nlattr *attr) |
| 530 | { |
| 531 | const u8 *pos; |
| 532 | int len; |
| 533 | |
| 534 | if (!attr) |
| 535 | return true; |
| 536 | |
| 537 | pos = nla_data(attr); |
| 538 | len = nla_len(attr); |
| 539 | |
| 540 | while (len) { |
| 541 | u8 elemlen; |
| 542 | |
| 543 | if (len < 2) |
| 544 | return false; |
| 545 | len -= 2; |
| 546 | |
| 547 | elemlen = pos[1]; |
| 548 | if (elemlen > len) |
| 549 | return false; |
| 550 | |
| 551 | len -= elemlen; |
| 552 | pos += 2 + elemlen; |
| 553 | } |
| 554 | |
| 555 | return true; |
| 556 | } |
| 557 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 558 | /* message building helper */ |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 559 | static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 560 | int flags, u8 cmd) |
| 561 | { |
| 562 | /* since there is no private header just add the generic one */ |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 563 | return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 564 | } |
| 565 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 566 | static int nl80211_msg_put_channel(struct sk_buff *msg, |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 567 | struct ieee80211_channel *chan, |
| 568 | bool large) |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 569 | { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 570 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
| 571 | chan->center_freq)) |
| 572 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 573 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 574 | if ((chan->flags & IEEE80211_CHAN_DISABLED) && |
| 575 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED)) |
| 576 | goto nla_put_failure; |
Luis R. Rodriguez | 8fe02e1 | 2013-10-21 19:22:25 +0200 | [diff] [blame] | 577 | if (chan->flags & IEEE80211_CHAN_NO_IR) { |
| 578 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR)) |
| 579 | goto nla_put_failure; |
| 580 | if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS)) |
| 581 | goto nla_put_failure; |
| 582 | } |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 583 | if (chan->flags & IEEE80211_CHAN_RADAR) { |
| 584 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR)) |
| 585 | goto nla_put_failure; |
| 586 | if (large) { |
| 587 | u32 time; |
| 588 | |
| 589 | time = elapsed_jiffies_msecs(chan->dfs_state_entered); |
| 590 | |
| 591 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE, |
| 592 | chan->dfs_state)) |
| 593 | goto nla_put_failure; |
| 594 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME, |
| 595 | time)) |
| 596 | goto nla_put_failure; |
Janusz Dziedzic | 089027e | 2014-02-21 19:46:12 +0100 | [diff] [blame] | 597 | if (nla_put_u32(msg, |
| 598 | NL80211_FREQUENCY_ATTR_DFS_CAC_TIME, |
| 599 | chan->dfs_cac_ms)) |
| 600 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 601 | } |
| 602 | } |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 603 | |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 604 | if (large) { |
| 605 | if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) && |
| 606 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS)) |
| 607 | goto nla_put_failure; |
| 608 | if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) && |
| 609 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS)) |
| 610 | goto nla_put_failure; |
| 611 | if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) && |
| 612 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ)) |
| 613 | goto nla_put_failure; |
| 614 | if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) && |
| 615 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ)) |
| 616 | goto nla_put_failure; |
David Spinadel | 570dbde | 2014-02-23 09:12:59 +0200 | [diff] [blame^] | 617 | if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) && |
| 618 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY)) |
| 619 | goto nla_put_failure; |
| 620 | if ((chan->flags & IEEE80211_CHAN_GO_CONCURRENT) && |
| 621 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_GO_CONCURRENT)) |
| 622 | goto nla_put_failure; |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 623 | } |
| 624 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 625 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
| 626 | DBM_TO_MBM(chan->max_power))) |
| 627 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 628 | |
| 629 | return 0; |
| 630 | |
| 631 | nla_put_failure: |
| 632 | return -ENOBUFS; |
| 633 | } |
| 634 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 635 | /* netlink command implementations */ |
| 636 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 637 | struct key_parse { |
| 638 | struct key_params p; |
| 639 | int idx; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 640 | int type; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 641 | bool def, defmgmt; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 642 | bool def_uni, def_multi; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 643 | }; |
| 644 | |
| 645 | static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k) |
| 646 | { |
| 647 | struct nlattr *tb[NL80211_KEY_MAX + 1]; |
| 648 | int err = nla_parse_nested(tb, NL80211_KEY_MAX, key, |
| 649 | nl80211_key_policy); |
| 650 | if (err) |
| 651 | return err; |
| 652 | |
| 653 | k->def = !!tb[NL80211_KEY_DEFAULT]; |
| 654 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; |
| 655 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 656 | if (k->def) { |
| 657 | k->def_uni = true; |
| 658 | k->def_multi = true; |
| 659 | } |
| 660 | if (k->defmgmt) |
| 661 | k->def_multi = true; |
| 662 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 663 | if (tb[NL80211_KEY_IDX]) |
| 664 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); |
| 665 | |
| 666 | if (tb[NL80211_KEY_DATA]) { |
| 667 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); |
| 668 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); |
| 669 | } |
| 670 | |
| 671 | if (tb[NL80211_KEY_SEQ]) { |
| 672 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); |
| 673 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); |
| 674 | } |
| 675 | |
| 676 | if (tb[NL80211_KEY_CIPHER]) |
| 677 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); |
| 678 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 679 | if (tb[NL80211_KEY_TYPE]) { |
| 680 | k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); |
| 681 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 682 | return -EINVAL; |
| 683 | } |
| 684 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 685 | if (tb[NL80211_KEY_DEFAULT_TYPES]) { |
| 686 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
Johannes Berg | 2da8f41 | 2012-01-20 13:52:37 +0100 | [diff] [blame] | 687 | err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 688 | tb[NL80211_KEY_DEFAULT_TYPES], |
| 689 | nl80211_key_default_policy); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 690 | if (err) |
| 691 | return err; |
| 692 | |
| 693 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 694 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 695 | } |
| 696 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 697 | return 0; |
| 698 | } |
| 699 | |
| 700 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) |
| 701 | { |
| 702 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { |
| 703 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 704 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 705 | } |
| 706 | |
| 707 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { |
| 708 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 709 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 710 | } |
| 711 | |
| 712 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 713 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 714 | |
| 715 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) |
| 716 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); |
| 717 | |
| 718 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; |
| 719 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; |
| 720 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 721 | if (k->def) { |
| 722 | k->def_uni = true; |
| 723 | k->def_multi = true; |
| 724 | } |
| 725 | if (k->defmgmt) |
| 726 | k->def_multi = true; |
| 727 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 728 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 729 | k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 730 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 731 | return -EINVAL; |
| 732 | } |
| 733 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 734 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { |
| 735 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
| 736 | int err = nla_parse_nested( |
| 737 | kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 738 | info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], |
| 739 | nl80211_key_default_policy); |
| 740 | if (err) |
| 741 | return err; |
| 742 | |
| 743 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 744 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 745 | } |
| 746 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 747 | return 0; |
| 748 | } |
| 749 | |
| 750 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) |
| 751 | { |
| 752 | int err; |
| 753 | |
| 754 | memset(k, 0, sizeof(*k)); |
| 755 | k->idx = -1; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 756 | k->type = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 757 | |
| 758 | if (info->attrs[NL80211_ATTR_KEY]) |
| 759 | err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k); |
| 760 | else |
| 761 | err = nl80211_parse_key_old(info, k); |
| 762 | |
| 763 | if (err) |
| 764 | return err; |
| 765 | |
| 766 | if (k->def && k->defmgmt) |
| 767 | return -EINVAL; |
| 768 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 769 | if (k->defmgmt) { |
| 770 | if (k->def_uni || !k->def_multi) |
| 771 | return -EINVAL; |
| 772 | } |
| 773 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 774 | if (k->idx != -1) { |
| 775 | if (k->defmgmt) { |
| 776 | if (k->idx < 4 || k->idx > 5) |
| 777 | return -EINVAL; |
| 778 | } else if (k->def) { |
| 779 | if (k->idx < 0 || k->idx > 3) |
| 780 | return -EINVAL; |
| 781 | } else { |
| 782 | if (k->idx < 0 || k->idx > 5) |
| 783 | return -EINVAL; |
| 784 | } |
| 785 | } |
| 786 | |
| 787 | return 0; |
| 788 | } |
| 789 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 790 | static struct cfg80211_cached_keys * |
| 791 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 792 | struct nlattr *keys, bool *no_ht) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 793 | { |
| 794 | struct key_parse parse; |
| 795 | struct nlattr *key; |
| 796 | struct cfg80211_cached_keys *result; |
| 797 | int rem, err, def = 0; |
| 798 | |
| 799 | result = kzalloc(sizeof(*result), GFP_KERNEL); |
| 800 | if (!result) |
| 801 | return ERR_PTR(-ENOMEM); |
| 802 | |
| 803 | result->def = -1; |
| 804 | result->defmgmt = -1; |
| 805 | |
| 806 | nla_for_each_nested(key, keys, rem) { |
| 807 | memset(&parse, 0, sizeof(parse)); |
| 808 | parse.idx = -1; |
| 809 | |
| 810 | err = nl80211_parse_key_new(key, &parse); |
| 811 | if (err) |
| 812 | goto error; |
| 813 | err = -EINVAL; |
| 814 | if (!parse.p.key) |
| 815 | goto error; |
| 816 | if (parse.idx < 0 || parse.idx > 4) |
| 817 | goto error; |
| 818 | if (parse.def) { |
| 819 | if (def) |
| 820 | goto error; |
| 821 | def = 1; |
| 822 | result->def = parse.idx; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 823 | if (!parse.def_uni || !parse.def_multi) |
| 824 | goto error; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 825 | } else if (parse.defmgmt) |
| 826 | goto error; |
| 827 | err = cfg80211_validate_key_settings(rdev, &parse.p, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 828 | parse.idx, false, NULL); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 829 | if (err) |
| 830 | goto error; |
| 831 | result->params[parse.idx].cipher = parse.p.cipher; |
| 832 | result->params[parse.idx].key_len = parse.p.key_len; |
| 833 | result->params[parse.idx].key = result->data[parse.idx]; |
| 834 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 835 | |
| 836 | if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 || |
| 837 | parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) { |
| 838 | if (no_ht) |
| 839 | *no_ht = true; |
| 840 | } |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 841 | } |
| 842 | |
| 843 | return result; |
| 844 | error: |
| 845 | kfree(result); |
| 846 | return ERR_PTR(err); |
| 847 | } |
| 848 | |
| 849 | static int nl80211_key_allowed(struct wireless_dev *wdev) |
| 850 | { |
| 851 | ASSERT_WDEV_LOCK(wdev); |
| 852 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 853 | switch (wdev->iftype) { |
| 854 | case NL80211_IFTYPE_AP: |
| 855 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 856 | case NL80211_IFTYPE_P2P_GO: |
Thomas Pedersen | ff973af | 2011-05-03 16:57:12 -0700 | [diff] [blame] | 857 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 858 | break; |
| 859 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 860 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 861 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 862 | if (!wdev->current_bss) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 863 | return -ENOLINK; |
| 864 | break; |
| 865 | default: |
| 866 | return -EINVAL; |
| 867 | } |
| 868 | |
| 869 | return 0; |
| 870 | } |
| 871 | |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 872 | static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy, |
| 873 | struct nlattr *tb) |
| 874 | { |
| 875 | struct ieee80211_channel *chan; |
| 876 | |
| 877 | if (tb == NULL) |
| 878 | return NULL; |
| 879 | chan = ieee80211_get_channel(wiphy, nla_get_u32(tb)); |
| 880 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) |
| 881 | return NULL; |
| 882 | return chan; |
| 883 | } |
| 884 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 885 | static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) |
| 886 | { |
| 887 | struct nlattr *nl_modes = nla_nest_start(msg, attr); |
| 888 | int i; |
| 889 | |
| 890 | if (!nl_modes) |
| 891 | goto nla_put_failure; |
| 892 | |
| 893 | i = 0; |
| 894 | while (ifmodes) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 895 | if ((ifmodes & 1) && nla_put_flag(msg, i)) |
| 896 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 897 | ifmodes >>= 1; |
| 898 | i++; |
| 899 | } |
| 900 | |
| 901 | nla_nest_end(msg, nl_modes); |
| 902 | return 0; |
| 903 | |
| 904 | nla_put_failure: |
| 905 | return -ENOBUFS; |
| 906 | } |
| 907 | |
| 908 | static int nl80211_put_iface_combinations(struct wiphy *wiphy, |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 909 | struct sk_buff *msg, |
| 910 | bool large) |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 911 | { |
| 912 | struct nlattr *nl_combis; |
| 913 | int i, j; |
| 914 | |
| 915 | nl_combis = nla_nest_start(msg, |
| 916 | NL80211_ATTR_INTERFACE_COMBINATIONS); |
| 917 | if (!nl_combis) |
| 918 | goto nla_put_failure; |
| 919 | |
| 920 | for (i = 0; i < wiphy->n_iface_combinations; i++) { |
| 921 | const struct ieee80211_iface_combination *c; |
| 922 | struct nlattr *nl_combi, *nl_limits; |
| 923 | |
| 924 | c = &wiphy->iface_combinations[i]; |
| 925 | |
| 926 | nl_combi = nla_nest_start(msg, i + 1); |
| 927 | if (!nl_combi) |
| 928 | goto nla_put_failure; |
| 929 | |
| 930 | nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS); |
| 931 | if (!nl_limits) |
| 932 | goto nla_put_failure; |
| 933 | |
| 934 | for (j = 0; j < c->n_limits; j++) { |
| 935 | struct nlattr *nl_limit; |
| 936 | |
| 937 | nl_limit = nla_nest_start(msg, j + 1); |
| 938 | if (!nl_limit) |
| 939 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 940 | if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX, |
| 941 | c->limits[j].max)) |
| 942 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 943 | if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, |
| 944 | c->limits[j].types)) |
| 945 | goto nla_put_failure; |
| 946 | nla_nest_end(msg, nl_limit); |
| 947 | } |
| 948 | |
| 949 | nla_nest_end(msg, nl_limits); |
| 950 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 951 | if (c->beacon_int_infra_match && |
| 952 | nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH)) |
| 953 | goto nla_put_failure; |
| 954 | if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, |
| 955 | c->num_different_channels) || |
| 956 | nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM, |
| 957 | c->max_interfaces)) |
| 958 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 959 | if (large && |
| 960 | nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS, |
| 961 | c->radar_detect_widths)) |
| 962 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 963 | |
| 964 | nla_nest_end(msg, nl_combi); |
| 965 | } |
| 966 | |
| 967 | nla_nest_end(msg, nl_combis); |
| 968 | |
| 969 | return 0; |
| 970 | nla_put_failure: |
| 971 | return -ENOBUFS; |
| 972 | } |
| 973 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 974 | #ifdef CONFIG_PM |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 975 | static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev, |
| 976 | struct sk_buff *msg) |
| 977 | { |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 978 | const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp; |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 979 | struct nlattr *nl_tcp; |
| 980 | |
| 981 | if (!tcp) |
| 982 | return 0; |
| 983 | |
| 984 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); |
| 985 | if (!nl_tcp) |
| 986 | return -ENOBUFS; |
| 987 | |
| 988 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 989 | tcp->data_payload_max)) |
| 990 | return -ENOBUFS; |
| 991 | |
| 992 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 993 | tcp->data_payload_max)) |
| 994 | return -ENOBUFS; |
| 995 | |
| 996 | if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ)) |
| 997 | return -ENOBUFS; |
| 998 | |
| 999 | if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, |
| 1000 | sizeof(*tcp->tok), tcp->tok)) |
| 1001 | return -ENOBUFS; |
| 1002 | |
| 1003 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, |
| 1004 | tcp->data_interval_max)) |
| 1005 | return -ENOBUFS; |
| 1006 | |
| 1007 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, |
| 1008 | tcp->wake_payload_max)) |
| 1009 | return -ENOBUFS; |
| 1010 | |
| 1011 | nla_nest_end(msg, nl_tcp); |
| 1012 | return 0; |
| 1013 | } |
| 1014 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1015 | static int nl80211_send_wowlan(struct sk_buff *msg, |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1016 | struct cfg80211_registered_device *dev, |
| 1017 | bool large) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1018 | { |
| 1019 | struct nlattr *nl_wowlan; |
| 1020 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 1021 | if (!dev->wiphy.wowlan) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1022 | return 0; |
| 1023 | |
| 1024 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); |
| 1025 | if (!nl_wowlan) |
| 1026 | return -ENOBUFS; |
| 1027 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 1028 | if (((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1029 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 1030 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1031 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 1032 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1033 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 1034 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1035 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) || |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 1036 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1037 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 1038 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1039 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 1040 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1041 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 1042 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1043 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 1044 | return -ENOBUFS; |
| 1045 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 1046 | if (dev->wiphy.wowlan->n_patterns) { |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 1047 | struct nl80211_pattern_support pat = { |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 1048 | .max_patterns = dev->wiphy.wowlan->n_patterns, |
| 1049 | .min_pattern_len = dev->wiphy.wowlan->pattern_min_len, |
| 1050 | .max_pattern_len = dev->wiphy.wowlan->pattern_max_len, |
| 1051 | .max_pkt_offset = dev->wiphy.wowlan->max_pkt_offset, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1052 | }; |
| 1053 | |
| 1054 | if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 1055 | sizeof(pat), &pat)) |
| 1056 | return -ENOBUFS; |
| 1057 | } |
| 1058 | |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1059 | if (large && nl80211_send_wowlan_tcp_caps(dev, msg)) |
| 1060 | return -ENOBUFS; |
| 1061 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1062 | nla_nest_end(msg, nl_wowlan); |
| 1063 | |
| 1064 | return 0; |
| 1065 | } |
| 1066 | #endif |
| 1067 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1068 | static int nl80211_send_coalesce(struct sk_buff *msg, |
| 1069 | struct cfg80211_registered_device *dev) |
| 1070 | { |
| 1071 | struct nl80211_coalesce_rule_support rule; |
| 1072 | |
| 1073 | if (!dev->wiphy.coalesce) |
| 1074 | return 0; |
| 1075 | |
| 1076 | rule.max_rules = dev->wiphy.coalesce->n_rules; |
| 1077 | rule.max_delay = dev->wiphy.coalesce->max_delay; |
| 1078 | rule.pat.max_patterns = dev->wiphy.coalesce->n_patterns; |
| 1079 | rule.pat.min_pattern_len = dev->wiphy.coalesce->pattern_min_len; |
| 1080 | rule.pat.max_pattern_len = dev->wiphy.coalesce->pattern_max_len; |
| 1081 | rule.pat.max_pkt_offset = dev->wiphy.coalesce->max_pkt_offset; |
| 1082 | |
| 1083 | if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule)) |
| 1084 | return -ENOBUFS; |
| 1085 | |
| 1086 | return 0; |
| 1087 | } |
| 1088 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1089 | static int nl80211_send_band_rateinfo(struct sk_buff *msg, |
| 1090 | struct ieee80211_supported_band *sband) |
| 1091 | { |
| 1092 | struct nlattr *nl_rates, *nl_rate; |
| 1093 | struct ieee80211_rate *rate; |
| 1094 | int i; |
| 1095 | |
| 1096 | /* add HT info */ |
| 1097 | if (sband->ht_cap.ht_supported && |
| 1098 | (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET, |
| 1099 | sizeof(sband->ht_cap.mcs), |
| 1100 | &sband->ht_cap.mcs) || |
| 1101 | nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA, |
| 1102 | sband->ht_cap.cap) || |
| 1103 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, |
| 1104 | sband->ht_cap.ampdu_factor) || |
| 1105 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, |
| 1106 | sband->ht_cap.ampdu_density))) |
| 1107 | return -ENOBUFS; |
| 1108 | |
| 1109 | /* add VHT info */ |
| 1110 | if (sband->vht_cap.vht_supported && |
| 1111 | (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET, |
| 1112 | sizeof(sband->vht_cap.vht_mcs), |
| 1113 | &sband->vht_cap.vht_mcs) || |
| 1114 | nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA, |
| 1115 | sband->vht_cap.cap))) |
| 1116 | return -ENOBUFS; |
| 1117 | |
| 1118 | /* add bitrates */ |
| 1119 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); |
| 1120 | if (!nl_rates) |
| 1121 | return -ENOBUFS; |
| 1122 | |
| 1123 | for (i = 0; i < sband->n_bitrates; i++) { |
| 1124 | nl_rate = nla_nest_start(msg, i); |
| 1125 | if (!nl_rate) |
| 1126 | return -ENOBUFS; |
| 1127 | |
| 1128 | rate = &sband->bitrates[i]; |
| 1129 | if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE, |
| 1130 | rate->bitrate)) |
| 1131 | return -ENOBUFS; |
| 1132 | if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) && |
| 1133 | nla_put_flag(msg, |
| 1134 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE)) |
| 1135 | return -ENOBUFS; |
| 1136 | |
| 1137 | nla_nest_end(msg, nl_rate); |
| 1138 | } |
| 1139 | |
| 1140 | nla_nest_end(msg, nl_rates); |
| 1141 | |
| 1142 | return 0; |
| 1143 | } |
| 1144 | |
| 1145 | static int |
| 1146 | nl80211_send_mgmt_stypes(struct sk_buff *msg, |
| 1147 | const struct ieee80211_txrx_stypes *mgmt_stypes) |
| 1148 | { |
| 1149 | u16 stypes; |
| 1150 | struct nlattr *nl_ftypes, *nl_ifs; |
| 1151 | enum nl80211_iftype ift; |
| 1152 | int i; |
| 1153 | |
| 1154 | if (!mgmt_stypes) |
| 1155 | return 0; |
| 1156 | |
| 1157 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES); |
| 1158 | if (!nl_ifs) |
| 1159 | return -ENOBUFS; |
| 1160 | |
| 1161 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 1162 | nl_ftypes = nla_nest_start(msg, ift); |
| 1163 | if (!nl_ftypes) |
| 1164 | return -ENOBUFS; |
| 1165 | i = 0; |
| 1166 | stypes = mgmt_stypes[ift].tx; |
| 1167 | while (stypes) { |
| 1168 | if ((stypes & 1) && |
| 1169 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1170 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1171 | return -ENOBUFS; |
| 1172 | stypes >>= 1; |
| 1173 | i++; |
| 1174 | } |
| 1175 | nla_nest_end(msg, nl_ftypes); |
| 1176 | } |
| 1177 | |
| 1178 | nla_nest_end(msg, nl_ifs); |
| 1179 | |
| 1180 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES); |
| 1181 | if (!nl_ifs) |
| 1182 | return -ENOBUFS; |
| 1183 | |
| 1184 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 1185 | nl_ftypes = nla_nest_start(msg, ift); |
| 1186 | if (!nl_ftypes) |
| 1187 | return -ENOBUFS; |
| 1188 | i = 0; |
| 1189 | stypes = mgmt_stypes[ift].rx; |
| 1190 | while (stypes) { |
| 1191 | if ((stypes & 1) && |
| 1192 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1193 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1194 | return -ENOBUFS; |
| 1195 | stypes >>= 1; |
| 1196 | i++; |
| 1197 | } |
| 1198 | nla_nest_end(msg, nl_ftypes); |
| 1199 | } |
| 1200 | nla_nest_end(msg, nl_ifs); |
| 1201 | |
| 1202 | return 0; |
| 1203 | } |
| 1204 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1205 | struct nl80211_dump_wiphy_state { |
| 1206 | s64 filter_wiphy; |
| 1207 | long start; |
| 1208 | long split_start, band_start, chan_start; |
| 1209 | bool split; |
| 1210 | }; |
| 1211 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1212 | static int nl80211_send_wiphy(struct cfg80211_registered_device *dev, |
| 1213 | struct sk_buff *msg, u32 portid, u32 seq, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1214 | int flags, struct nl80211_dump_wiphy_state *state) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1215 | { |
| 1216 | void *hdr; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1217 | struct nlattr *nl_bands, *nl_band; |
| 1218 | struct nlattr *nl_freqs, *nl_freq; |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1219 | struct nlattr *nl_cmds; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1220 | enum ieee80211_band band; |
| 1221 | struct ieee80211_channel *chan; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1222 | int i; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1223 | const struct ieee80211_txrx_stypes *mgmt_stypes = |
| 1224 | dev->wiphy.mgmt_stypes; |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1225 | u32 features; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1226 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 1227 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_WIPHY); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1228 | if (!hdr) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1229 | return -ENOBUFS; |
| 1230 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1231 | if (WARN_ON(!state)) |
| 1232 | return -EINVAL; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1233 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1234 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1235 | nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, |
| 1236 | wiphy_name(&dev->wiphy)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1237 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1238 | cfg80211_rdev_list_generation)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1239 | goto nla_put_failure; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1240 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1241 | switch (state->split_start) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1242 | case 0: |
| 1243 | if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, |
| 1244 | dev->wiphy.retry_short) || |
| 1245 | nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, |
| 1246 | dev->wiphy.retry_long) || |
| 1247 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, |
| 1248 | dev->wiphy.frag_threshold) || |
| 1249 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, |
| 1250 | dev->wiphy.rts_threshold) || |
| 1251 | nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, |
| 1252 | dev->wiphy.coverage_class) || |
| 1253 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, |
| 1254 | dev->wiphy.max_scan_ssids) || |
| 1255 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, |
| 1256 | dev->wiphy.max_sched_scan_ssids) || |
| 1257 | nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, |
| 1258 | dev->wiphy.max_scan_ie_len) || |
| 1259 | nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, |
| 1260 | dev->wiphy.max_sched_scan_ie_len) || |
| 1261 | nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS, |
| 1262 | dev->wiphy.max_match_sets)) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1263 | goto nla_put_failure; |
| 1264 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1265 | if ((dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) && |
| 1266 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN)) |
| 1267 | goto nla_put_failure; |
| 1268 | if ((dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) && |
| 1269 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH)) |
| 1270 | goto nla_put_failure; |
| 1271 | if ((dev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && |
| 1272 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD)) |
| 1273 | goto nla_put_failure; |
| 1274 | if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) && |
| 1275 | nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT)) |
| 1276 | goto nla_put_failure; |
| 1277 | if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) && |
| 1278 | nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT)) |
| 1279 | goto nla_put_failure; |
| 1280 | if ((dev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) && |
| 1281 | nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1282 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1283 | state->split_start++; |
| 1284 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1285 | break; |
| 1286 | case 1: |
| 1287 | if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES, |
| 1288 | sizeof(u32) * dev->wiphy.n_cipher_suites, |
| 1289 | dev->wiphy.cipher_suites)) |
Mahesh Palivela | bf0c111e | 2012-06-22 07:27:46 +0000 | [diff] [blame] | 1290 | goto nla_put_failure; |
| 1291 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1292 | if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, |
| 1293 | dev->wiphy.max_num_pmkids)) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1294 | goto nla_put_failure; |
| 1295 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1296 | if ((dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 1297 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE)) |
| 1298 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1299 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1300 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, |
| 1301 | dev->wiphy.available_antennas_tx) || |
| 1302 | nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, |
| 1303 | dev->wiphy.available_antennas_rx)) |
| 1304 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1305 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1306 | if ((dev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) && |
| 1307 | nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD, |
| 1308 | dev->wiphy.probe_resp_offload)) |
| 1309 | goto nla_put_failure; |
Jouni Malinen | e2f367f26 | 2008-11-21 19:01:30 +0200 | [diff] [blame] | 1310 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1311 | if ((dev->wiphy.available_antennas_tx || |
| 1312 | dev->wiphy.available_antennas_rx) && |
| 1313 | dev->ops->get_antenna) { |
| 1314 | u32 tx_ant = 0, rx_ant = 0; |
| 1315 | int res; |
| 1316 | res = rdev_get_antenna(dev, &tx_ant, &rx_ant); |
| 1317 | if (!res) { |
| 1318 | if (nla_put_u32(msg, |
| 1319 | NL80211_ATTR_WIPHY_ANTENNA_TX, |
| 1320 | tx_ant) || |
| 1321 | nla_put_u32(msg, |
| 1322 | NL80211_ATTR_WIPHY_ANTENNA_RX, |
| 1323 | rx_ant)) |
| 1324 | goto nla_put_failure; |
| 1325 | } |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1326 | } |
| 1327 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1328 | state->split_start++; |
| 1329 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1330 | break; |
| 1331 | case 2: |
| 1332 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, |
| 1333 | dev->wiphy.interface_modes)) |
| 1334 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1335 | state->split_start++; |
| 1336 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1337 | break; |
| 1338 | case 3: |
| 1339 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); |
| 1340 | if (!nl_bands) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1341 | goto nla_put_failure; |
| 1342 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1343 | for (band = state->band_start; |
| 1344 | band < IEEE80211_NUM_BANDS; band++) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1345 | struct ieee80211_supported_band *sband; |
| 1346 | |
| 1347 | sband = dev->wiphy.bands[band]; |
| 1348 | |
| 1349 | if (!sband) |
| 1350 | continue; |
| 1351 | |
| 1352 | nl_band = nla_nest_start(msg, band); |
| 1353 | if (!nl_band) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1354 | goto nla_put_failure; |
| 1355 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1356 | switch (state->chan_start) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1357 | case 0: |
| 1358 | if (nl80211_send_band_rateinfo(msg, sband)) |
| 1359 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1360 | state->chan_start++; |
| 1361 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1362 | break; |
| 1363 | default: |
| 1364 | /* add frequencies */ |
| 1365 | nl_freqs = nla_nest_start( |
| 1366 | msg, NL80211_BAND_ATTR_FREQS); |
| 1367 | if (!nl_freqs) |
| 1368 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1369 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1370 | for (i = state->chan_start - 1; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1371 | i < sband->n_channels; |
| 1372 | i++) { |
| 1373 | nl_freq = nla_nest_start(msg, i); |
| 1374 | if (!nl_freq) |
| 1375 | goto nla_put_failure; |
| 1376 | |
| 1377 | chan = &sband->channels[i]; |
| 1378 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1379 | if (nl80211_msg_put_channel( |
| 1380 | msg, chan, |
| 1381 | state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1382 | goto nla_put_failure; |
| 1383 | |
| 1384 | nla_nest_end(msg, nl_freq); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1385 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1386 | break; |
| 1387 | } |
| 1388 | if (i < sband->n_channels) |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1389 | state->chan_start = i + 2; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1390 | else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1391 | state->chan_start = 0; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1392 | nla_nest_end(msg, nl_freqs); |
| 1393 | } |
| 1394 | |
| 1395 | nla_nest_end(msg, nl_band); |
| 1396 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1397 | if (state->split) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1398 | /* start again here */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1399 | if (state->chan_start) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1400 | band--; |
| 1401 | break; |
| 1402 | } |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1403 | } |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1404 | nla_nest_end(msg, nl_bands); |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1405 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1406 | if (band < IEEE80211_NUM_BANDS) |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1407 | state->band_start = band + 1; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1408 | else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1409 | state->band_start = 0; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1410 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1411 | /* if bands & channels are done, continue outside */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1412 | if (state->band_start == 0 && state->chan_start == 0) |
| 1413 | state->split_start++; |
| 1414 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1415 | break; |
| 1416 | case 4: |
| 1417 | nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); |
| 1418 | if (!nl_cmds) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1419 | goto nla_put_failure; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1420 | |
| 1421 | i = 0; |
| 1422 | #define CMD(op, n) \ |
| 1423 | do { \ |
| 1424 | if (dev->ops->op) { \ |
| 1425 | i++; \ |
| 1426 | if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \ |
| 1427 | goto nla_put_failure; \ |
| 1428 | } \ |
| 1429 | } while (0) |
| 1430 | |
| 1431 | CMD(add_virtual_intf, NEW_INTERFACE); |
| 1432 | CMD(change_virtual_intf, SET_INTERFACE); |
| 1433 | CMD(add_key, NEW_KEY); |
| 1434 | CMD(start_ap, START_AP); |
| 1435 | CMD(add_station, NEW_STATION); |
| 1436 | CMD(add_mpath, NEW_MPATH); |
| 1437 | CMD(update_mesh_config, SET_MESH_CONFIG); |
| 1438 | CMD(change_bss, SET_BSS); |
| 1439 | CMD(auth, AUTHENTICATE); |
| 1440 | CMD(assoc, ASSOCIATE); |
| 1441 | CMD(deauth, DEAUTHENTICATE); |
| 1442 | CMD(disassoc, DISASSOCIATE); |
| 1443 | CMD(join_ibss, JOIN_IBSS); |
| 1444 | CMD(join_mesh, JOIN_MESH); |
| 1445 | CMD(set_pmksa, SET_PMKSA); |
| 1446 | CMD(del_pmksa, DEL_PMKSA); |
| 1447 | CMD(flush_pmksa, FLUSH_PMKSA); |
| 1448 | if (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) |
| 1449 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); |
| 1450 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); |
| 1451 | CMD(mgmt_tx, FRAME); |
| 1452 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); |
| 1453 | if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { |
| 1454 | i++; |
| 1455 | if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS)) |
| 1456 | goto nla_put_failure; |
| 1457 | } |
| 1458 | if (dev->ops->set_monitor_channel || dev->ops->start_ap || |
| 1459 | dev->ops->join_mesh) { |
| 1460 | i++; |
| 1461 | if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL)) |
| 1462 | goto nla_put_failure; |
| 1463 | } |
| 1464 | CMD(set_wds_peer, SET_WDS_PEER); |
| 1465 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) { |
| 1466 | CMD(tdls_mgmt, TDLS_MGMT); |
| 1467 | CMD(tdls_oper, TDLS_OPER); |
| 1468 | } |
| 1469 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) |
| 1470 | CMD(sched_scan_start, START_SCHED_SCAN); |
| 1471 | CMD(probe_client, PROBE_CLIENT); |
| 1472 | CMD(set_noack_map, SET_NOACK_MAP); |
| 1473 | if (dev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) { |
| 1474 | i++; |
| 1475 | if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS)) |
| 1476 | goto nla_put_failure; |
| 1477 | } |
| 1478 | CMD(start_p2p_device, START_P2P_DEVICE); |
| 1479 | CMD(set_mcast_rate, SET_MCAST_RATE); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1480 | if (state->split) { |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 1481 | CMD(crit_proto_start, CRIT_PROTOCOL_START); |
| 1482 | CMD(crit_proto_stop, CRIT_PROTOCOL_STOP); |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 1483 | if (dev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH) |
| 1484 | CMD(channel_switch, CHANNEL_SWITCH); |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 1485 | } |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 1486 | CMD(set_qos_map, SET_QOS_MAP); |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1487 | |
Kalle Valo | 4745fc0 | 2011-11-17 19:06:10 +0200 | [diff] [blame] | 1488 | #ifdef CONFIG_NL80211_TESTMODE |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1489 | CMD(testmode_cmd, TESTMODE); |
Kalle Valo | 4745fc0 | 2011-11-17 19:06:10 +0200 | [diff] [blame] | 1490 | #endif |
| 1491 | |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1492 | #undef CMD |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1493 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1494 | if (dev->ops->connect || dev->ops->auth) { |
| 1495 | i++; |
| 1496 | if (nla_put_u32(msg, i, NL80211_CMD_CONNECT)) |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1497 | goto nla_put_failure; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1498 | } |
| 1499 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1500 | if (dev->ops->disconnect || dev->ops->deauth) { |
| 1501 | i++; |
| 1502 | if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT)) |
| 1503 | goto nla_put_failure; |
| 1504 | } |
Johannes Berg | 74b70a4 | 2010-08-24 12:15:53 +0200 | [diff] [blame] | 1505 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1506 | nla_nest_end(msg, nl_cmds); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1507 | state->split_start++; |
| 1508 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1509 | break; |
| 1510 | case 5: |
| 1511 | if (dev->ops->remain_on_channel && |
| 1512 | (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) && |
| 1513 | nla_put_u32(msg, |
| 1514 | NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, |
| 1515 | dev->wiphy.max_remain_on_channel_duration)) |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1516 | goto nla_put_failure; |
| 1517 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1518 | if ((dev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) && |
| 1519 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) |
| 1520 | goto nla_put_failure; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1521 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1522 | if (nl80211_send_mgmt_stypes(msg, mgmt_stypes)) |
| 1523 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1524 | state->split_start++; |
| 1525 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1526 | break; |
| 1527 | case 6: |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 1528 | #ifdef CONFIG_PM |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1529 | if (nl80211_send_wowlan(msg, dev, state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1530 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1531 | state->split_start++; |
| 1532 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1533 | break; |
| 1534 | #else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1535 | state->split_start++; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1536 | #endif |
| 1537 | case 7: |
| 1538 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, |
| 1539 | dev->wiphy.software_iftypes)) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1540 | goto nla_put_failure; |
| 1541 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1542 | if (nl80211_put_iface_combinations(&dev->wiphy, msg, |
| 1543 | state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1544 | goto nla_put_failure; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1545 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1546 | state->split_start++; |
| 1547 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1548 | break; |
| 1549 | case 8: |
| 1550 | if ((dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) && |
| 1551 | nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME, |
| 1552 | dev->wiphy.ap_sme_capa)) |
| 1553 | goto nla_put_failure; |
| 1554 | |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1555 | features = dev->wiphy.features; |
| 1556 | /* |
| 1557 | * We can only add the per-channel limit information if the |
| 1558 | * dump is split, otherwise it makes it too big. Therefore |
| 1559 | * only advertise it in that case. |
| 1560 | */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1561 | if (state->split) |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1562 | features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS; |
| 1563 | if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1564 | goto nla_put_failure; |
| 1565 | |
| 1566 | if (dev->wiphy.ht_capa_mod_mask && |
| 1567 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, |
| 1568 | sizeof(*dev->wiphy.ht_capa_mod_mask), |
| 1569 | dev->wiphy.ht_capa_mod_mask)) |
| 1570 | goto nla_put_failure; |
| 1571 | |
| 1572 | if (dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME && |
| 1573 | dev->wiphy.max_acl_mac_addrs && |
| 1574 | nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX, |
| 1575 | dev->wiphy.max_acl_mac_addrs)) |
| 1576 | goto nla_put_failure; |
| 1577 | |
| 1578 | /* |
| 1579 | * Any information below this point is only available to |
| 1580 | * applications that can deal with it being split. This |
| 1581 | * helps ensure that newly added capabilities don't break |
| 1582 | * older tools by overrunning their buffers. |
| 1583 | * |
| 1584 | * We still increment split_start so that in the split |
| 1585 | * case we'll continue with more data in the next round, |
| 1586 | * but break unconditionally so unsplit data stops here. |
| 1587 | */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1588 | state->split_start++; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1589 | break; |
| 1590 | case 9: |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1591 | if (dev->wiphy.extended_capabilities && |
| 1592 | (nla_put(msg, NL80211_ATTR_EXT_CAPA, |
| 1593 | dev->wiphy.extended_capabilities_len, |
| 1594 | dev->wiphy.extended_capabilities) || |
| 1595 | nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, |
| 1596 | dev->wiphy.extended_capabilities_len, |
| 1597 | dev->wiphy.extended_capabilities_mask))) |
| 1598 | goto nla_put_failure; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1599 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 1600 | if (dev->wiphy.vht_capa_mod_mask && |
| 1601 | nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, |
| 1602 | sizeof(*dev->wiphy.vht_capa_mod_mask), |
| 1603 | dev->wiphy.vht_capa_mod_mask)) |
| 1604 | goto nla_put_failure; |
| 1605 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1606 | state->split_start++; |
| 1607 | break; |
| 1608 | case 10: |
| 1609 | if (nl80211_send_coalesce(msg, dev)) |
| 1610 | goto nla_put_failure; |
| 1611 | |
Felix Fietkau | 01e0daa | 2013-11-09 14:57:54 +0100 | [diff] [blame] | 1612 | if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) && |
| 1613 | (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) || |
| 1614 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ))) |
| 1615 | goto nla_put_failure; |
Jouni Malinen | b43504c | 2014-01-15 00:01:08 +0200 | [diff] [blame] | 1616 | |
| 1617 | if (dev->wiphy.max_ap_assoc_sta && |
| 1618 | nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA, |
| 1619 | dev->wiphy.max_ap_assoc_sta)) |
| 1620 | goto nla_put_failure; |
| 1621 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 1622 | state->split_start++; |
| 1623 | break; |
| 1624 | case 11: |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1625 | if (dev->wiphy.n_vendor_commands) { |
| 1626 | const struct nl80211_vendor_cmd_info *info; |
| 1627 | struct nlattr *nested; |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 1628 | |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1629 | nested = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); |
| 1630 | if (!nested) |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 1631 | goto nla_put_failure; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1632 | |
| 1633 | for (i = 0; i < dev->wiphy.n_vendor_commands; i++) { |
| 1634 | info = &dev->wiphy.vendor_commands[i].info; |
| 1635 | if (nla_put(msg, i + 1, sizeof(*info), info)) |
| 1636 | goto nla_put_failure; |
| 1637 | } |
| 1638 | nla_nest_end(msg, nested); |
| 1639 | } |
| 1640 | |
| 1641 | if (dev->wiphy.n_vendor_events) { |
| 1642 | const struct nl80211_vendor_cmd_info *info; |
| 1643 | struct nlattr *nested; |
| 1644 | |
| 1645 | nested = nla_nest_start(msg, |
| 1646 | NL80211_ATTR_VENDOR_EVENTS); |
| 1647 | if (!nested) |
| 1648 | goto nla_put_failure; |
| 1649 | |
| 1650 | for (i = 0; i < dev->wiphy.n_vendor_events; i++) { |
| 1651 | info = &dev->wiphy.vendor_events[i]; |
| 1652 | if (nla_put(msg, i + 1, sizeof(*info), info)) |
| 1653 | goto nla_put_failure; |
| 1654 | } |
| 1655 | nla_nest_end(msg, nested); |
| 1656 | } |
Felix Fietkau | 01e0daa | 2013-11-09 14:57:54 +0100 | [diff] [blame] | 1657 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1658 | /* done */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1659 | state->split_start = 0; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1660 | break; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1661 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1662 | return genlmsg_end(msg, hdr); |
| 1663 | |
| 1664 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 1665 | genlmsg_cancel(msg, hdr); |
| 1666 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1667 | } |
| 1668 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1669 | static int nl80211_dump_wiphy_parse(struct sk_buff *skb, |
| 1670 | struct netlink_callback *cb, |
| 1671 | struct nl80211_dump_wiphy_state *state) |
| 1672 | { |
| 1673 | struct nlattr **tb = nl80211_fam.attrbuf; |
| 1674 | int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 1675 | tb, nl80211_fam.maxattr, nl80211_policy); |
| 1676 | /* ignore parse errors for backward compatibility */ |
| 1677 | if (ret) |
| 1678 | return 0; |
| 1679 | |
| 1680 | state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP]; |
| 1681 | if (tb[NL80211_ATTR_WIPHY]) |
| 1682 | state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]); |
| 1683 | if (tb[NL80211_ATTR_WDEV]) |
| 1684 | state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32; |
| 1685 | if (tb[NL80211_ATTR_IFINDEX]) { |
| 1686 | struct net_device *netdev; |
| 1687 | struct cfg80211_registered_device *rdev; |
| 1688 | int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); |
| 1689 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 1690 | netdev = __dev_get_by_index(sock_net(skb->sk), ifidx); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1691 | if (!netdev) |
| 1692 | return -ENODEV; |
| 1693 | if (netdev->ieee80211_ptr) { |
| 1694 | rdev = wiphy_to_dev( |
| 1695 | netdev->ieee80211_ptr->wiphy); |
| 1696 | state->filter_wiphy = rdev->wiphy_idx; |
| 1697 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1698 | } |
| 1699 | |
| 1700 | return 0; |
| 1701 | } |
| 1702 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1703 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) |
| 1704 | { |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1705 | int idx = 0, ret; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1706 | struct nl80211_dump_wiphy_state *state = (void *)cb->args[0]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1707 | struct cfg80211_registered_device *dev; |
Johannes Berg | 3a5a423 | 2013-06-19 10:09:57 +0200 | [diff] [blame] | 1708 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1709 | rtnl_lock(); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1710 | if (!state) { |
| 1711 | state = kzalloc(sizeof(*state), GFP_KERNEL); |
John W. Linville | 57ed5cd | 2013-06-28 13:18:21 -0400 | [diff] [blame] | 1712 | if (!state) { |
| 1713 | rtnl_unlock(); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1714 | return -ENOMEM; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1715 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1716 | state->filter_wiphy = -1; |
| 1717 | ret = nl80211_dump_wiphy_parse(skb, cb, state); |
| 1718 | if (ret) { |
| 1719 | kfree(state); |
| 1720 | rtnl_unlock(); |
| 1721 | return ret; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1722 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1723 | cb->args[0] = (long)state; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1724 | } |
| 1725 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1726 | list_for_each_entry(dev, &cfg80211_rdev_list, list) { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1727 | if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk))) |
| 1728 | continue; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1729 | if (++idx <= state->start) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1730 | continue; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1731 | if (state->filter_wiphy != -1 && |
| 1732 | state->filter_wiphy != dev->wiphy_idx) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1733 | continue; |
| 1734 | /* attempt to fit multiple wiphy data chunks into the skb */ |
| 1735 | do { |
| 1736 | ret = nl80211_send_wiphy(dev, skb, |
| 1737 | NETLINK_CB(cb->skb).portid, |
| 1738 | cb->nlh->nlmsg_seq, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1739 | NLM_F_MULTI, state); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1740 | if (ret < 0) { |
| 1741 | /* |
| 1742 | * If sending the wiphy data didn't fit (ENOBUFS |
| 1743 | * or EMSGSIZE returned), this SKB is still |
| 1744 | * empty (so it's not too big because another |
| 1745 | * wiphy dataset is already in the skb) and |
| 1746 | * we've not tried to adjust the dump allocation |
| 1747 | * yet ... then adjust the alloc size to be |
| 1748 | * bigger, and return 1 but with the empty skb. |
| 1749 | * This results in an empty message being RX'ed |
| 1750 | * in userspace, but that is ignored. |
| 1751 | * |
| 1752 | * We can then retry with the larger buffer. |
| 1753 | */ |
| 1754 | if ((ret == -ENOBUFS || ret == -EMSGSIZE) && |
Pontus Fuchs | f12cb28 | 2014-01-16 15:00:40 +0100 | [diff] [blame] | 1755 | !skb->len && !state->split && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1756 | cb->min_dump_alloc < 4096) { |
| 1757 | cb->min_dump_alloc = 4096; |
Pontus Fuchs | f12cb28 | 2014-01-16 15:00:40 +0100 | [diff] [blame] | 1758 | state->split_start = 0; |
David S. Miller | d98cae64e | 2013-06-19 16:49:39 -0700 | [diff] [blame] | 1759 | rtnl_unlock(); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1760 | return 1; |
| 1761 | } |
| 1762 | idx--; |
| 1763 | break; |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1764 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1765 | } while (state->split_start > 0); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1766 | break; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1767 | } |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1768 | rtnl_unlock(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1769 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1770 | state->start = idx; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1771 | |
| 1772 | return skb->len; |
| 1773 | } |
| 1774 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1775 | static int nl80211_dump_wiphy_done(struct netlink_callback *cb) |
| 1776 | { |
| 1777 | kfree((void *)cb->args[0]); |
| 1778 | return 0; |
| 1779 | } |
| 1780 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1781 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1782 | { |
| 1783 | struct sk_buff *msg; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1784 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1785 | struct nl80211_dump_wiphy_state state = {}; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1786 | |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1787 | msg = nlmsg_new(4096, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1788 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1789 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1790 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1791 | 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] | 1792 | &state) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1793 | nlmsg_free(msg); |
| 1794 | return -ENOBUFS; |
| 1795 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1796 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 1797 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1798 | } |
| 1799 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1800 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
| 1801 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, |
| 1802 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, |
| 1803 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, |
| 1804 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, |
| 1805 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, |
| 1806 | }; |
| 1807 | |
| 1808 | static int parse_txq_params(struct nlattr *tb[], |
| 1809 | struct ieee80211_txq_params *txq_params) |
| 1810 | { |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1811 | if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] || |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1812 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
| 1813 | !tb[NL80211_TXQ_ATTR_AIFS]) |
| 1814 | return -EINVAL; |
| 1815 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1816 | txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1817 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
| 1818 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); |
| 1819 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); |
| 1820 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); |
| 1821 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1822 | if (txq_params->ac >= NL80211_NUM_ACS) |
| 1823 | return -EINVAL; |
| 1824 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1825 | return 0; |
| 1826 | } |
| 1827 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1828 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
| 1829 | { |
| 1830 | /* |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1831 | * You can only set the channel explicitly for WDS interfaces, |
| 1832 | * all others have their channel managed via their respective |
| 1833 | * "establish a connection" command (connect, join, ...) |
| 1834 | * |
| 1835 | * For AP/GO and mesh mode, the channel can be set with the |
| 1836 | * channel userspace API, but is only stored and passed to the |
| 1837 | * low-level driver when the AP starts or the mesh is joined. |
| 1838 | * This is for backward compatibility, userspace can also give |
| 1839 | * the channel in the start-ap or join-mesh commands instead. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1840 | * |
| 1841 | * Monitors are special as they are normally slaved to |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1842 | * whatever else is going on, so they have their own special |
| 1843 | * operation to set the monitor channel if possible. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1844 | */ |
| 1845 | return !wdev || |
| 1846 | wdev->iftype == NL80211_IFTYPE_AP || |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1847 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 1848 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
| 1849 | wdev->iftype == NL80211_IFTYPE_P2P_GO; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1850 | } |
| 1851 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1852 | static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev, |
| 1853 | struct genl_info *info, |
| 1854 | struct cfg80211_chan_def *chandef) |
| 1855 | { |
Mahesh Palivela | dbeca2e | 2012-11-29 14:11:07 +0530 | [diff] [blame] | 1856 | u32 control_freq; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1857 | |
| 1858 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 1859 | return -EINVAL; |
| 1860 | |
| 1861 | control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 1862 | |
| 1863 | chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1864 | chandef->width = NL80211_CHAN_WIDTH_20_NOHT; |
| 1865 | chandef->center_freq1 = control_freq; |
| 1866 | chandef->center_freq2 = 0; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1867 | |
| 1868 | /* Primary channel not allowed */ |
| 1869 | if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) |
| 1870 | return -EINVAL; |
| 1871 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1872 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 1873 | enum nl80211_channel_type chantype; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1874 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1875 | chantype = nla_get_u32( |
| 1876 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 1877 | |
| 1878 | switch (chantype) { |
| 1879 | case NL80211_CHAN_NO_HT: |
| 1880 | case NL80211_CHAN_HT20: |
| 1881 | case NL80211_CHAN_HT40PLUS: |
| 1882 | case NL80211_CHAN_HT40MINUS: |
| 1883 | cfg80211_chandef_create(chandef, chandef->chan, |
| 1884 | chantype); |
| 1885 | break; |
| 1886 | default: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1887 | return -EINVAL; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1888 | } |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1889 | } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) { |
| 1890 | chandef->width = |
| 1891 | nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]); |
| 1892 | if (info->attrs[NL80211_ATTR_CENTER_FREQ1]) |
| 1893 | chandef->center_freq1 = |
| 1894 | nla_get_u32( |
| 1895 | info->attrs[NL80211_ATTR_CENTER_FREQ1]); |
| 1896 | if (info->attrs[NL80211_ATTR_CENTER_FREQ2]) |
| 1897 | chandef->center_freq2 = |
| 1898 | nla_get_u32( |
| 1899 | info->attrs[NL80211_ATTR_CENTER_FREQ2]); |
| 1900 | } |
| 1901 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 1902 | if (!cfg80211_chandef_valid(chandef)) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1903 | return -EINVAL; |
| 1904 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 1905 | if (!cfg80211_chandef_usable(&rdev->wiphy, chandef, |
| 1906 | IEEE80211_CHAN_DISABLED)) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1907 | return -EINVAL; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1908 | |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 1909 | if ((chandef->width == NL80211_CHAN_WIDTH_5 || |
| 1910 | chandef->width == NL80211_CHAN_WIDTH_10) && |
| 1911 | !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ)) |
| 1912 | return -EINVAL; |
| 1913 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1914 | return 0; |
| 1915 | } |
| 1916 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1917 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
| 1918 | struct wireless_dev *wdev, |
| 1919 | struct genl_info *info) |
| 1920 | { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1921 | struct cfg80211_chan_def chandef; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1922 | int result; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1923 | enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR; |
| 1924 | |
| 1925 | if (wdev) |
| 1926 | iftype = wdev->iftype; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1927 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1928 | if (!nl80211_can_set_dev_channel(wdev)) |
| 1929 | return -EOPNOTSUPP; |
| 1930 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1931 | result = nl80211_parse_chandef(rdev, info, &chandef); |
| 1932 | if (result) |
| 1933 | return result; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1934 | |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1935 | switch (iftype) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1936 | case NL80211_IFTYPE_AP: |
| 1937 | case NL80211_IFTYPE_P2P_GO: |
| 1938 | if (wdev->beacon_interval) { |
| 1939 | result = -EBUSY; |
| 1940 | break; |
| 1941 | } |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1942 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef)) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1943 | result = -EINVAL; |
| 1944 | break; |
| 1945 | } |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1946 | wdev->preset_chandef = chandef; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1947 | result = 0; |
| 1948 | break; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1949 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1950 | result = cfg80211_set_mesh_channel(rdev, wdev, &chandef); |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1951 | break; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1952 | case NL80211_IFTYPE_MONITOR: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1953 | result = cfg80211_set_monitor_channel(rdev, &chandef); |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1954 | break; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1955 | default: |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1956 | result = -EINVAL; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1957 | } |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1958 | |
| 1959 | return result; |
| 1960 | } |
| 1961 | |
| 1962 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) |
| 1963 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1964 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1965 | struct net_device *netdev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1966 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1967 | return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1968 | } |
| 1969 | |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1970 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
| 1971 | { |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1972 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1973 | struct net_device *dev = info->user_ptr[1]; |
| 1974 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 388ac77 | 2010-10-07 13:11:09 +0200 | [diff] [blame] | 1975 | const u8 *bssid; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1976 | |
| 1977 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 1978 | return -EINVAL; |
| 1979 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1980 | if (netif_running(dev)) |
| 1981 | return -EBUSY; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1982 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1983 | if (!rdev->ops->set_wds_peer) |
| 1984 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1985 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1986 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
| 1987 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1988 | |
| 1989 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 1990 | return rdev_set_wds_peer(rdev, dev, bssid); |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1991 | } |
| 1992 | |
| 1993 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1994 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1995 | { |
| 1996 | struct cfg80211_registered_device *rdev; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1997 | struct net_device *netdev = NULL; |
| 1998 | struct wireless_dev *wdev; |
Bill Jordan | a1e567c | 2010-09-10 11:22:32 -0400 | [diff] [blame] | 1999 | int result = 0, rem_txq_params = 0; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2000 | struct nlattr *nl_txq_params; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2001 | u32 changed; |
| 2002 | u8 retry_short = 0, retry_long = 0; |
| 2003 | u32 frag_threshold = 0, rts_threshold = 0; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2004 | u8 coverage_class = 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2005 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2006 | ASSERT_RTNL(); |
| 2007 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2008 | /* |
| 2009 | * Try to find the wiphy and netdev. Normally this |
| 2010 | * function shouldn't need the netdev, but this is |
| 2011 | * done for backward compatibility -- previously |
| 2012 | * setting the channel was done per wiphy, but now |
| 2013 | * it is per netdev. Previous userland like hostapd |
| 2014 | * also passed a netdev to set_wiphy, so that it is |
| 2015 | * possible to let that go to the right netdev! |
| 2016 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2017 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2018 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
| 2019 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); |
| 2020 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2021 | netdev = __dev_get_by_index(genl_info_net(info), ifindex); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2022 | if (netdev && netdev->ieee80211_ptr) |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2023 | rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2024 | else |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2025 | netdev = NULL; |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2026 | } |
| 2027 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2028 | if (!netdev) { |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 2029 | rdev = __cfg80211_rdev_from_attrs(genl_info_net(info), |
| 2030 | info->attrs); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2031 | if (IS_ERR(rdev)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2032 | return PTR_ERR(rdev); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2033 | wdev = NULL; |
| 2034 | netdev = NULL; |
| 2035 | result = 0; |
Johannes Berg | 71fe96b | 2012-10-24 10:04:58 +0200 | [diff] [blame] | 2036 | } else |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2037 | wdev = netdev->ieee80211_ptr; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2038 | |
| 2039 | /* |
| 2040 | * end workaround code, by now the rdev is available |
| 2041 | * and locked, and wdev may or may not be NULL. |
| 2042 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2043 | |
| 2044 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2045 | result = cfg80211_dev_rename( |
| 2046 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2047 | |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2048 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2049 | return result; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2050 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2051 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { |
| 2052 | struct ieee80211_txq_params txq_params; |
| 2053 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; |
| 2054 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2055 | if (!rdev->ops->set_txq_params) |
| 2056 | return -EOPNOTSUPP; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2057 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2058 | if (!netdev) |
| 2059 | return -EINVAL; |
Eliad Peller | f70f01c | 2011-09-25 20:06:53 +0300 | [diff] [blame] | 2060 | |
Johannes Berg | 133a3ff | 2011-11-03 14:50:13 +0100 | [diff] [blame] | 2061 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2062 | netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2063 | return -EINVAL; |
Johannes Berg | 133a3ff | 2011-11-03 14:50:13 +0100 | [diff] [blame] | 2064 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2065 | if (!netif_running(netdev)) |
| 2066 | return -ENETDOWN; |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 2067 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2068 | nla_for_each_nested(nl_txq_params, |
| 2069 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], |
| 2070 | rem_txq_params) { |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 2071 | result = nla_parse(tb, NL80211_TXQ_ATTR_MAX, |
| 2072 | nla_data(nl_txq_params), |
| 2073 | nla_len(nl_txq_params), |
| 2074 | txq_params_policy); |
| 2075 | if (result) |
| 2076 | return result; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2077 | result = parse_txq_params(tb, &txq_params); |
| 2078 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2079 | return result; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2080 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2081 | result = rdev_set_txq_params(rdev, netdev, |
| 2082 | &txq_params); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2083 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2084 | return result; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2085 | } |
| 2086 | } |
| 2087 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2088 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 71fe96b | 2012-10-24 10:04:58 +0200 | [diff] [blame] | 2089 | result = __nl80211_set_channel(rdev, |
| 2090 | nl80211_can_set_dev_channel(wdev) ? wdev : NULL, |
| 2091 | info); |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2092 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2093 | return result; |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2094 | } |
| 2095 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2096 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2097 | struct wireless_dev *txp_wdev = wdev; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2098 | enum nl80211_tx_power_setting type; |
| 2099 | int idx, mbm = 0; |
| 2100 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2101 | if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER)) |
| 2102 | txp_wdev = NULL; |
| 2103 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2104 | if (!rdev->ops->set_tx_power) |
| 2105 | return -EOPNOTSUPP; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2106 | |
| 2107 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; |
| 2108 | type = nla_get_u32(info->attrs[idx]); |
| 2109 | |
| 2110 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2111 | (type != NL80211_TX_POWER_AUTOMATIC)) |
| 2112 | return -EINVAL; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2113 | |
| 2114 | if (type != NL80211_TX_POWER_AUTOMATIC) { |
| 2115 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; |
| 2116 | mbm = nla_get_u32(info->attrs[idx]); |
| 2117 | } |
| 2118 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2119 | result = rdev_set_tx_power(rdev, txp_wdev, type, mbm); |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2120 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2121 | return result; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2122 | } |
| 2123 | |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2124 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
| 2125 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { |
| 2126 | u32 tx_ant, rx_ant; |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2127 | if ((!rdev->wiphy.available_antennas_tx && |
| 2128 | !rdev->wiphy.available_antennas_rx) || |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2129 | !rdev->ops->set_antenna) |
| 2130 | return -EOPNOTSUPP; |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2131 | |
| 2132 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); |
| 2133 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); |
| 2134 | |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2135 | /* reject antenna configurations which don't match the |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2136 | * available antenna masks, except for the "all" mask */ |
| 2137 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2138 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) |
| 2139 | return -EINVAL; |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2140 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2141 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
| 2142 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2143 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2144 | result = rdev_set_antenna(rdev, tx_ant, rx_ant); |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2145 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2146 | return result; |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2147 | } |
| 2148 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2149 | changed = 0; |
| 2150 | |
| 2151 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { |
| 2152 | retry_short = nla_get_u8( |
| 2153 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2154 | if (retry_short == 0) |
| 2155 | return -EINVAL; |
| 2156 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2157 | changed |= WIPHY_PARAM_RETRY_SHORT; |
| 2158 | } |
| 2159 | |
| 2160 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { |
| 2161 | retry_long = nla_get_u8( |
| 2162 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2163 | if (retry_long == 0) |
| 2164 | return -EINVAL; |
| 2165 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2166 | changed |= WIPHY_PARAM_RETRY_LONG; |
| 2167 | } |
| 2168 | |
| 2169 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { |
| 2170 | frag_threshold = nla_get_u32( |
| 2171 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2172 | if (frag_threshold < 256) |
| 2173 | return -EINVAL; |
| 2174 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2175 | if (frag_threshold != (u32) -1) { |
| 2176 | /* |
| 2177 | * Fragments (apart from the last one) are required to |
| 2178 | * have even length. Make the fragmentation code |
| 2179 | * simpler by stripping LSB should someone try to use |
| 2180 | * odd threshold value. |
| 2181 | */ |
| 2182 | frag_threshold &= ~0x1; |
| 2183 | } |
| 2184 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; |
| 2185 | } |
| 2186 | |
| 2187 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { |
| 2188 | rts_threshold = nla_get_u32( |
| 2189 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); |
| 2190 | changed |= WIPHY_PARAM_RTS_THRESHOLD; |
| 2191 | } |
| 2192 | |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2193 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
| 2194 | coverage_class = nla_get_u8( |
| 2195 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); |
| 2196 | changed |= WIPHY_PARAM_COVERAGE_CLASS; |
| 2197 | } |
| 2198 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2199 | if (changed) { |
| 2200 | u8 old_retry_short, old_retry_long; |
| 2201 | u32 old_frag_threshold, old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2202 | u8 old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2203 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2204 | if (!rdev->ops->set_wiphy_params) |
| 2205 | return -EOPNOTSUPP; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2206 | |
| 2207 | old_retry_short = rdev->wiphy.retry_short; |
| 2208 | old_retry_long = rdev->wiphy.retry_long; |
| 2209 | old_frag_threshold = rdev->wiphy.frag_threshold; |
| 2210 | old_rts_threshold = rdev->wiphy.rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2211 | old_coverage_class = rdev->wiphy.coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2212 | |
| 2213 | if (changed & WIPHY_PARAM_RETRY_SHORT) |
| 2214 | rdev->wiphy.retry_short = retry_short; |
| 2215 | if (changed & WIPHY_PARAM_RETRY_LONG) |
| 2216 | rdev->wiphy.retry_long = retry_long; |
| 2217 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) |
| 2218 | rdev->wiphy.frag_threshold = frag_threshold; |
| 2219 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) |
| 2220 | rdev->wiphy.rts_threshold = rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2221 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
| 2222 | rdev->wiphy.coverage_class = coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2223 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2224 | result = rdev_set_wiphy_params(rdev, changed); |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2225 | if (result) { |
| 2226 | rdev->wiphy.retry_short = old_retry_short; |
| 2227 | rdev->wiphy.retry_long = old_retry_long; |
| 2228 | rdev->wiphy.frag_threshold = old_frag_threshold; |
| 2229 | rdev->wiphy.rts_threshold = old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2230 | rdev->wiphy.coverage_class = old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2231 | } |
| 2232 | } |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2233 | return 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2234 | } |
| 2235 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 2236 | static inline u64 wdev_id(struct wireless_dev *wdev) |
| 2237 | { |
| 2238 | return (u64)wdev->identifier | |
| 2239 | ((u64)wiphy_to_dev(wdev->wiphy)->wiphy_idx << 32); |
| 2240 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2241 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2242 | static int nl80211_send_chandef(struct sk_buff *msg, |
Janusz Dziedzic | d2859df | 2013-11-06 13:55:51 +0100 | [diff] [blame] | 2243 | const struct cfg80211_chan_def *chandef) |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2244 | { |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 2245 | WARN_ON(!cfg80211_chandef_valid(chandef)); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2246 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2247 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
| 2248 | chandef->chan->center_freq)) |
| 2249 | return -ENOBUFS; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2250 | switch (chandef->width) { |
| 2251 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 2252 | case NL80211_CHAN_WIDTH_20: |
| 2253 | case NL80211_CHAN_WIDTH_40: |
| 2254 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 2255 | cfg80211_get_chandef_type(chandef))) |
| 2256 | return -ENOBUFS; |
| 2257 | break; |
| 2258 | default: |
| 2259 | break; |
| 2260 | } |
| 2261 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width)) |
| 2262 | return -ENOBUFS; |
| 2263 | if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1)) |
| 2264 | return -ENOBUFS; |
| 2265 | if (chandef->center_freq2 && |
| 2266 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2)) |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2267 | return -ENOBUFS; |
| 2268 | return 0; |
| 2269 | } |
| 2270 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2271 | 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] | 2272 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2273 | struct wireless_dev *wdev) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2274 | { |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2275 | struct net_device *dev = wdev->netdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2276 | void *hdr; |
| 2277 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2278 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_INTERFACE); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2279 | if (!hdr) |
| 2280 | return -1; |
| 2281 | |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2282 | if (dev && |
| 2283 | (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2284 | nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name))) |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2285 | goto nla_put_failure; |
| 2286 | |
| 2287 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 2288 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 2289 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2290 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2291 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
| 2292 | rdev->devlist_generation ^ |
| 2293 | (cfg80211_rdev_list_generation << 2))) |
| 2294 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2295 | |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 2296 | if (rdev->ops->get_channel) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2297 | int ret; |
| 2298 | struct cfg80211_chan_def chandef; |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 2299 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2300 | ret = rdev_get_channel(rdev, wdev, &chandef); |
| 2301 | if (ret == 0) { |
| 2302 | if (nl80211_send_chandef(msg, &chandef)) |
| 2303 | goto nla_put_failure; |
| 2304 | } |
Pontus Fuchs | d91df0e | 2012-04-03 16:39:58 +0200 | [diff] [blame] | 2305 | } |
| 2306 | |
Antonio Quartulli | b84e7a0 | 2012-11-07 12:52:20 +0100 | [diff] [blame] | 2307 | if (wdev->ssid_len) { |
| 2308 | if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid)) |
| 2309 | goto nla_put_failure; |
| 2310 | } |
| 2311 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2312 | return genlmsg_end(msg, hdr); |
| 2313 | |
| 2314 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 2315 | genlmsg_cancel(msg, hdr); |
| 2316 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2317 | } |
| 2318 | |
| 2319 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) |
| 2320 | { |
| 2321 | int wp_idx = 0; |
| 2322 | int if_idx = 0; |
| 2323 | int wp_start = cb->args[0]; |
| 2324 | int if_start = cb->args[1]; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2325 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2326 | struct wireless_dev *wdev; |
| 2327 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2328 | rtnl_lock(); |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2329 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 2330 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2331 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2332 | if (wp_idx < wp_start) { |
| 2333 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2334 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2335 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2336 | if_idx = 0; |
| 2337 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 2338 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2339 | if (if_idx < if_start) { |
| 2340 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2341 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2342 | } |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2343 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2344 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2345 | rdev, wdev) < 0) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2346 | goto out; |
| 2347 | } |
| 2348 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2349 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2350 | |
| 2351 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2352 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2353 | out: |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2354 | rtnl_unlock(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2355 | |
| 2356 | cb->args[0] = wp_idx; |
| 2357 | cb->args[1] = if_idx; |
| 2358 | |
| 2359 | return skb->len; |
| 2360 | } |
| 2361 | |
| 2362 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) |
| 2363 | { |
| 2364 | struct sk_buff *msg; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2365 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2366 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2367 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2368 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2369 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2370 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2371 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2372 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2373 | dev, wdev) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2374 | nlmsg_free(msg); |
| 2375 | return -ENOBUFS; |
| 2376 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2377 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 2378 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2379 | } |
| 2380 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2381 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
| 2382 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, |
| 2383 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, |
| 2384 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, |
| 2385 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, |
| 2386 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2387 | [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG }, |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2388 | }; |
| 2389 | |
| 2390 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) |
| 2391 | { |
| 2392 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; |
| 2393 | int flag; |
| 2394 | |
| 2395 | *mntrflags = 0; |
| 2396 | |
| 2397 | if (!nla) |
| 2398 | return -EINVAL; |
| 2399 | |
| 2400 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, |
| 2401 | nla, mntr_flags_policy)) |
| 2402 | return -EINVAL; |
| 2403 | |
| 2404 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) |
| 2405 | if (flags[flag]) |
| 2406 | *mntrflags |= (1<<flag); |
| 2407 | |
| 2408 | return 0; |
| 2409 | } |
| 2410 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2411 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2412 | struct net_device *netdev, u8 use_4addr, |
| 2413 | enum nl80211_iftype iftype) |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2414 | { |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2415 | if (!use_4addr) { |
Jiri Pirko | f350a0a8 | 2010-06-15 06:50:45 +0000 | [diff] [blame] | 2416 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2417 | return -EBUSY; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2418 | return 0; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2419 | } |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2420 | |
| 2421 | switch (iftype) { |
| 2422 | case NL80211_IFTYPE_AP_VLAN: |
| 2423 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) |
| 2424 | return 0; |
| 2425 | break; |
| 2426 | case NL80211_IFTYPE_STATION: |
| 2427 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) |
| 2428 | return 0; |
| 2429 | break; |
| 2430 | default: |
| 2431 | break; |
| 2432 | } |
| 2433 | |
| 2434 | return -EOPNOTSUPP; |
| 2435 | } |
| 2436 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2437 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
| 2438 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2439 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2440 | struct vif_params params; |
Johannes Berg | e36d56b | 2009-06-09 21:04:43 +0200 | [diff] [blame] | 2441 | int err; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2442 | enum nl80211_iftype otype, ntype; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2443 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2444 | u32 _flags, *flags = NULL; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2445 | bool change = false; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2446 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2447 | memset(¶ms, 0, sizeof(params)); |
| 2448 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2449 | otype = ntype = dev->ieee80211_ptr->iftype; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2450 | |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 2451 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2452 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2453 | if (otype != ntype) |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2454 | change = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2455 | if (ntype > NL80211_IFTYPE_MAX) |
| 2456 | return -EINVAL; |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 2457 | } |
| 2458 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2459 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2460 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2461 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2462 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
| 2463 | return -EINVAL; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2464 | if (netif_running(dev)) |
| 2465 | return -EBUSY; |
| 2466 | |
| 2467 | wdev_lock(wdev); |
| 2468 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 2469 | IEEE80211_MAX_MESH_ID_LEN); |
| 2470 | wdev->mesh_id_up_len = |
| 2471 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 2472 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 2473 | wdev->mesh_id_up_len); |
| 2474 | wdev_unlock(wdev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2475 | } |
| 2476 | |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2477 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
| 2478 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
| 2479 | change = true; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2480 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2481 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2482 | return err; |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2483 | } else { |
| 2484 | params.use_4addr = -1; |
| 2485 | } |
| 2486 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2487 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2488 | if (ntype != NL80211_IFTYPE_MONITOR) |
| 2489 | return -EINVAL; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2490 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
| 2491 | &_flags); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2492 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2493 | return err; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2494 | |
| 2495 | flags = &_flags; |
| 2496 | change = true; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2497 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2498 | |
Luciano Coelho | 1800329 | 2013-08-29 13:26:57 +0300 | [diff] [blame] | 2499 | if (flags && (*flags & MONITOR_FLAG_ACTIVE) && |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2500 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
| 2501 | return -EOPNOTSUPP; |
| 2502 | |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2503 | if (change) |
Johannes Berg | 3d54d25 | 2009-08-21 14:51:05 +0200 | [diff] [blame] | 2504 | err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2505 | else |
| 2506 | err = 0; |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 2507 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2508 | if (!err && params.use_4addr != -1) |
| 2509 | dev->ieee80211_ptr->use_4addr = params.use_4addr; |
| 2510 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2511 | return err; |
| 2512 | } |
| 2513 | |
| 2514 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) |
| 2515 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2516 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2517 | struct vif_params params; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2518 | struct wireless_dev *wdev; |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2519 | struct sk_buff *msg; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2520 | int err; |
| 2521 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2522 | u32 flags; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2523 | |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 2524 | /* to avoid failing a new interface creation due to pending removal */ |
| 2525 | cfg80211_destroy_ifaces(rdev); |
| 2526 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2527 | memset(¶ms, 0, sizeof(params)); |
| 2528 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2529 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
| 2530 | return -EINVAL; |
| 2531 | |
| 2532 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
| 2533 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
| 2534 | if (type > NL80211_IFTYPE_MAX) |
| 2535 | return -EINVAL; |
| 2536 | } |
| 2537 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2538 | if (!rdev->ops->add_virtual_intf || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2539 | !(rdev->wiphy.interface_modes & (1 << type))) |
| 2540 | return -EOPNOTSUPP; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2541 | |
Arend van Spriel | 1c18f14 | 2013-01-08 10:17:27 +0100 | [diff] [blame] | 2542 | if (type == NL80211_IFTYPE_P2P_DEVICE && info->attrs[NL80211_ATTR_MAC]) { |
| 2543 | nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC], |
| 2544 | ETH_ALEN); |
| 2545 | if (!is_valid_ether_addr(params.macaddr)) |
| 2546 | return -EADDRNOTAVAIL; |
| 2547 | } |
| 2548 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2549 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2550 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2551 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2552 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2553 | return err; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2554 | } |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2555 | |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2556 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 2557 | if (!msg) |
| 2558 | return -ENOMEM; |
| 2559 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2560 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
| 2561 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, |
| 2562 | &flags); |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2563 | |
Luciano Coelho | 1800329 | 2013-08-29 13:26:57 +0300 | [diff] [blame] | 2564 | if (!err && (flags & MONITOR_FLAG_ACTIVE) && |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2565 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
| 2566 | return -EOPNOTSUPP; |
| 2567 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2568 | wdev = rdev_add_virtual_intf(rdev, |
| 2569 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), |
| 2570 | type, err ? NULL : &flags, ¶ms); |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2571 | if (IS_ERR(wdev)) { |
| 2572 | nlmsg_free(msg); |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2573 | return PTR_ERR(wdev); |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2574 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2575 | |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 2576 | if (info->attrs[NL80211_ATTR_IFACE_SOCKET_OWNER]) |
| 2577 | wdev->owner_nlportid = info->snd_portid; |
| 2578 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2579 | switch (type) { |
| 2580 | case NL80211_IFTYPE_MESH_POINT: |
| 2581 | if (!info->attrs[NL80211_ATTR_MESH_ID]) |
| 2582 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2583 | wdev_lock(wdev); |
| 2584 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 2585 | IEEE80211_MAX_MESH_ID_LEN); |
| 2586 | wdev->mesh_id_up_len = |
| 2587 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 2588 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 2589 | wdev->mesh_id_up_len); |
| 2590 | wdev_unlock(wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2591 | break; |
| 2592 | case NL80211_IFTYPE_P2P_DEVICE: |
| 2593 | /* |
| 2594 | * P2P Device doesn't have a netdev, so doesn't go |
| 2595 | * through the netdev notifier and must be added here |
| 2596 | */ |
| 2597 | mutex_init(&wdev->mtx); |
| 2598 | INIT_LIST_HEAD(&wdev->event_list); |
| 2599 | spin_lock_init(&wdev->event_lock); |
| 2600 | INIT_LIST_HEAD(&wdev->mgmt_registrations); |
| 2601 | spin_lock_init(&wdev->mgmt_registrations_lock); |
| 2602 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2603 | wdev->identifier = ++rdev->wdev_id; |
| 2604 | list_add_rcu(&wdev->list, &rdev->wdev_list); |
| 2605 | rdev->devlist_generation++; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2606 | break; |
| 2607 | default: |
| 2608 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2609 | } |
| 2610 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2611 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2612 | rdev, wdev) < 0) { |
| 2613 | nlmsg_free(msg); |
| 2614 | return -ENOBUFS; |
| 2615 | } |
| 2616 | |
| 2617 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2618 | } |
| 2619 | |
| 2620 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) |
| 2621 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2622 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2623 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2624 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2625 | if (!rdev->ops->del_virtual_intf) |
| 2626 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2627 | |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2628 | /* |
| 2629 | * If we remove a wireless device without a netdev then clear |
| 2630 | * user_ptr[1] so that nl80211_post_doit won't dereference it |
| 2631 | * to check if it needs to do dev_put(). Otherwise it crashes |
| 2632 | * since the wdev has been freed, unlike with a netdev where |
| 2633 | * we need the dev_put() for the netdev to really be freed. |
| 2634 | */ |
| 2635 | if (!wdev->netdev) |
| 2636 | info->user_ptr[1] = NULL; |
| 2637 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2638 | return rdev_del_virtual_intf(rdev, wdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2639 | } |
| 2640 | |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 2641 | static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info) |
| 2642 | { |
| 2643 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2644 | struct net_device *dev = info->user_ptr[1]; |
| 2645 | u16 noack_map; |
| 2646 | |
| 2647 | if (!info->attrs[NL80211_ATTR_NOACK_MAP]) |
| 2648 | return -EINVAL; |
| 2649 | |
| 2650 | if (!rdev->ops->set_noack_map) |
| 2651 | return -EOPNOTSUPP; |
| 2652 | |
| 2653 | noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]); |
| 2654 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2655 | return rdev_set_noack_map(rdev, dev, noack_map); |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 2656 | } |
| 2657 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2658 | struct get_key_cookie { |
| 2659 | struct sk_buff *msg; |
| 2660 | int error; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2661 | int idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2662 | }; |
| 2663 | |
| 2664 | static void get_key_callback(void *c, struct key_params *params) |
| 2665 | { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2666 | struct nlattr *key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2667 | struct get_key_cookie *cookie = c; |
| 2668 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2669 | if ((params->key && |
| 2670 | nla_put(cookie->msg, NL80211_ATTR_KEY_DATA, |
| 2671 | params->key_len, params->key)) || |
| 2672 | (params->seq && |
| 2673 | nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ, |
| 2674 | params->seq_len, params->seq)) || |
| 2675 | (params->cipher && |
| 2676 | nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER, |
| 2677 | params->cipher))) |
| 2678 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2679 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2680 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
| 2681 | if (!key) |
| 2682 | goto nla_put_failure; |
| 2683 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2684 | if ((params->key && |
| 2685 | nla_put(cookie->msg, NL80211_KEY_DATA, |
| 2686 | params->key_len, params->key)) || |
| 2687 | (params->seq && |
| 2688 | nla_put(cookie->msg, NL80211_KEY_SEQ, |
| 2689 | params->seq_len, params->seq)) || |
| 2690 | (params->cipher && |
| 2691 | nla_put_u32(cookie->msg, NL80211_KEY_CIPHER, |
| 2692 | params->cipher))) |
| 2693 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2694 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2695 | if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx)) |
| 2696 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2697 | |
| 2698 | nla_nest_end(cookie->msg, key); |
| 2699 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2700 | return; |
| 2701 | nla_put_failure: |
| 2702 | cookie->error = 1; |
| 2703 | } |
| 2704 | |
| 2705 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) |
| 2706 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2707 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2708 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2709 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2710 | u8 key_idx = 0; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2711 | const u8 *mac_addr = NULL; |
| 2712 | bool pairwise; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2713 | struct get_key_cookie cookie = { |
| 2714 | .error = 0, |
| 2715 | }; |
| 2716 | void *hdr; |
| 2717 | struct sk_buff *msg; |
| 2718 | |
| 2719 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 2720 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 2721 | |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 2722 | if (key_idx > 5) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2723 | return -EINVAL; |
| 2724 | |
| 2725 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2726 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2727 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2728 | pairwise = !!mac_addr; |
| 2729 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 2730 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 2731 | if (kt >= NUM_NL80211_KEYTYPES) |
| 2732 | return -EINVAL; |
| 2733 | if (kt != NL80211_KEYTYPE_GROUP && |
| 2734 | kt != NL80211_KEYTYPE_PAIRWISE) |
| 2735 | return -EINVAL; |
| 2736 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; |
| 2737 | } |
| 2738 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2739 | if (!rdev->ops->get_key) |
| 2740 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2741 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2742 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2743 | if (!msg) |
| 2744 | return -ENOMEM; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2745 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2746 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2747 | NL80211_CMD_NEW_KEY); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 2748 | if (!hdr) |
Johannes Berg | 9fe271a | 2013-10-25 11:15:12 +0200 | [diff] [blame] | 2749 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2750 | |
| 2751 | cookie.msg = msg; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2752 | cookie.idx = key_idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2753 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2754 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 2755 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) |
| 2756 | goto nla_put_failure; |
| 2757 | if (mac_addr && |
| 2758 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 2759 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2760 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2761 | if (pairwise && mac_addr && |
| 2762 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 2763 | return -ENOENT; |
| 2764 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2765 | err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie, |
| 2766 | get_key_callback); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2767 | |
| 2768 | if (err) |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 2769 | goto free_msg; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2770 | |
| 2771 | if (cookie.error) |
| 2772 | goto nla_put_failure; |
| 2773 | |
| 2774 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2775 | return genlmsg_reply(msg, info); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2776 | |
| 2777 | nla_put_failure: |
| 2778 | err = -ENOBUFS; |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 2779 | free_msg: |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2780 | nlmsg_free(msg); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2781 | return err; |
| 2782 | } |
| 2783 | |
| 2784 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) |
| 2785 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2786 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2787 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2788 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2789 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2790 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2791 | err = nl80211_parse_key(info, &key); |
| 2792 | if (err) |
| 2793 | return err; |
| 2794 | |
| 2795 | if (key.idx < 0) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2796 | return -EINVAL; |
| 2797 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2798 | /* only support setting default key */ |
| 2799 | if (!key.def && !key.defmgmt) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2800 | return -EINVAL; |
| 2801 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2802 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2803 | |
| 2804 | if (key.def) { |
| 2805 | if (!rdev->ops->set_default_key) { |
| 2806 | err = -EOPNOTSUPP; |
| 2807 | goto out; |
| 2808 | } |
| 2809 | |
| 2810 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2811 | if (err) |
| 2812 | goto out; |
| 2813 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2814 | err = rdev_set_default_key(rdev, dev, key.idx, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2815 | key.def_uni, key.def_multi); |
| 2816 | |
| 2817 | if (err) |
| 2818 | goto out; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2819 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 2820 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2821 | dev->ieee80211_ptr->wext.default_key = key.idx; |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2822 | #endif |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2823 | } else { |
| 2824 | if (key.def_uni || !key.def_multi) { |
| 2825 | err = -EINVAL; |
| 2826 | goto out; |
| 2827 | } |
| 2828 | |
| 2829 | if (!rdev->ops->set_default_mgmt_key) { |
| 2830 | err = -EOPNOTSUPP; |
| 2831 | goto out; |
| 2832 | } |
| 2833 | |
| 2834 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2835 | if (err) |
| 2836 | goto out; |
| 2837 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2838 | err = rdev_set_default_mgmt_key(rdev, dev, key.idx); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2839 | if (err) |
| 2840 | goto out; |
| 2841 | |
| 2842 | #ifdef CONFIG_CFG80211_WEXT |
| 2843 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; |
| 2844 | #endif |
| 2845 | } |
| 2846 | |
| 2847 | out: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2848 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2849 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2850 | return err; |
| 2851 | } |
| 2852 | |
| 2853 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) |
| 2854 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2855 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2856 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2857 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2858 | struct key_parse key; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2859 | const u8 *mac_addr = NULL; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2860 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2861 | err = nl80211_parse_key(info, &key); |
| 2862 | if (err) |
| 2863 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2864 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2865 | if (!key.p.key) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2866 | return -EINVAL; |
| 2867 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2868 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2869 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2870 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2871 | if (key.type == -1) { |
| 2872 | if (mac_addr) |
| 2873 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 2874 | else |
| 2875 | key.type = NL80211_KEYTYPE_GROUP; |
| 2876 | } |
| 2877 | |
| 2878 | /* for now */ |
| 2879 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 2880 | key.type != NL80211_KEYTYPE_GROUP) |
| 2881 | return -EINVAL; |
| 2882 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2883 | if (!rdev->ops->add_key) |
| 2884 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2885 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2886 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
| 2887 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2888 | mac_addr)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2889 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2890 | |
| 2891 | wdev_lock(dev->ieee80211_ptr); |
| 2892 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2893 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2894 | err = rdev_add_key(rdev, dev, key.idx, |
| 2895 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2896 | mac_addr, &key.p); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2897 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2898 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2899 | return err; |
| 2900 | } |
| 2901 | |
| 2902 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) |
| 2903 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2904 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2905 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2906 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2907 | u8 *mac_addr = NULL; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2908 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2909 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2910 | err = nl80211_parse_key(info, &key); |
| 2911 | if (err) |
| 2912 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2913 | |
| 2914 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2915 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2916 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2917 | if (key.type == -1) { |
| 2918 | if (mac_addr) |
| 2919 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 2920 | else |
| 2921 | key.type = NL80211_KEYTYPE_GROUP; |
| 2922 | } |
| 2923 | |
| 2924 | /* for now */ |
| 2925 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 2926 | key.type != NL80211_KEYTYPE_GROUP) |
| 2927 | return -EINVAL; |
| 2928 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2929 | if (!rdev->ops->del_key) |
| 2930 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2931 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2932 | wdev_lock(dev->ieee80211_ptr); |
| 2933 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2934 | |
| 2935 | if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr && |
| 2936 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 2937 | err = -ENOENT; |
| 2938 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2939 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2940 | err = rdev_del_key(rdev, dev, key.idx, |
| 2941 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2942 | mac_addr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2943 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 2944 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2945 | if (!err) { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2946 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2947 | dev->ieee80211_ptr->wext.default_key = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2948 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2949 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
| 2950 | } |
| 2951 | #endif |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2952 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2953 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2954 | return err; |
| 2955 | } |
| 2956 | |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 2957 | /* This function returns an error or the number of nested attributes */ |
| 2958 | static int validate_acl_mac_addrs(struct nlattr *nl_attr) |
| 2959 | { |
| 2960 | struct nlattr *attr; |
| 2961 | int n_entries = 0, tmp; |
| 2962 | |
| 2963 | nla_for_each_nested(attr, nl_attr, tmp) { |
| 2964 | if (nla_len(attr) != ETH_ALEN) |
| 2965 | return -EINVAL; |
| 2966 | |
| 2967 | n_entries++; |
| 2968 | } |
| 2969 | |
| 2970 | return n_entries; |
| 2971 | } |
| 2972 | |
| 2973 | /* |
| 2974 | * This function parses ACL information and allocates memory for ACL data. |
| 2975 | * On successful return, the calling function is responsible to free the |
| 2976 | * ACL buffer returned by this function. |
| 2977 | */ |
| 2978 | static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy, |
| 2979 | struct genl_info *info) |
| 2980 | { |
| 2981 | enum nl80211_acl_policy acl_policy; |
| 2982 | struct nlattr *attr; |
| 2983 | struct cfg80211_acl_data *acl; |
| 2984 | int i = 0, n_entries, tmp; |
| 2985 | |
| 2986 | if (!wiphy->max_acl_mac_addrs) |
| 2987 | return ERR_PTR(-EOPNOTSUPP); |
| 2988 | |
| 2989 | if (!info->attrs[NL80211_ATTR_ACL_POLICY]) |
| 2990 | return ERR_PTR(-EINVAL); |
| 2991 | |
| 2992 | acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]); |
| 2993 | if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED && |
| 2994 | acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED) |
| 2995 | return ERR_PTR(-EINVAL); |
| 2996 | |
| 2997 | if (!info->attrs[NL80211_ATTR_MAC_ADDRS]) |
| 2998 | return ERR_PTR(-EINVAL); |
| 2999 | |
| 3000 | n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]); |
| 3001 | if (n_entries < 0) |
| 3002 | return ERR_PTR(n_entries); |
| 3003 | |
| 3004 | if (n_entries > wiphy->max_acl_mac_addrs) |
| 3005 | return ERR_PTR(-ENOTSUPP); |
| 3006 | |
| 3007 | acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries), |
| 3008 | GFP_KERNEL); |
| 3009 | if (!acl) |
| 3010 | return ERR_PTR(-ENOMEM); |
| 3011 | |
| 3012 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) { |
| 3013 | memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN); |
| 3014 | i++; |
| 3015 | } |
| 3016 | |
| 3017 | acl->n_acl_entries = n_entries; |
| 3018 | acl->acl_policy = acl_policy; |
| 3019 | |
| 3020 | return acl; |
| 3021 | } |
| 3022 | |
| 3023 | static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info) |
| 3024 | { |
| 3025 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3026 | struct net_device *dev = info->user_ptr[1]; |
| 3027 | struct cfg80211_acl_data *acl; |
| 3028 | int err; |
| 3029 | |
| 3030 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3031 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3032 | return -EOPNOTSUPP; |
| 3033 | |
| 3034 | if (!dev->ieee80211_ptr->beacon_interval) |
| 3035 | return -EINVAL; |
| 3036 | |
| 3037 | acl = parse_acl_data(&rdev->wiphy, info); |
| 3038 | if (IS_ERR(acl)) |
| 3039 | return PTR_ERR(acl); |
| 3040 | |
| 3041 | err = rdev_set_mac_acl(rdev, dev, acl); |
| 3042 | |
| 3043 | kfree(acl); |
| 3044 | |
| 3045 | return err; |
| 3046 | } |
| 3047 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3048 | static int nl80211_parse_beacon(struct nlattr *attrs[], |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3049 | struct cfg80211_beacon_data *bcn) |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3050 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3051 | bool haveinfo = false; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3052 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3053 | if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) || |
| 3054 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) || |
| 3055 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) || |
| 3056 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP])) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 3057 | return -EINVAL; |
| 3058 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3059 | memset(bcn, 0, sizeof(*bcn)); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3060 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3061 | if (attrs[NL80211_ATTR_BEACON_HEAD]) { |
| 3062 | bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]); |
| 3063 | bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3064 | if (!bcn->head_len) |
| 3065 | return -EINVAL; |
| 3066 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3067 | } |
| 3068 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3069 | if (attrs[NL80211_ATTR_BEACON_TAIL]) { |
| 3070 | bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]); |
| 3071 | bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3072 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3073 | } |
| 3074 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3075 | if (!haveinfo) |
| 3076 | return -EINVAL; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3077 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3078 | if (attrs[NL80211_ATTR_IE]) { |
| 3079 | bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]); |
| 3080 | bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]); |
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_IE_PROBE_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3084 | bcn->proberesp_ies = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3085 | nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3086 | bcn->proberesp_ies_len = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3087 | nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 3088 | } |
| 3089 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3090 | if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3091 | bcn->assocresp_ies = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3092 | nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3093 | bcn->assocresp_ies_len = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3094 | nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 3095 | } |
| 3096 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3097 | if (attrs[NL80211_ATTR_PROBE_RESP]) { |
| 3098 | bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]); |
| 3099 | bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]); |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 3100 | } |
| 3101 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3102 | return 0; |
| 3103 | } |
| 3104 | |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3105 | static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev, |
| 3106 | struct cfg80211_ap_settings *params) |
| 3107 | { |
| 3108 | struct wireless_dev *wdev; |
| 3109 | bool ret = false; |
| 3110 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 3111 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3112 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 3113 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 3114 | continue; |
| 3115 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3116 | if (!wdev->preset_chandef.chan) |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3117 | continue; |
| 3118 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3119 | params->chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3120 | ret = true; |
| 3121 | break; |
| 3122 | } |
| 3123 | |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3124 | return ret; |
| 3125 | } |
| 3126 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 3127 | static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev, |
| 3128 | enum nl80211_auth_type auth_type, |
| 3129 | enum nl80211_commands cmd) |
| 3130 | { |
| 3131 | if (auth_type > NL80211_AUTHTYPE_MAX) |
| 3132 | return false; |
| 3133 | |
| 3134 | switch (cmd) { |
| 3135 | case NL80211_CMD_AUTHENTICATE: |
| 3136 | if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && |
| 3137 | auth_type == NL80211_AUTHTYPE_SAE) |
| 3138 | return false; |
| 3139 | return true; |
| 3140 | case NL80211_CMD_CONNECT: |
| 3141 | case NL80211_CMD_START_AP: |
| 3142 | /* SAE not supported yet */ |
| 3143 | if (auth_type == NL80211_AUTHTYPE_SAE) |
| 3144 | return false; |
| 3145 | return true; |
| 3146 | default: |
| 3147 | return false; |
| 3148 | } |
| 3149 | } |
| 3150 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3151 | static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) |
| 3152 | { |
| 3153 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3154 | struct net_device *dev = info->user_ptr[1]; |
| 3155 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3156 | struct cfg80211_ap_settings params; |
| 3157 | int err; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 3158 | u8 radar_detect_width = 0; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3159 | |
| 3160 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3161 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3162 | return -EOPNOTSUPP; |
| 3163 | |
| 3164 | if (!rdev->ops->start_ap) |
| 3165 | return -EOPNOTSUPP; |
| 3166 | |
| 3167 | if (wdev->beacon_interval) |
| 3168 | return -EALREADY; |
| 3169 | |
| 3170 | memset(¶ms, 0, sizeof(params)); |
| 3171 | |
| 3172 | /* these are required for START_AP */ |
| 3173 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || |
| 3174 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || |
| 3175 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) |
| 3176 | return -EINVAL; |
| 3177 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3178 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3179 | if (err) |
| 3180 | return err; |
| 3181 | |
| 3182 | params.beacon_interval = |
| 3183 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 3184 | params.dtim_period = |
| 3185 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 3186 | |
| 3187 | err = cfg80211_validate_beacon_int(rdev, params.beacon_interval); |
| 3188 | if (err) |
| 3189 | return err; |
| 3190 | |
| 3191 | /* |
| 3192 | * In theory, some of these attributes should be required here |
| 3193 | * but since they were not used when the command was originally |
| 3194 | * added, keep them optional for old user space programs to let |
| 3195 | * them continue to work with drivers that do not need the |
| 3196 | * additional information -- drivers must check! |
| 3197 | */ |
| 3198 | if (info->attrs[NL80211_ATTR_SSID]) { |
| 3199 | params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 3200 | params.ssid_len = |
| 3201 | nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 3202 | if (params.ssid_len == 0 || |
| 3203 | params.ssid_len > IEEE80211_MAX_SSID_LEN) |
| 3204 | return -EINVAL; |
| 3205 | } |
| 3206 | |
| 3207 | if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) { |
| 3208 | params.hidden_ssid = nla_get_u32( |
| 3209 | info->attrs[NL80211_ATTR_HIDDEN_SSID]); |
| 3210 | if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE && |
| 3211 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN && |
| 3212 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS) |
| 3213 | return -EINVAL; |
| 3214 | } |
| 3215 | |
| 3216 | params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
| 3217 | |
| 3218 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 3219 | params.auth_type = nla_get_u32( |
| 3220 | info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 3221 | if (!nl80211_valid_auth_type(rdev, params.auth_type, |
| 3222 | NL80211_CMD_START_AP)) |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3223 | return -EINVAL; |
| 3224 | } else |
| 3225 | params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 3226 | |
| 3227 | err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, |
| 3228 | NL80211_MAX_NR_CIPHER_SUITES); |
| 3229 | if (err) |
| 3230 | return err; |
| 3231 | |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 3232 | if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) { |
| 3233 | if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER)) |
| 3234 | return -EOPNOTSUPP; |
| 3235 | params.inactivity_timeout = nla_get_u16( |
| 3236 | info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]); |
| 3237 | } |
| 3238 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 3239 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 3240 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3241 | return -EINVAL; |
| 3242 | params.p2p_ctwindow = |
| 3243 | nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
| 3244 | if (params.p2p_ctwindow > 127) |
| 3245 | return -EINVAL; |
| 3246 | if (params.p2p_ctwindow != 0 && |
| 3247 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 3248 | return -EINVAL; |
| 3249 | } |
| 3250 | |
| 3251 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 3252 | u8 tmp; |
| 3253 | |
| 3254 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3255 | return -EINVAL; |
| 3256 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
| 3257 | if (tmp > 1) |
| 3258 | return -EINVAL; |
| 3259 | params.p2p_opp_ps = tmp; |
| 3260 | if (params.p2p_opp_ps != 0 && |
| 3261 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 3262 | return -EINVAL; |
| 3263 | } |
| 3264 | |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3265 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3266 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
| 3267 | if (err) |
| 3268 | return err; |
| 3269 | } else if (wdev->preset_chandef.chan) { |
| 3270 | params.chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3271 | } else if (!nl80211_get_ap_channel(rdev, ¶ms)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3272 | return -EINVAL; |
| 3273 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3274 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, ¶ms.chandef)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3275 | return -EINVAL; |
| 3276 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 3277 | err = cfg80211_chandef_dfs_required(wdev->wiphy, ¶ms.chandef); |
| 3278 | if (err < 0) |
| 3279 | return err; |
| 3280 | if (err) { |
| 3281 | radar_detect_width = BIT(params.chandef.width); |
| 3282 | params.radar_required = true; |
| 3283 | } |
| 3284 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 3285 | err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype, |
| 3286 | params.chandef.chan, |
| 3287 | CHAN_MODE_SHARED, |
| 3288 | radar_detect_width); |
Michal Kazior | e4e3245 | 2012-06-29 12:47:08 +0200 | [diff] [blame] | 3289 | if (err) |
| 3290 | return err; |
| 3291 | |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 3292 | if (info->attrs[NL80211_ATTR_ACL_POLICY]) { |
| 3293 | params.acl = parse_acl_data(&rdev->wiphy, info); |
| 3294 | if (IS_ERR(params.acl)) |
| 3295 | return PTR_ERR(params.acl); |
| 3296 | } |
| 3297 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 3298 | wdev_lock(wdev); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3299 | err = rdev_start_ap(rdev, dev, ¶ms); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3300 | if (!err) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3301 | wdev->preset_chandef = params.chandef; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3302 | wdev->beacon_interval = params.beacon_interval; |
Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 3303 | wdev->chandef = params.chandef; |
Antonio Quartulli | 06e191e | 2012-11-07 12:52:19 +0100 | [diff] [blame] | 3304 | wdev->ssid_len = params.ssid_len; |
| 3305 | memcpy(wdev->ssid, params.ssid, wdev->ssid_len); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3306 | } |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 3307 | wdev_unlock(wdev); |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 3308 | |
| 3309 | kfree(params.acl); |
| 3310 | |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 3311 | return err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3312 | } |
| 3313 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3314 | static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info) |
| 3315 | { |
| 3316 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3317 | struct net_device *dev = info->user_ptr[1]; |
| 3318 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3319 | struct cfg80211_beacon_data params; |
| 3320 | int err; |
| 3321 | |
| 3322 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3323 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3324 | return -EOPNOTSUPP; |
| 3325 | |
| 3326 | if (!rdev->ops->change_beacon) |
| 3327 | return -EOPNOTSUPP; |
| 3328 | |
| 3329 | if (!wdev->beacon_interval) |
| 3330 | return -EINVAL; |
| 3331 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3332 | err = nl80211_parse_beacon(info->attrs, ¶ms); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3333 | if (err) |
| 3334 | return err; |
| 3335 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 3336 | wdev_lock(wdev); |
| 3337 | err = rdev_change_beacon(rdev, dev, ¶ms); |
| 3338 | wdev_unlock(wdev); |
| 3339 | |
| 3340 | return err; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3341 | } |
| 3342 | |
| 3343 | 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] | 3344 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3345 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3346 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3347 | |
Ilan Peer | 7c8d5e0 | 2014-02-25 15:33:38 +0200 | [diff] [blame] | 3348 | return cfg80211_stop_ap(rdev, dev, false); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3349 | } |
| 3350 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3351 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
| 3352 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, |
| 3353 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, |
| 3354 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, |
Jouni Malinen | 0e46724 | 2009-05-11 21:57:55 +0300 | [diff] [blame] | 3355 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 3356 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
Johannes Berg | d83023d | 2011-12-14 09:29:15 +0100 | [diff] [blame] | 3357 | [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3358 | }; |
| 3359 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3360 | static int parse_station_flags(struct genl_info *info, |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3361 | enum nl80211_iftype iftype, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3362 | struct station_parameters *params) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3363 | { |
| 3364 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3365 | struct nlattr *nla; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3366 | int flag; |
| 3367 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3368 | /* |
| 3369 | * Try parsing the new attribute first so userspace |
| 3370 | * can specify both for older kernels. |
| 3371 | */ |
| 3372 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; |
| 3373 | if (nla) { |
| 3374 | struct nl80211_sta_flag_update *sta_flags; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3375 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3376 | sta_flags = nla_data(nla); |
| 3377 | params->sta_flags_mask = sta_flags->mask; |
| 3378 | params->sta_flags_set = sta_flags->set; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3379 | params->sta_flags_set &= params->sta_flags_mask; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3380 | if ((params->sta_flags_mask | |
| 3381 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) |
| 3382 | return -EINVAL; |
| 3383 | return 0; |
| 3384 | } |
| 3385 | |
| 3386 | /* if present, parse the old attribute */ |
| 3387 | |
| 3388 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3389 | if (!nla) |
| 3390 | return 0; |
| 3391 | |
| 3392 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, |
| 3393 | nla, sta_flags_policy)) |
| 3394 | return -EINVAL; |
| 3395 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3396 | /* |
| 3397 | * Only allow certain flags for interface types so that |
| 3398 | * other attributes are silently ignored. Remember that |
| 3399 | * this is backward compatibility code with old userspace |
| 3400 | * and shouldn't be hit in other cases anyway. |
| 3401 | */ |
| 3402 | switch (iftype) { |
| 3403 | case NL80211_IFTYPE_AP: |
| 3404 | case NL80211_IFTYPE_AP_VLAN: |
| 3405 | case NL80211_IFTYPE_P2P_GO: |
| 3406 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3407 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 3408 | BIT(NL80211_STA_FLAG_WME) | |
| 3409 | BIT(NL80211_STA_FLAG_MFP); |
| 3410 | break; |
| 3411 | case NL80211_IFTYPE_P2P_CLIENT: |
| 3412 | case NL80211_IFTYPE_STATION: |
| 3413 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3414 | BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3415 | break; |
| 3416 | case NL80211_IFTYPE_MESH_POINT: |
| 3417 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3418 | BIT(NL80211_STA_FLAG_MFP) | |
| 3419 | BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 3420 | default: |
| 3421 | return -EINVAL; |
| 3422 | } |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3423 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 3424 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) { |
| 3425 | if (flags[flag]) { |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3426 | params->sta_flags_set |= (1<<flag); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3427 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 3428 | /* no longer support new API additions in old API */ |
| 3429 | if (flag > NL80211_STA_FLAG_MAX_OLD_API) |
| 3430 | return -EINVAL; |
| 3431 | } |
| 3432 | } |
| 3433 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3434 | return 0; |
| 3435 | } |
| 3436 | |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3437 | static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, |
| 3438 | int attr) |
| 3439 | { |
| 3440 | struct nlattr *rate; |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 3441 | u32 bitrate; |
| 3442 | u16 bitrate_compat; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3443 | |
| 3444 | rate = nla_nest_start(msg, attr); |
| 3445 | if (!rate) |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 3446 | return false; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3447 | |
| 3448 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ |
| 3449 | bitrate = cfg80211_calculate_bitrate(info); |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 3450 | /* report 16-bit bitrate only if we can */ |
| 3451 | bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 3452 | if (bitrate > 0 && |
| 3453 | nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate)) |
| 3454 | return false; |
| 3455 | if (bitrate_compat > 0 && |
| 3456 | nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat)) |
| 3457 | return false; |
| 3458 | |
| 3459 | if (info->flags & RATE_INFO_FLAGS_MCS) { |
| 3460 | if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) |
| 3461 | return false; |
| 3462 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && |
| 3463 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) |
| 3464 | return false; |
| 3465 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 3466 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 3467 | return false; |
| 3468 | } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) { |
| 3469 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs)) |
| 3470 | return false; |
| 3471 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss)) |
| 3472 | return false; |
| 3473 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && |
| 3474 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) |
| 3475 | return false; |
| 3476 | if (info->flags & RATE_INFO_FLAGS_80_MHZ_WIDTH && |
| 3477 | nla_put_flag(msg, NL80211_RATE_INFO_80_MHZ_WIDTH)) |
| 3478 | return false; |
| 3479 | if (info->flags & RATE_INFO_FLAGS_80P80_MHZ_WIDTH && |
| 3480 | nla_put_flag(msg, NL80211_RATE_INFO_80P80_MHZ_WIDTH)) |
| 3481 | return false; |
| 3482 | if (info->flags & RATE_INFO_FLAGS_160_MHZ_WIDTH && |
| 3483 | nla_put_flag(msg, NL80211_RATE_INFO_160_MHZ_WIDTH)) |
| 3484 | return false; |
| 3485 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 3486 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 3487 | return false; |
| 3488 | } |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3489 | |
| 3490 | nla_nest_end(msg, rate); |
| 3491 | return true; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3492 | } |
| 3493 | |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 3494 | static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal, |
| 3495 | int id) |
| 3496 | { |
| 3497 | void *attr; |
| 3498 | int i = 0; |
| 3499 | |
| 3500 | if (!mask) |
| 3501 | return true; |
| 3502 | |
| 3503 | attr = nla_nest_start(msg, id); |
| 3504 | if (!attr) |
| 3505 | return false; |
| 3506 | |
| 3507 | for (i = 0; i < IEEE80211_MAX_CHAINS; i++) { |
| 3508 | if (!(mask & BIT(i))) |
| 3509 | continue; |
| 3510 | |
| 3511 | if (nla_put_u8(msg, i, signal[i])) |
| 3512 | return false; |
| 3513 | } |
| 3514 | |
| 3515 | nla_nest_end(msg, attr); |
| 3516 | |
| 3517 | return true; |
| 3518 | } |
| 3519 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3520 | 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] | 3521 | int flags, |
| 3522 | struct cfg80211_registered_device *rdev, |
| 3523 | struct net_device *dev, |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 3524 | const u8 *mac_addr, struct station_info *sinfo) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3525 | { |
| 3526 | void *hdr; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3527 | struct nlattr *sinfoattr, *bss_param; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3528 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3529 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3530 | if (!hdr) |
| 3531 | return -1; |
| 3532 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3533 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 3534 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 3535 | nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation)) |
| 3536 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 3537 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3538 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
| 3539 | if (!sinfoattr) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3540 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3541 | if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) && |
| 3542 | nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME, |
| 3543 | sinfo->connected_time)) |
| 3544 | goto nla_put_failure; |
| 3545 | if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) && |
| 3546 | nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME, |
| 3547 | sinfo->inactive_time)) |
| 3548 | goto nla_put_failure; |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3549 | if ((sinfo->filled & (STATION_INFO_RX_BYTES | |
| 3550 | STATION_INFO_RX_BYTES64)) && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3551 | nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES, |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3552 | (u32)sinfo->rx_bytes)) |
| 3553 | goto nla_put_failure; |
| 3554 | if ((sinfo->filled & (STATION_INFO_TX_BYTES | |
Felix Fietkau | 4325d72 | 2013-05-23 15:05:59 +0200 | [diff] [blame] | 3555 | STATION_INFO_TX_BYTES64)) && |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3556 | nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES, |
| 3557 | (u32)sinfo->tx_bytes)) |
| 3558 | goto nla_put_failure; |
| 3559 | if ((sinfo->filled & STATION_INFO_RX_BYTES64) && |
| 3560 | nla_put_u64(msg, NL80211_STA_INFO_RX_BYTES64, |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3561 | sinfo->rx_bytes)) |
| 3562 | goto nla_put_failure; |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3563 | if ((sinfo->filled & STATION_INFO_TX_BYTES64) && |
| 3564 | nla_put_u64(msg, NL80211_STA_INFO_TX_BYTES64, |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3565 | sinfo->tx_bytes)) |
| 3566 | goto nla_put_failure; |
| 3567 | if ((sinfo->filled & STATION_INFO_LLID) && |
| 3568 | nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid)) |
| 3569 | goto nla_put_failure; |
| 3570 | if ((sinfo->filled & STATION_INFO_PLID) && |
| 3571 | nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid)) |
| 3572 | goto nla_put_failure; |
| 3573 | if ((sinfo->filled & STATION_INFO_PLINK_STATE) && |
| 3574 | nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE, |
| 3575 | sinfo->plink_state)) |
| 3576 | goto nla_put_failure; |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3577 | switch (rdev->wiphy.signal_type) { |
| 3578 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3579 | if ((sinfo->filled & STATION_INFO_SIGNAL) && |
| 3580 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL, |
| 3581 | sinfo->signal)) |
| 3582 | goto nla_put_failure; |
| 3583 | if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) && |
| 3584 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG, |
| 3585 | sinfo->signal_avg)) |
| 3586 | goto nla_put_failure; |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3587 | break; |
| 3588 | default: |
| 3589 | break; |
| 3590 | } |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 3591 | if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL) { |
| 3592 | if (!nl80211_put_signal(msg, sinfo->chains, |
| 3593 | sinfo->chain_signal, |
| 3594 | NL80211_STA_INFO_CHAIN_SIGNAL)) |
| 3595 | goto nla_put_failure; |
| 3596 | } |
| 3597 | if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL_AVG) { |
| 3598 | if (!nl80211_put_signal(msg, sinfo->chains, |
| 3599 | sinfo->chain_signal_avg, |
| 3600 | NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) |
| 3601 | goto nla_put_failure; |
| 3602 | } |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3603 | if (sinfo->filled & STATION_INFO_TX_BITRATE) { |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3604 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
| 3605 | NL80211_STA_INFO_TX_BITRATE)) |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3606 | goto nla_put_failure; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3607 | } |
| 3608 | if (sinfo->filled & STATION_INFO_RX_BITRATE) { |
| 3609 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, |
| 3610 | NL80211_STA_INFO_RX_BITRATE)) |
| 3611 | goto nla_put_failure; |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3612 | } |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3613 | if ((sinfo->filled & STATION_INFO_RX_PACKETS) && |
| 3614 | nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS, |
| 3615 | sinfo->rx_packets)) |
| 3616 | goto nla_put_failure; |
| 3617 | if ((sinfo->filled & STATION_INFO_TX_PACKETS) && |
| 3618 | nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS, |
| 3619 | sinfo->tx_packets)) |
| 3620 | goto nla_put_failure; |
| 3621 | if ((sinfo->filled & STATION_INFO_TX_RETRIES) && |
| 3622 | nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES, |
| 3623 | sinfo->tx_retries)) |
| 3624 | goto nla_put_failure; |
| 3625 | if ((sinfo->filled & STATION_INFO_TX_FAILED) && |
| 3626 | nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED, |
| 3627 | sinfo->tx_failed)) |
| 3628 | goto nla_put_failure; |
| 3629 | if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) && |
| 3630 | nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS, |
| 3631 | sinfo->beacon_loss_count)) |
| 3632 | goto nla_put_failure; |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 3633 | if ((sinfo->filled & STATION_INFO_LOCAL_PM) && |
| 3634 | nla_put_u32(msg, NL80211_STA_INFO_LOCAL_PM, |
| 3635 | sinfo->local_pm)) |
| 3636 | goto nla_put_failure; |
| 3637 | if ((sinfo->filled & STATION_INFO_PEER_PM) && |
| 3638 | nla_put_u32(msg, NL80211_STA_INFO_PEER_PM, |
| 3639 | sinfo->peer_pm)) |
| 3640 | goto nla_put_failure; |
| 3641 | if ((sinfo->filled & STATION_INFO_NONPEER_PM) && |
| 3642 | nla_put_u32(msg, NL80211_STA_INFO_NONPEER_PM, |
| 3643 | sinfo->nonpeer_pm)) |
| 3644 | goto nla_put_failure; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3645 | if (sinfo->filled & STATION_INFO_BSS_PARAM) { |
| 3646 | bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); |
| 3647 | if (!bss_param) |
| 3648 | goto nla_put_failure; |
| 3649 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3650 | if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) && |
| 3651 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) || |
| 3652 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) && |
| 3653 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) || |
| 3654 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) && |
| 3655 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) || |
| 3656 | nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, |
| 3657 | sinfo->bss_param.dtim_period) || |
| 3658 | nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, |
| 3659 | sinfo->bss_param.beacon_interval)) |
| 3660 | goto nla_put_failure; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3661 | |
| 3662 | nla_nest_end(msg, bss_param); |
| 3663 | } |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3664 | if ((sinfo->filled & STATION_INFO_STA_FLAGS) && |
| 3665 | nla_put(msg, NL80211_STA_INFO_STA_FLAGS, |
| 3666 | sizeof(struct nl80211_sta_flag_update), |
| 3667 | &sinfo->sta_flags)) |
| 3668 | goto nla_put_failure; |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 3669 | if ((sinfo->filled & STATION_INFO_T_OFFSET) && |
| 3670 | nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET, |
| 3671 | sinfo->t_offset)) |
| 3672 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3673 | nla_nest_end(msg, sinfoattr); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3674 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3675 | if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) && |
| 3676 | nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, |
| 3677 | sinfo->assoc_req_ies)) |
| 3678 | goto nla_put_failure; |
Jouni Malinen | 50d3dfb | 2011-08-08 12:11:52 +0300 | [diff] [blame] | 3679 | |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3680 | return genlmsg_end(msg, hdr); |
| 3681 | |
| 3682 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 3683 | genlmsg_cancel(msg, hdr); |
| 3684 | return -EMSGSIZE; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3685 | } |
| 3686 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3687 | static int nl80211_dump_station(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3688 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3689 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3690 | struct station_info sinfo; |
| 3691 | struct cfg80211_registered_device *dev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3692 | struct wireless_dev *wdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3693 | u8 mac_addr[ETH_ALEN]; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3694 | int sta_idx = cb->args[2]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3695 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3696 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3697 | err = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3698 | if (err) |
| 3699 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3700 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3701 | if (!wdev->netdev) { |
| 3702 | err = -EINVAL; |
| 3703 | goto out_err; |
| 3704 | } |
| 3705 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3706 | if (!dev->ops->dump_station) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3707 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3708 | goto out_err; |
| 3709 | } |
| 3710 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3711 | while (1) { |
Jouni Malinen | f612ced | 2011-08-11 11:46:22 +0300 | [diff] [blame] | 3712 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3713 | err = rdev_dump_station(dev, wdev->netdev, sta_idx, |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3714 | mac_addr, &sinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3715 | if (err == -ENOENT) |
| 3716 | break; |
| 3717 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3718 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3719 | |
| 3720 | if (nl80211_send_station(skb, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3721 | NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3722 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3723 | dev, wdev->netdev, mac_addr, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3724 | &sinfo) < 0) |
| 3725 | goto out; |
| 3726 | |
| 3727 | sta_idx++; |
| 3728 | } |
| 3729 | |
| 3730 | |
| 3731 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3732 | cb->args[2] = sta_idx; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3733 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3734 | out_err: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3735 | nl80211_finish_wdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3736 | |
| 3737 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3738 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3739 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3740 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
| 3741 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3742 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3743 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3744 | struct station_info sinfo; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3745 | struct sk_buff *msg; |
| 3746 | u8 *mac_addr = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3747 | int err; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3748 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3749 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3750 | |
| 3751 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3752 | return -EINVAL; |
| 3753 | |
| 3754 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3755 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3756 | if (!rdev->ops->get_station) |
| 3757 | return -EOPNOTSUPP; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3758 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3759 | err = rdev_get_station(rdev, dev, mac_addr, &sinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3760 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3761 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3762 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3763 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3764 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3765 | return -ENOMEM; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3766 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3767 | 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] | 3768 | rdev, dev, mac_addr, &sinfo) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3769 | nlmsg_free(msg); |
| 3770 | return -ENOBUFS; |
| 3771 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3772 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3773 | return genlmsg_reply(msg, info); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3774 | } |
| 3775 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3776 | int cfg80211_check_station_change(struct wiphy *wiphy, |
| 3777 | struct station_parameters *params, |
| 3778 | enum cfg80211_station_type statype) |
| 3779 | { |
| 3780 | if (params->listen_interval != -1) |
| 3781 | return -EINVAL; |
| 3782 | if (params->aid) |
| 3783 | return -EINVAL; |
| 3784 | |
| 3785 | /* When you run into this, adjust the code below for the new flag */ |
| 3786 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); |
| 3787 | |
| 3788 | switch (statype) { |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 3789 | case CFG80211_STA_MESH_PEER_KERNEL: |
| 3790 | case CFG80211_STA_MESH_PEER_USER: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3791 | /* |
| 3792 | * No ignoring the TDLS flag here -- the userspace mesh |
| 3793 | * code doesn't have the bug of including TDLS in the |
| 3794 | * mask everywhere. |
| 3795 | */ |
| 3796 | if (params->sta_flags_mask & |
| 3797 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3798 | BIT(NL80211_STA_FLAG_MFP) | |
| 3799 | BIT(NL80211_STA_FLAG_AUTHORIZED))) |
| 3800 | return -EINVAL; |
| 3801 | break; |
| 3802 | case CFG80211_STA_TDLS_PEER_SETUP: |
| 3803 | case CFG80211_STA_TDLS_PEER_ACTIVE: |
| 3804 | if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 3805 | return -EINVAL; |
| 3806 | /* ignore since it can't change */ |
| 3807 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3808 | break; |
| 3809 | default: |
| 3810 | /* disallow mesh-specific things */ |
| 3811 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) |
| 3812 | return -EINVAL; |
| 3813 | if (params->local_pm) |
| 3814 | return -EINVAL; |
| 3815 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
| 3816 | return -EINVAL; |
| 3817 | } |
| 3818 | |
| 3819 | if (statype != CFG80211_STA_TDLS_PEER_SETUP && |
| 3820 | statype != CFG80211_STA_TDLS_PEER_ACTIVE) { |
| 3821 | /* TDLS can't be set, ... */ |
| 3822 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
| 3823 | return -EINVAL; |
| 3824 | /* |
| 3825 | * ... but don't bother the driver with it. This works around |
| 3826 | * a hostapd/wpa_supplicant issue -- it always includes the |
| 3827 | * TLDS_PEER flag in the mask even for AP mode. |
| 3828 | */ |
| 3829 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3830 | } |
| 3831 | |
| 3832 | if (statype != CFG80211_STA_TDLS_PEER_SETUP) { |
| 3833 | /* reject other things that can't change */ |
| 3834 | if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) |
| 3835 | return -EINVAL; |
| 3836 | if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY) |
| 3837 | return -EINVAL; |
| 3838 | if (params->supported_rates) |
| 3839 | return -EINVAL; |
| 3840 | if (params->ext_capab || params->ht_capa || params->vht_capa) |
| 3841 | return -EINVAL; |
| 3842 | } |
| 3843 | |
| 3844 | if (statype != CFG80211_STA_AP_CLIENT) { |
| 3845 | if (params->vlan) |
| 3846 | return -EINVAL; |
| 3847 | } |
| 3848 | |
| 3849 | switch (statype) { |
| 3850 | case CFG80211_STA_AP_MLME_CLIENT: |
| 3851 | /* Use this only for authorizing/unauthorizing a station */ |
| 3852 | if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))) |
| 3853 | return -EOPNOTSUPP; |
| 3854 | break; |
| 3855 | case CFG80211_STA_AP_CLIENT: |
| 3856 | /* accept only the listed bits */ |
| 3857 | if (params->sta_flags_mask & |
| 3858 | ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3859 | BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3860 | BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 3861 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 3862 | BIT(NL80211_STA_FLAG_WME) | |
| 3863 | BIT(NL80211_STA_FLAG_MFP))) |
| 3864 | return -EINVAL; |
| 3865 | |
| 3866 | /* but authenticated/associated only if driver handles it */ |
| 3867 | if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
| 3868 | params->sta_flags_mask & |
| 3869 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3870 | BIT(NL80211_STA_FLAG_ASSOCIATED))) |
| 3871 | return -EINVAL; |
| 3872 | break; |
| 3873 | case CFG80211_STA_IBSS: |
| 3874 | case CFG80211_STA_AP_STA: |
| 3875 | /* reject any changes other than AUTHORIZED */ |
| 3876 | if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) |
| 3877 | return -EINVAL; |
| 3878 | break; |
| 3879 | case CFG80211_STA_TDLS_PEER_SETUP: |
| 3880 | /* reject any changes other than AUTHORIZED or WME */ |
| 3881 | if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3882 | BIT(NL80211_STA_FLAG_WME))) |
| 3883 | return -EINVAL; |
| 3884 | /* force (at least) rates when authorizing */ |
| 3885 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) && |
| 3886 | !params->supported_rates) |
| 3887 | return -EINVAL; |
| 3888 | break; |
| 3889 | case CFG80211_STA_TDLS_PEER_ACTIVE: |
| 3890 | /* reject any changes */ |
| 3891 | return -EINVAL; |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 3892 | case CFG80211_STA_MESH_PEER_KERNEL: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3893 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
| 3894 | return -EINVAL; |
| 3895 | break; |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 3896 | case CFG80211_STA_MESH_PEER_USER: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3897 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) |
| 3898 | return -EINVAL; |
| 3899 | break; |
| 3900 | } |
| 3901 | |
| 3902 | return 0; |
| 3903 | } |
| 3904 | EXPORT_SYMBOL(cfg80211_check_station_change); |
| 3905 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3906 | /* |
Felix Fietkau | c258d2d | 2009-11-11 17:23:31 +0100 | [diff] [blame] | 3907 | * 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] | 3908 | */ |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3909 | static struct net_device *get_vlan(struct genl_info *info, |
| 3910 | struct cfg80211_registered_device *rdev) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3911 | { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3912 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3913 | struct net_device *v; |
| 3914 | int ret; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3915 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3916 | if (!vlanattr) |
| 3917 | return NULL; |
| 3918 | |
| 3919 | v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); |
| 3920 | if (!v) |
| 3921 | return ERR_PTR(-ENODEV); |
| 3922 | |
| 3923 | if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { |
| 3924 | ret = -EINVAL; |
| 3925 | goto error; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3926 | } |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3927 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3928 | if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
| 3929 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3930 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { |
| 3931 | ret = -EINVAL; |
| 3932 | goto error; |
| 3933 | } |
| 3934 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3935 | if (!netif_running(v)) { |
| 3936 | ret = -ENETDOWN; |
| 3937 | goto error; |
| 3938 | } |
| 3939 | |
| 3940 | return v; |
| 3941 | error: |
| 3942 | dev_put(v); |
| 3943 | return ERR_PTR(ret); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3944 | } |
| 3945 | |
Johannes Berg | 94e860f | 2014-01-20 23:58:15 +0100 | [diff] [blame] | 3946 | static const struct nla_policy |
| 3947 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = { |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3948 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, |
| 3949 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, |
| 3950 | }; |
| 3951 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 3952 | static int nl80211_parse_sta_wme(struct genl_info *info, |
| 3953 | struct station_parameters *params) |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3954 | { |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3955 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; |
| 3956 | struct nlattr *nla; |
| 3957 | int err; |
| 3958 | |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3959 | /* parse WME attributes if present */ |
| 3960 | if (!info->attrs[NL80211_ATTR_STA_WME]) |
| 3961 | return 0; |
| 3962 | |
| 3963 | nla = info->attrs[NL80211_ATTR_STA_WME]; |
| 3964 | err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla, |
| 3965 | nl80211_sta_wme_policy); |
| 3966 | if (err) |
| 3967 | return err; |
| 3968 | |
| 3969 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) |
| 3970 | params->uapsd_queues = nla_get_u8( |
| 3971 | tb[NL80211_STA_WME_UAPSD_QUEUES]); |
| 3972 | if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) |
| 3973 | return -EINVAL; |
| 3974 | |
| 3975 | if (tb[NL80211_STA_WME_MAX_SP]) |
| 3976 | params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); |
| 3977 | |
| 3978 | if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) |
| 3979 | return -EINVAL; |
| 3980 | |
| 3981 | params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; |
| 3982 | |
| 3983 | return 0; |
| 3984 | } |
| 3985 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 3986 | static int nl80211_parse_sta_channel_info(struct genl_info *info, |
| 3987 | struct station_parameters *params) |
| 3988 | { |
| 3989 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) { |
| 3990 | params->supported_channels = |
| 3991 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); |
| 3992 | params->supported_channels_len = |
| 3993 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); |
| 3994 | /* |
| 3995 | * Need to include at least one (first channel, number of |
| 3996 | * channels) tuple for each subband, and must have proper |
| 3997 | * tuples for the rest of the data as well. |
| 3998 | */ |
| 3999 | if (params->supported_channels_len < 2) |
| 4000 | return -EINVAL; |
| 4001 | if (params->supported_channels_len % 2) |
| 4002 | return -EINVAL; |
| 4003 | } |
| 4004 | |
| 4005 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) { |
| 4006 | params->supported_oper_classes = |
| 4007 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); |
| 4008 | params->supported_oper_classes_len = |
| 4009 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); |
| 4010 | /* |
| 4011 | * The value of the Length field of the Supported Operating |
| 4012 | * Classes element is between 2 and 253. |
| 4013 | */ |
| 4014 | if (params->supported_oper_classes_len < 2 || |
| 4015 | params->supported_oper_classes_len > 253) |
| 4016 | return -EINVAL; |
| 4017 | } |
| 4018 | return 0; |
| 4019 | } |
| 4020 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4021 | static int nl80211_set_station_tdls(struct genl_info *info, |
| 4022 | struct station_parameters *params) |
| 4023 | { |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 4024 | int err; |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4025 | /* Dummy STA entry gets updated once the peer capabilities are known */ |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 4026 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
| 4027 | params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4028 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 4029 | params->ht_capa = |
| 4030 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
| 4031 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 4032 | params->vht_capa = |
| 4033 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 4034 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 4035 | err = nl80211_parse_sta_channel_info(info, params); |
| 4036 | if (err) |
| 4037 | return err; |
| 4038 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4039 | return nl80211_parse_sta_wme(info, params); |
| 4040 | } |
| 4041 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4042 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
| 4043 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4044 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4045 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4046 | struct station_parameters params; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4047 | u8 *mac_addr; |
| 4048 | int err; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4049 | |
| 4050 | memset(¶ms, 0, sizeof(params)); |
| 4051 | |
| 4052 | params.listen_interval = -1; |
| 4053 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4054 | if (!rdev->ops->change_station) |
| 4055 | return -EOPNOTSUPP; |
| 4056 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4057 | if (info->attrs[NL80211_ATTR_STA_AID]) |
| 4058 | return -EINVAL; |
| 4059 | |
| 4060 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4061 | return -EINVAL; |
| 4062 | |
| 4063 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4064 | |
| 4065 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { |
| 4066 | params.supported_rates = |
| 4067 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4068 | params.supported_rates_len = |
| 4069 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4070 | } |
| 4071 | |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 4072 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
| 4073 | params.capability = |
| 4074 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); |
| 4075 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; |
| 4076 | } |
| 4077 | |
| 4078 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { |
| 4079 | params.ext_capab = |
| 4080 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4081 | params.ext_capab_len = |
| 4082 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4083 | } |
| 4084 | |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 4085 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
Johannes Berg | ba23d20 | 2012-12-27 17:32:09 +0100 | [diff] [blame] | 4086 | return -EINVAL; |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 4087 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 4088 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4089 | return -EINVAL; |
| 4090 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4091 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4092 | params.plink_action = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4093 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 4094 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) |
| 4095 | return -EINVAL; |
| 4096 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4097 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4098 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) { |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 4099 | params.plink_state = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4100 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
| 4101 | if (params.plink_state >= NUM_NL80211_PLINK_STATES) |
| 4102 | return -EINVAL; |
| 4103 | params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE; |
| 4104 | } |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 4105 | |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4106 | if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) { |
| 4107 | enum nl80211_mesh_power_mode pm = nla_get_u32( |
| 4108 | info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]); |
| 4109 | |
| 4110 | if (pm <= NL80211_MESH_POWER_UNKNOWN || |
| 4111 | pm > NL80211_MESH_POWER_MAX) |
| 4112 | return -EINVAL; |
| 4113 | |
| 4114 | params.local_pm = pm; |
| 4115 | } |
| 4116 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4117 | /* Include parameters for TDLS peer (will check later) */ |
| 4118 | err = nl80211_set_station_tdls(info, ¶ms); |
| 4119 | if (err) |
| 4120 | return err; |
| 4121 | |
| 4122 | params.vlan = get_vlan(info, rdev); |
| 4123 | if (IS_ERR(params.vlan)) |
| 4124 | return PTR_ERR(params.vlan); |
| 4125 | |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4126 | switch (dev->ieee80211_ptr->iftype) { |
| 4127 | case NL80211_IFTYPE_AP: |
| 4128 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4129 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4130 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4131 | case NL80211_IFTYPE_STATION: |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 4132 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4133 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4134 | break; |
| 4135 | default: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4136 | err = -EOPNOTSUPP; |
| 4137 | goto out_put_vlan; |
Johannes Berg | 034d655 | 2009-05-27 10:35:29 +0200 | [diff] [blame] | 4138 | } |
| 4139 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4140 | /* driver will call cfg80211_check_station_change() */ |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4141 | err = rdev_change_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4142 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4143 | out_put_vlan: |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4144 | if (params.vlan) |
| 4145 | dev_put(params.vlan); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4146 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4147 | return err; |
| 4148 | } |
| 4149 | |
| 4150 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) |
| 4151 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4152 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4153 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4154 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4155 | struct station_parameters params; |
| 4156 | u8 *mac_addr = NULL; |
| 4157 | |
| 4158 | memset(¶ms, 0, sizeof(params)); |
| 4159 | |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4160 | if (!rdev->ops->add_station) |
| 4161 | return -EOPNOTSUPP; |
| 4162 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4163 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4164 | return -EINVAL; |
| 4165 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4166 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 4167 | return -EINVAL; |
| 4168 | |
| 4169 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) |
| 4170 | return -EINVAL; |
| 4171 | |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 4172 | if (!info->attrs[NL80211_ATTR_STA_AID] && |
| 4173 | !info->attrs[NL80211_ATTR_PEER_AID]) |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 4174 | return -EINVAL; |
| 4175 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4176 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4177 | params.supported_rates = |
| 4178 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4179 | params.supported_rates_len = |
| 4180 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4181 | params.listen_interval = |
| 4182 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 4183 | |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4184 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 4185 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4186 | else |
| 4187 | 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] | 4188 | if (!params.aid || params.aid > IEEE80211_MAX_AID) |
| 4189 | return -EINVAL; |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 4190 | |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 4191 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
| 4192 | params.capability = |
| 4193 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); |
| 4194 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; |
| 4195 | } |
| 4196 | |
| 4197 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { |
| 4198 | params.ext_capab = |
| 4199 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4200 | params.ext_capab_len = |
| 4201 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4202 | } |
| 4203 | |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 4204 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 4205 | params.ht_capa = |
| 4206 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4207 | |
Mahesh Palivela | f461be3e | 2012-10-11 08:04:52 +0000 | [diff] [blame] | 4208 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 4209 | params.vht_capa = |
| 4210 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 4211 | |
Marek Kwaczynski | 60f4a7b | 2013-12-03 10:04:59 +0100 | [diff] [blame] | 4212 | if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) { |
| 4213 | params.opmode_notif_used = true; |
| 4214 | params.opmode_notif = |
| 4215 | nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]); |
| 4216 | } |
| 4217 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4218 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 4219 | params.plink_action = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4220 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 4221 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) |
| 4222 | return -EINVAL; |
| 4223 | } |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 4224 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 4225 | err = nl80211_parse_sta_channel_info(info, ¶ms); |
| 4226 | if (err) |
| 4227 | return err; |
| 4228 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4229 | err = nl80211_parse_sta_wme(info, ¶ms); |
| 4230 | if (err) |
| 4231 | return err; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4232 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 4233 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4234 | return -EINVAL; |
| 4235 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4236 | /* When you run into this, adjust the code below for the new flag */ |
| 4237 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); |
| 4238 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4239 | switch (dev->ieee80211_ptr->iftype) { |
| 4240 | case NL80211_IFTYPE_AP: |
| 4241 | case NL80211_IFTYPE_AP_VLAN: |
| 4242 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4243 | /* ignore WME attributes if iface/sta is not capable */ |
| 4244 | if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) || |
| 4245 | !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) |
| 4246 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4247 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4248 | /* TDLS peers cannot be added */ |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4249 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
| 4250 | info->attrs[NL80211_ATTR_PEER_AID]) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 4251 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4252 | /* but don't bother the driver with it */ |
| 4253 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4254 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4255 | /* allow authenticated/associated only if driver handles it */ |
| 4256 | if (!(rdev->wiphy.features & |
| 4257 | NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
| 4258 | params.sta_flags_mask & |
| 4259 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 4260 | BIT(NL80211_STA_FLAG_ASSOCIATED))) |
| 4261 | return -EINVAL; |
| 4262 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4263 | /* must be last in here for error handling */ |
| 4264 | params.vlan = get_vlan(info, rdev); |
| 4265 | if (IS_ERR(params.vlan)) |
| 4266 | return PTR_ERR(params.vlan); |
| 4267 | break; |
| 4268 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4269 | /* ignore uAPSD data */ |
| 4270 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
| 4271 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4272 | /* associated is disallowed */ |
| 4273 | if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) |
| 4274 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4275 | /* TDLS peers cannot be added */ |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4276 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
| 4277 | info->attrs[NL80211_ATTR_PEER_AID]) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 4278 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4279 | break; |
| 4280 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 93d08f0 | 2013-03-04 09:29:46 +0100 | [diff] [blame] | 4281 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4282 | /* ignore uAPSD data */ |
| 4283 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
| 4284 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4285 | /* these are disallowed */ |
| 4286 | if (params.sta_flags_mask & |
| 4287 | (BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 4288 | BIT(NL80211_STA_FLAG_AUTHENTICATED))) |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4289 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4290 | /* Only TDLS peers can be added */ |
| 4291 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 4292 | return -EINVAL; |
| 4293 | /* Can only add if TDLS ... */ |
| 4294 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) |
| 4295 | return -EOPNOTSUPP; |
| 4296 | /* ... with external setup is supported */ |
| 4297 | if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) |
| 4298 | return -EOPNOTSUPP; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4299 | /* |
| 4300 | * Older wpa_supplicant versions always mark the TDLS peer |
| 4301 | * as authorized, but it shouldn't yet be. |
| 4302 | */ |
| 4303 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED); |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4304 | break; |
| 4305 | default: |
| 4306 | return -EOPNOTSUPP; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4307 | } |
| 4308 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4309 | /* be aware of params.vlan when changing code here */ |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4310 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4311 | err = rdev_add_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4312 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4313 | if (params.vlan) |
| 4314 | dev_put(params.vlan); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4315 | return err; |
| 4316 | } |
| 4317 | |
| 4318 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) |
| 4319 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4320 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4321 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4322 | u8 *mac_addr = NULL; |
| 4323 | |
| 4324 | if (info->attrs[NL80211_ATTR_MAC]) |
| 4325 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4326 | |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 4327 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Marco Porsch | d5d9de0 | 2010-03-30 10:00:16 +0200 | [diff] [blame] | 4328 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4329 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4330 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4331 | return -EINVAL; |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 4332 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4333 | if (!rdev->ops->del_station) |
| 4334 | return -EOPNOTSUPP; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4335 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4336 | return rdev_del_station(rdev, dev, mac_addr); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4337 | } |
| 4338 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4339 | 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] | 4340 | int flags, struct net_device *dev, |
| 4341 | u8 *dst, u8 *next_hop, |
| 4342 | struct mpath_info *pinfo) |
| 4343 | { |
| 4344 | void *hdr; |
| 4345 | struct nlattr *pinfoattr; |
| 4346 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4347 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4348 | if (!hdr) |
| 4349 | return -1; |
| 4350 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4351 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 4352 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || |
| 4353 | nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) || |
| 4354 | nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation)) |
| 4355 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 4356 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4357 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
| 4358 | if (!pinfoattr) |
| 4359 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4360 | if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) && |
| 4361 | nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN, |
| 4362 | pinfo->frame_qlen)) |
| 4363 | goto nla_put_failure; |
| 4364 | if (((pinfo->filled & MPATH_INFO_SN) && |
| 4365 | nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) || |
| 4366 | ((pinfo->filled & MPATH_INFO_METRIC) && |
| 4367 | nla_put_u32(msg, NL80211_MPATH_INFO_METRIC, |
| 4368 | pinfo->metric)) || |
| 4369 | ((pinfo->filled & MPATH_INFO_EXPTIME) && |
| 4370 | nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME, |
| 4371 | pinfo->exptime)) || |
| 4372 | ((pinfo->filled & MPATH_INFO_FLAGS) && |
| 4373 | nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS, |
| 4374 | pinfo->flags)) || |
| 4375 | ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) && |
| 4376 | nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, |
| 4377 | pinfo->discovery_timeout)) || |
| 4378 | ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) && |
| 4379 | nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, |
| 4380 | pinfo->discovery_retries))) |
| 4381 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4382 | |
| 4383 | nla_nest_end(msg, pinfoattr); |
| 4384 | |
| 4385 | return genlmsg_end(msg, hdr); |
| 4386 | |
| 4387 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 4388 | genlmsg_cancel(msg, hdr); |
| 4389 | return -EMSGSIZE; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4390 | } |
| 4391 | |
| 4392 | static int nl80211_dump_mpath(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4393 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4394 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4395 | struct mpath_info pinfo; |
| 4396 | struct cfg80211_registered_device *dev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4397 | struct wireless_dev *wdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4398 | u8 dst[ETH_ALEN]; |
| 4399 | u8 next_hop[ETH_ALEN]; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4400 | int path_idx = cb->args[2]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4401 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4402 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4403 | err = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4404 | if (err) |
| 4405 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4406 | |
| 4407 | if (!dev->ops->dump_mpath) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4408 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4409 | goto out_err; |
| 4410 | } |
| 4411 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4412 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4413 | err = -EOPNOTSUPP; |
Roel Kluin | 0448b5f | 2009-08-22 21:15:49 +0200 | [diff] [blame] | 4414 | goto out_err; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4415 | } |
| 4416 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4417 | while (1) { |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4418 | err = rdev_dump_mpath(dev, wdev->netdev, path_idx, dst, |
| 4419 | next_hop, &pinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4420 | if (err == -ENOENT) |
| 4421 | break; |
| 4422 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4423 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4424 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4425 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4426 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4427 | wdev->netdev, dst, next_hop, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4428 | &pinfo) < 0) |
| 4429 | goto out; |
| 4430 | |
| 4431 | path_idx++; |
| 4432 | } |
| 4433 | |
| 4434 | |
| 4435 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4436 | cb->args[2] = path_idx; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4437 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4438 | out_err: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4439 | nl80211_finish_wdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4440 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4441 | } |
| 4442 | |
| 4443 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4444 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4445 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4446 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4447 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4448 | struct mpath_info pinfo; |
| 4449 | struct sk_buff *msg; |
| 4450 | u8 *dst = NULL; |
| 4451 | u8 next_hop[ETH_ALEN]; |
| 4452 | |
| 4453 | memset(&pinfo, 0, sizeof(pinfo)); |
| 4454 | |
| 4455 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4456 | return -EINVAL; |
| 4457 | |
| 4458 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4459 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4460 | if (!rdev->ops->get_mpath) |
| 4461 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4462 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4463 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4464 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4465 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4466 | err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4467 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4468 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4469 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4470 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4471 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4472 | return -ENOMEM; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4473 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4474 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4475 | dev, dst, next_hop, &pinfo) < 0) { |
| 4476 | nlmsg_free(msg); |
| 4477 | return -ENOBUFS; |
| 4478 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4479 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4480 | return genlmsg_reply(msg, info); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4481 | } |
| 4482 | |
| 4483 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4484 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4485 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4486 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4487 | u8 *dst = NULL; |
| 4488 | u8 *next_hop = NULL; |
| 4489 | |
| 4490 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4491 | return -EINVAL; |
| 4492 | |
| 4493 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 4494 | return -EINVAL; |
| 4495 | |
| 4496 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4497 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 4498 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4499 | if (!rdev->ops->change_mpath) |
| 4500 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4501 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4502 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4503 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4504 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4505 | return rdev_change_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4506 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4507 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4508 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4509 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4510 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4511 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4512 | u8 *dst = NULL; |
| 4513 | u8 *next_hop = NULL; |
| 4514 | |
| 4515 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4516 | return -EINVAL; |
| 4517 | |
| 4518 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 4519 | return -EINVAL; |
| 4520 | |
| 4521 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4522 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 4523 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4524 | if (!rdev->ops->add_mpath) |
| 4525 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4526 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4527 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4528 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4529 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4530 | return rdev_add_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4531 | } |
| 4532 | |
| 4533 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4534 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4535 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4536 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4537 | u8 *dst = NULL; |
| 4538 | |
| 4539 | if (info->attrs[NL80211_ATTR_MAC]) |
| 4540 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4541 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4542 | if (!rdev->ops->del_mpath) |
| 4543 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4544 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4545 | return rdev_del_mpath(rdev, dev, dst); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4546 | } |
| 4547 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4548 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
| 4549 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4550 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4551 | struct net_device *dev = info->user_ptr[1]; |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 4552 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4553 | struct bss_parameters params; |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 4554 | int err; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4555 | |
| 4556 | memset(¶ms, 0, sizeof(params)); |
| 4557 | /* default to not changing parameters */ |
| 4558 | params.use_cts_prot = -1; |
| 4559 | params.use_short_preamble = -1; |
| 4560 | params.use_short_slot_time = -1; |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 4561 | params.ap_isolate = -1; |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 4562 | params.ht_opmode = -1; |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 4563 | params.p2p_ctwindow = -1; |
| 4564 | params.p2p_opp_ps = -1; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4565 | |
| 4566 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) |
| 4567 | params.use_cts_prot = |
| 4568 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); |
| 4569 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) |
| 4570 | params.use_short_preamble = |
| 4571 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); |
| 4572 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) |
| 4573 | params.use_short_slot_time = |
| 4574 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 4575 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 4576 | params.basic_rates = |
| 4577 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 4578 | params.basic_rates_len = |
| 4579 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 4580 | } |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 4581 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
| 4582 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 4583 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
| 4584 | params.ht_opmode = |
| 4585 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4586 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 4587 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 4588 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4589 | return -EINVAL; |
| 4590 | params.p2p_ctwindow = |
| 4591 | nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
| 4592 | if (params.p2p_ctwindow < 0) |
| 4593 | return -EINVAL; |
| 4594 | if (params.p2p_ctwindow != 0 && |
| 4595 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 4596 | return -EINVAL; |
| 4597 | } |
| 4598 | |
| 4599 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 4600 | u8 tmp; |
| 4601 | |
| 4602 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4603 | return -EINVAL; |
| 4604 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
| 4605 | if (tmp > 1) |
| 4606 | return -EINVAL; |
| 4607 | params.p2p_opp_ps = tmp; |
| 4608 | if (params.p2p_opp_ps && |
| 4609 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 4610 | return -EINVAL; |
| 4611 | } |
| 4612 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4613 | if (!rdev->ops->change_bss) |
| 4614 | return -EOPNOTSUPP; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4615 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4616 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4617 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4618 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4619 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 4620 | wdev_lock(wdev); |
| 4621 | err = rdev_change_bss(rdev, dev, ¶ms); |
| 4622 | wdev_unlock(wdev); |
| 4623 | |
| 4624 | return err; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4625 | } |
| 4626 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 4627 | 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] | 4628 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
| 4629 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, |
| 4630 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, |
| 4631 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, |
| 4632 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, |
| 4633 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, |
Janusz Dziedzic | 089027e | 2014-02-21 19:46:12 +0100 | [diff] [blame] | 4634 | [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 }, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4635 | }; |
| 4636 | |
| 4637 | static int parse_reg_rule(struct nlattr *tb[], |
| 4638 | struct ieee80211_reg_rule *reg_rule) |
| 4639 | { |
| 4640 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; |
| 4641 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; |
| 4642 | |
| 4643 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) |
| 4644 | return -EINVAL; |
| 4645 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) |
| 4646 | return -EINVAL; |
| 4647 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) |
| 4648 | return -EINVAL; |
Janusz Dziedzic | b0dfd2e | 2014-02-20 13:52:16 +0100 | [diff] [blame] | 4649 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) |
| 4650 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4651 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) |
| 4652 | return -EINVAL; |
| 4653 | |
| 4654 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); |
| 4655 | |
| 4656 | freq_range->start_freq_khz = |
| 4657 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); |
| 4658 | freq_range->end_freq_khz = |
| 4659 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); |
Janusz Dziedzic | b0dfd2e | 2014-02-20 13:52:16 +0100 | [diff] [blame] | 4660 | freq_range->max_bandwidth_khz = |
| 4661 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4662 | |
| 4663 | power_rule->max_eirp = |
| 4664 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); |
| 4665 | |
| 4666 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) |
| 4667 | power_rule->max_antenna_gain = |
| 4668 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); |
| 4669 | |
Janusz Dziedzic | 089027e | 2014-02-21 19:46:12 +0100 | [diff] [blame] | 4670 | if (tb[NL80211_ATTR_DFS_CAC_TIME]) |
| 4671 | reg_rule->dfs_cac_ms = |
| 4672 | nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]); |
| 4673 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4674 | return 0; |
| 4675 | } |
| 4676 | |
| 4677 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 4678 | { |
| 4679 | int r; |
| 4680 | char *data = NULL; |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4681 | enum nl80211_user_reg_hint_type user_reg_hint_type; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4682 | |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 4683 | /* |
| 4684 | * You should only get this when cfg80211 hasn't yet initialized |
| 4685 | * completely when built-in to the kernel right between the time |
| 4686 | * window between nl80211_init() and regulatory_init(), if that is |
| 4687 | * even possible. |
| 4688 | */ |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4689 | if (unlikely(!rcu_access_pointer(cfg80211_regdomain))) |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 4690 | return -EINPROGRESS; |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 4691 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 4692 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 4693 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4694 | |
| 4695 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 4696 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4697 | if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]) |
| 4698 | user_reg_hint_type = |
| 4699 | nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]); |
| 4700 | else |
| 4701 | user_reg_hint_type = NL80211_USER_REG_HINT_USER; |
| 4702 | |
| 4703 | switch (user_reg_hint_type) { |
| 4704 | case NL80211_USER_REG_HINT_USER: |
| 4705 | case NL80211_USER_REG_HINT_CELL_BASE: |
| 4706 | break; |
| 4707 | default: |
| 4708 | return -EINVAL; |
| 4709 | } |
| 4710 | |
| 4711 | r = regulatory_hint_user(data, user_reg_hint_type); |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 4712 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4713 | return r; |
| 4714 | } |
| 4715 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4716 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4717 | struct genl_info *info) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4718 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4719 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4720 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4721 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 4722 | struct mesh_config cur_params; |
| 4723 | int err = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4724 | void *hdr; |
| 4725 | struct nlattr *pinfoattr; |
| 4726 | struct sk_buff *msg; |
| 4727 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4728 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4729 | return -EOPNOTSUPP; |
| 4730 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4731 | if (!rdev->ops->get_mesh_config) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4732 | return -EOPNOTSUPP; |
Jouni Malinen | f3f9258 | 2009-03-20 17:57:36 +0200 | [diff] [blame] | 4733 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4734 | wdev_lock(wdev); |
| 4735 | /* If not connected, get default parameters */ |
| 4736 | if (!wdev->mesh_id_len) |
| 4737 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); |
| 4738 | else |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4739 | err = rdev_get_mesh_config(rdev, dev, &cur_params); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4740 | wdev_unlock(wdev); |
| 4741 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4742 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4743 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4744 | |
| 4745 | /* Draw up a netlink message to send back */ |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4746 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4747 | if (!msg) |
| 4748 | return -ENOMEM; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4749 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4750 | NL80211_CMD_GET_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4751 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4752 | goto out; |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4753 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4754 | if (!pinfoattr) |
| 4755 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4756 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 4757 | nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 4758 | cur_params.dot11MeshRetryTimeout) || |
| 4759 | nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 4760 | cur_params.dot11MeshConfirmTimeout) || |
| 4761 | nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 4762 | cur_params.dot11MeshHoldingTimeout) || |
| 4763 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 4764 | cur_params.dot11MeshMaxPeerLinks) || |
| 4765 | nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES, |
| 4766 | cur_params.dot11MeshMaxRetries) || |
| 4767 | nla_put_u8(msg, NL80211_MESHCONF_TTL, |
| 4768 | cur_params.dot11MeshTTL) || |
| 4769 | nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL, |
| 4770 | cur_params.element_ttl) || |
| 4771 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 4772 | cur_params.auto_open_plinks) || |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 4773 | nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 4774 | cur_params.dot11MeshNbrOffsetMaxNeighbor) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4775 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 4776 | cur_params.dot11MeshHWMPmaxPREQretries) || |
| 4777 | nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 4778 | cur_params.path_refresh_time) || |
| 4779 | nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 4780 | cur_params.min_discovery_timeout) || |
| 4781 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 4782 | cur_params.dot11MeshHWMPactivePathTimeout) || |
| 4783 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 4784 | cur_params.dot11MeshHWMPpreqMinInterval) || |
| 4785 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
| 4786 | cur_params.dot11MeshHWMPperrMinInterval) || |
| 4787 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 4788 | cur_params.dot11MeshHWMPnetDiameterTraversalTime) || |
| 4789 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 4790 | cur_params.dot11MeshHWMPRootMode) || |
| 4791 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
| 4792 | cur_params.dot11MeshHWMPRannInterval) || |
| 4793 | nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
| 4794 | cur_params.dot11MeshGateAnnouncementProtocol) || |
| 4795 | nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, |
| 4796 | cur_params.dot11MeshForwarding) || |
| 4797 | nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, |
Ashok Nagarajan | 70c33ea | 2012-04-30 14:20:32 -0700 | [diff] [blame] | 4798 | cur_params.rssi_threshold) || |
| 4799 | nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4800 | cur_params.ht_opmode) || |
| 4801 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 4802 | cur_params.dot11MeshHWMPactivePathToRootTimeout) || |
| 4803 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4804 | cur_params.dot11MeshHWMProotInterval) || |
| 4805 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4806 | cur_params.dot11MeshHWMPconfirmationInterval) || |
| 4807 | nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE, |
| 4808 | cur_params.power_mode) || |
| 4809 | nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW, |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 4810 | cur_params.dot11MeshAwakeWindowDuration) || |
| 4811 | nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT, |
| 4812 | cur_params.plink_timeout)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4813 | goto nla_put_failure; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4814 | nla_nest_end(msg, pinfoattr); |
| 4815 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4816 | return genlmsg_reply(msg, info); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4817 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4818 | nla_put_failure: |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4819 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4820 | out: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 4821 | nlmsg_free(msg); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4822 | return -ENOBUFS; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4823 | } |
| 4824 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 4825 | 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] | 4826 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
| 4827 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, |
| 4828 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, |
| 4829 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, |
| 4830 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, |
| 4831 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 4832 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4833 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 4834 | [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4835 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
| 4836 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, |
| 4837 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, |
| 4838 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, |
| 4839 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 4840 | [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4841 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
Javier Cardona | 699403d | 2011-08-09 16:45:09 -0700 | [diff] [blame] | 4842 | [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 }, |
Javier Cardona | 0507e15 | 2011-08-09 16:45:10 -0700 | [diff] [blame] | 4843 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 }, |
Javier Cardona | 16dd726 | 2011-08-09 16:45:11 -0700 | [diff] [blame] | 4844 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | 94f9065 | 2012-01-21 01:02:16 +0800 | [diff] [blame] | 4845 | [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4846 | [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 }, |
| 4847 | [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4848 | [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 }, |
| 4849 | [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4850 | [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 }, |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4851 | [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 }, |
| 4852 | [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 }, |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 4853 | [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4854 | }; |
| 4855 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4856 | static const struct nla_policy |
| 4857 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 4858 | [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4859 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
| 4860 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 4861 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
Colleen Twitty | 6e16d90 | 2013-05-08 11:45:59 -0700 | [diff] [blame] | 4862 | [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 }, |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 4863 | [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG }, |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4864 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4865 | .len = IEEE80211_MAX_DATA_LEN }, |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 4866 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4867 | }; |
| 4868 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4869 | static int nl80211_parse_mesh_config(struct genl_info *info, |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4870 | struct mesh_config *cfg, |
| 4871 | u32 *mask_out) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4872 | { |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4873 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4874 | u32 mask = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4875 | |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4876 | #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \ |
| 4877 | do { \ |
| 4878 | if (tb[attr]) { \ |
| 4879 | if (fn(tb[attr]) < min || fn(tb[attr]) > max) \ |
| 4880 | return -EINVAL; \ |
| 4881 | cfg->param = fn(tb[attr]); \ |
| 4882 | mask |= (1 << (attr - 1)); \ |
| 4883 | } \ |
| 4884 | } while (0) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4885 | |
| 4886 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4887 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4888 | return -EINVAL; |
| 4889 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4890 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4891 | nl80211_meshconf_params_policy)) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4892 | return -EINVAL; |
| 4893 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4894 | /* This makes sure that there aren't more than 32 mesh config |
| 4895 | * parameters (otherwise our bitfield scheme would not work.) */ |
| 4896 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); |
| 4897 | |
| 4898 | /* Fill in the params struct */ |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4899 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4900 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 4901 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4902 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4903 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 4904 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4905 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4906 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 4907 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4908 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4909 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 4910 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4911 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4912 | mask, NL80211_MESHCONF_MAX_RETRIES, |
| 4913 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4914 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4915 | mask, NL80211_MESHCONF_TTL, nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4916 | 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] | 4917 | mask, NL80211_MESHCONF_ELEMENT_TTL, |
| 4918 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4919 | 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] | 4920 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 4921 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4922 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, |
| 4923 | 1, 255, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4924 | NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 4925 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4926 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4927 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 4928 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4929 | 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] | 4930 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 4931 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4932 | 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] | 4933 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 4934 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4935 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
| 4936 | 1, 65535, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4937 | NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 4938 | nla_get_u32); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4939 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4940 | 1, 65535, mask, |
| 4941 | NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4942 | nla_get_u16); |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 4943 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4944 | 1, 65535, mask, |
| 4945 | NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4946 | nla_get_u16); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4947 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4948 | dot11MeshHWMPnetDiameterTraversalTime, |
| 4949 | 1, 65535, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4950 | NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 4951 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4952 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4, |
| 4953 | mask, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 4954 | nla_get_u8); |
| 4955 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535, |
| 4956 | mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4957 | nla_get_u16); |
Rui Paulo | 63c5723 | 2009-11-09 23:46:57 +0000 | [diff] [blame] | 4958 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4959 | dot11MeshGateAnnouncementProtocol, 0, 1, |
| 4960 | mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4961 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4962 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4963 | mask, NL80211_MESHCONF_FORWARDING, |
| 4964 | nla_get_u8); |
Chun-Yeow Yeoh | 83374fe | 2013-07-11 18:24:03 +0800 | [diff] [blame] | 4965 | 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] | 4966 | mask, NL80211_MESHCONF_RSSI_THRESHOLD, |
Chun-Yeow Yeoh | 83374fe | 2013-07-11 18:24:03 +0800 | [diff] [blame] | 4967 | nla_get_s32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4968 | 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] | 4969 | mask, NL80211_MESHCONF_HT_OPMODE, |
| 4970 | nla_get_u16); |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4971 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4972 | 1, 65535, mask, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4973 | NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 4974 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4975 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4976 | mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
| 4977 | nla_get_u16); |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4978 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4979 | dot11MeshHWMPconfirmationInterval, |
| 4980 | 1, 65535, mask, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4981 | NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
| 4982 | nla_get_u16); |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4983 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode, |
| 4984 | NL80211_MESH_POWER_ACTIVE, |
| 4985 | NL80211_MESH_POWER_MAX, |
| 4986 | mask, NL80211_MESHCONF_POWER_MODE, |
| 4987 | nla_get_u32); |
| 4988 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration, |
| 4989 | 0, 65535, mask, |
| 4990 | NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16); |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 4991 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 1, 0xffffffff, |
| 4992 | mask, NL80211_MESHCONF_PLINK_TIMEOUT, |
| 4993 | nla_get_u32); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4994 | if (mask_out) |
| 4995 | *mask_out = mask; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4996 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4997 | return 0; |
| 4998 | |
| 4999 | #undef FILL_IN_MESH_PARAM_IF_SET |
| 5000 | } |
| 5001 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5002 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
| 5003 | struct mesh_setup *setup) |
| 5004 | { |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 5005 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5006 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
| 5007 | |
| 5008 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) |
| 5009 | return -EINVAL; |
| 5010 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, |
| 5011 | info->attrs[NL80211_ATTR_MESH_SETUP], |
| 5012 | nl80211_mesh_setup_params_policy)) |
| 5013 | return -EINVAL; |
| 5014 | |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 5015 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC]) |
| 5016 | setup->sync_method = |
| 5017 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ? |
| 5018 | IEEE80211_SYNC_METHOD_VENDOR : |
| 5019 | IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET; |
| 5020 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5021 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
| 5022 | setup->path_sel_proto = |
| 5023 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? |
| 5024 | IEEE80211_PATH_PROTOCOL_VENDOR : |
| 5025 | IEEE80211_PATH_PROTOCOL_HWMP; |
| 5026 | |
| 5027 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) |
| 5028 | setup->path_metric = |
| 5029 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? |
| 5030 | IEEE80211_PATH_METRIC_VENDOR : |
| 5031 | IEEE80211_PATH_METRIC_AIRTIME; |
| 5032 | |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 5033 | |
| 5034 | if (tb[NL80211_MESH_SETUP_IE]) { |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5035 | struct nlattr *ieattr = |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 5036 | tb[NL80211_MESH_SETUP_IE]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5037 | if (!is_valid_ie_attr(ieattr)) |
| 5038 | return -EINVAL; |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 5039 | setup->ie = nla_data(ieattr); |
| 5040 | setup->ie_len = nla_len(ieattr); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5041 | } |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 5042 | if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] && |
| 5043 | !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM)) |
| 5044 | return -EINVAL; |
| 5045 | setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]); |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 5046 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
| 5047 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 5048 | if (setup->is_secure) |
| 5049 | setup->user_mpm = true; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5050 | |
Colleen Twitty | 6e16d90 | 2013-05-08 11:45:59 -0700 | [diff] [blame] | 5051 | if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) { |
| 5052 | if (!setup->user_mpm) |
| 5053 | return -EINVAL; |
| 5054 | setup->auth_id = |
| 5055 | nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]); |
| 5056 | } |
| 5057 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5058 | return 0; |
| 5059 | } |
| 5060 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5061 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5062 | struct genl_info *info) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5063 | { |
| 5064 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5065 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5066 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5067 | struct mesh_config cfg; |
| 5068 | u32 mask; |
| 5069 | int err; |
| 5070 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5071 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 5072 | return -EOPNOTSUPP; |
| 5073 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5074 | if (!rdev->ops->update_mesh_config) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5075 | return -EOPNOTSUPP; |
| 5076 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5077 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5078 | if (err) |
| 5079 | return err; |
| 5080 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5081 | wdev_lock(wdev); |
| 5082 | if (!wdev->mesh_id_len) |
| 5083 | err = -ENOLINK; |
| 5084 | |
| 5085 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5086 | err = rdev_update_mesh_config(rdev, dev, mask, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5087 | |
| 5088 | wdev_unlock(wdev); |
| 5089 | |
| 5090 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5091 | } |
| 5092 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5093 | static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info) |
| 5094 | { |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5095 | const struct ieee80211_regdomain *regdom; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5096 | struct sk_buff *msg; |
| 5097 | void *hdr = NULL; |
| 5098 | struct nlattr *nl_reg_rules; |
| 5099 | unsigned int i; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5100 | |
| 5101 | if (!cfg80211_regdomain) |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5102 | return -EINVAL; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5103 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 5104 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5105 | if (!msg) |
| 5106 | return -ENOBUFS; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5107 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5108 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5109 | NL80211_CMD_GET_REG); |
| 5110 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 5111 | goto put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5112 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 5113 | if (reg_last_request_cell_base() && |
| 5114 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, |
| 5115 | NL80211_USER_REG_HINT_CELL_BASE)) |
| 5116 | goto nla_put_failure; |
| 5117 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5118 | rcu_read_lock(); |
| 5119 | regdom = rcu_dereference(cfg80211_regdomain); |
| 5120 | |
| 5121 | if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) || |
| 5122 | (regdom->dfs_region && |
| 5123 | nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region))) |
| 5124 | goto nla_put_failure_rcu; |
| 5125 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5126 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
| 5127 | if (!nl_reg_rules) |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5128 | goto nla_put_failure_rcu; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5129 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5130 | for (i = 0; i < regdom->n_reg_rules; i++) { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5131 | struct nlattr *nl_reg_rule; |
| 5132 | const struct ieee80211_reg_rule *reg_rule; |
| 5133 | const struct ieee80211_freq_range *freq_range; |
| 5134 | const struct ieee80211_power_rule *power_rule; |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 5135 | unsigned int max_bandwidth_khz; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5136 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5137 | reg_rule = ®dom->reg_rules[i]; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5138 | freq_range = ®_rule->freq_range; |
| 5139 | power_rule = ®_rule->power_rule; |
| 5140 | |
| 5141 | nl_reg_rule = nla_nest_start(msg, i); |
| 5142 | if (!nl_reg_rule) |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5143 | goto nla_put_failure_rcu; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5144 | |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 5145 | max_bandwidth_khz = freq_range->max_bandwidth_khz; |
| 5146 | if (!max_bandwidth_khz) |
| 5147 | max_bandwidth_khz = reg_get_max_bandwidth(regdom, |
| 5148 | reg_rule); |
| 5149 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5150 | if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
| 5151 | reg_rule->flags) || |
| 5152 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START, |
| 5153 | freq_range->start_freq_khz) || |
| 5154 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END, |
| 5155 | freq_range->end_freq_khz) || |
| 5156 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 5157 | max_bandwidth_khz) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5158 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
| 5159 | power_rule->max_antenna_gain) || |
| 5160 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, |
Janusz Dziedzic | 089027e | 2014-02-21 19:46:12 +0100 | [diff] [blame] | 5161 | power_rule->max_eirp) || |
| 5162 | nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME, |
| 5163 | reg_rule->dfs_cac_ms)) |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5164 | goto nla_put_failure_rcu; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5165 | |
| 5166 | nla_nest_end(msg, nl_reg_rule); |
| 5167 | } |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5168 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5169 | |
| 5170 | nla_nest_end(msg, nl_reg_rules); |
| 5171 | |
| 5172 | genlmsg_end(msg, hdr); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5173 | return genlmsg_reply(msg, info); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5174 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5175 | nla_put_failure_rcu: |
| 5176 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5177 | nla_put_failure: |
| 5178 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 5179 | put_failure: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 5180 | nlmsg_free(msg); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5181 | return -EMSGSIZE; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5182 | } |
| 5183 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5184 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 5185 | { |
| 5186 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; |
| 5187 | struct nlattr *nl_reg_rule; |
| 5188 | char *alpha2 = NULL; |
| 5189 | int rem_reg_rules = 0, r = 0; |
| 5190 | u32 num_rules = 0, rule_idx = 0, size_of_regd; |
Luis R. Rodriguez | 4c7d398 | 2013-11-13 18:54:02 +0100 | [diff] [blame] | 5191 | enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5192 | struct ieee80211_regdomain *rd = NULL; |
| 5193 | |
| 5194 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 5195 | return -EINVAL; |
| 5196 | |
| 5197 | if (!info->attrs[NL80211_ATTR_REG_RULES]) |
| 5198 | return -EINVAL; |
| 5199 | |
| 5200 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 5201 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 5202 | if (info->attrs[NL80211_ATTR_DFS_REGION]) |
| 5203 | dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); |
| 5204 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5205 | 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] | 5206 | rem_reg_rules) { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5207 | num_rules++; |
| 5208 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) |
Luis R. Rodriguez | 4776c6e | 2009-05-13 17:04:39 -0400 | [diff] [blame] | 5209 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5210 | } |
| 5211 | |
Luis R. Rodriguez | e438768 | 2013-11-05 09:18:01 -0800 | [diff] [blame] | 5212 | if (!reg_is_valid_request(alpha2)) |
| 5213 | return -EINVAL; |
| 5214 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5215 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 5216 | num_rules * sizeof(struct ieee80211_reg_rule); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5217 | |
| 5218 | rd = kzalloc(size_of_regd, GFP_KERNEL); |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 5219 | if (!rd) |
| 5220 | return -ENOMEM; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5221 | |
| 5222 | rd->n_reg_rules = num_rules; |
| 5223 | rd->alpha2[0] = alpha2[0]; |
| 5224 | rd->alpha2[1] = alpha2[1]; |
| 5225 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 5226 | /* |
| 5227 | * Disable DFS master mode if the DFS region was |
| 5228 | * not supported or known on this kernel. |
| 5229 | */ |
| 5230 | if (reg_supported_dfs_region(dfs_region)) |
| 5231 | rd->dfs_region = dfs_region; |
| 5232 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5233 | 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] | 5234 | rem_reg_rules) { |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 5235 | r = nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, |
| 5236 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), |
| 5237 | reg_rule_policy); |
| 5238 | if (r) |
| 5239 | goto bad_reg; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5240 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
| 5241 | if (r) |
| 5242 | goto bad_reg; |
| 5243 | |
| 5244 | rule_idx++; |
| 5245 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 5246 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
| 5247 | r = -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5248 | goto bad_reg; |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 5249 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5250 | } |
| 5251 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5252 | r = set_regdom(rd); |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 5253 | /* set_regdom took ownership */ |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 5254 | rd = NULL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5255 | |
Johannes Berg | d2372b3 | 2008-10-24 20:32:20 +0200 | [diff] [blame] | 5256 | bad_reg: |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5257 | kfree(rd); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 5258 | return r; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5259 | } |
| 5260 | |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5261 | static int validate_scan_freqs(struct nlattr *freqs) |
| 5262 | { |
| 5263 | struct nlattr *attr1, *attr2; |
| 5264 | int n_channels = 0, tmp1, tmp2; |
| 5265 | |
| 5266 | nla_for_each_nested(attr1, freqs, tmp1) { |
| 5267 | n_channels++; |
| 5268 | /* |
| 5269 | * Some hardware has a limited channel list for |
| 5270 | * scanning, and it is pretty much nonsensical |
| 5271 | * to scan for a channel twice, so disallow that |
| 5272 | * and don't require drivers to check that the |
| 5273 | * channel list they get isn't longer than what |
| 5274 | * they can scan, as long as they can scan all |
| 5275 | * the channels they registered at once. |
| 5276 | */ |
| 5277 | nla_for_each_nested(attr2, freqs, tmp2) |
| 5278 | if (attr1 != attr2 && |
| 5279 | nla_get_u32(attr1) == nla_get_u32(attr2)) |
| 5280 | return 0; |
| 5281 | } |
| 5282 | |
| 5283 | return n_channels; |
| 5284 | } |
| 5285 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5286 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
| 5287 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5288 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 5289 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5290 | struct cfg80211_scan_request *request; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5291 | struct nlattr *attr; |
| 5292 | struct wiphy *wiphy; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5293 | int err, tmp, n_ssids = 0, n_channels, i; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5294 | size_t ie_len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5295 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5296 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5297 | return -EINVAL; |
| 5298 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5299 | wiphy = &rdev->wiphy; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5300 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5301 | if (!rdev->ops->scan) |
| 5302 | return -EOPNOTSUPP; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5303 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 5304 | if (rdev->scan_req || rdev->scan_msg) { |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5305 | err = -EBUSY; |
| 5306 | goto unlock; |
| 5307 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5308 | |
| 5309 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5310 | n_channels = validate_scan_freqs( |
| 5311 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5312 | if (!n_channels) { |
| 5313 | err = -EINVAL; |
| 5314 | goto unlock; |
| 5315 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5316 | } else { |
Ilan Peer | bdfbec2 | 2014-01-09 11:37:23 +0200 | [diff] [blame] | 5317 | n_channels = ieee80211_get_num_supported_channels(wiphy); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5318 | } |
| 5319 | |
| 5320 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 5321 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) |
| 5322 | n_ssids++; |
| 5323 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5324 | if (n_ssids > wiphy->max_scan_ssids) { |
| 5325 | err = -EINVAL; |
| 5326 | goto unlock; |
| 5327 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5328 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5329 | if (info->attrs[NL80211_ATTR_IE]) |
| 5330 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5331 | else |
| 5332 | ie_len = 0; |
| 5333 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5334 | if (ie_len > wiphy->max_scan_ie_len) { |
| 5335 | err = -EINVAL; |
| 5336 | goto unlock; |
| 5337 | } |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 5338 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5339 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 5340 | + sizeof(*request->ssids) * n_ssids |
| 5341 | + sizeof(*request->channels) * n_channels |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5342 | + ie_len, GFP_KERNEL); |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5343 | if (!request) { |
| 5344 | err = -ENOMEM; |
| 5345 | goto unlock; |
| 5346 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5347 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5348 | if (n_ssids) |
Johannes Berg | 5ba6353 | 2009-08-07 17:54:07 +0200 | [diff] [blame] | 5349 | request->ssids = (void *)&request->channels[n_channels]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5350 | request->n_ssids = n_ssids; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5351 | if (ie_len) { |
| 5352 | if (request->ssids) |
| 5353 | request->ie = (void *)(request->ssids + n_ssids); |
| 5354 | else |
| 5355 | request->ie = (void *)(request->channels + n_channels); |
| 5356 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5357 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5358 | i = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5359 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 5360 | /* user specified, bail out if channel not found */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5361 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5362 | struct ieee80211_channel *chan; |
| 5363 | |
| 5364 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 5365 | |
| 5366 | if (!chan) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5367 | err = -EINVAL; |
| 5368 | goto out_free; |
| 5369 | } |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5370 | |
| 5371 | /* ignore disabled channels */ |
| 5372 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5373 | continue; |
| 5374 | |
| 5375 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5376 | i++; |
| 5377 | } |
| 5378 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5379 | enum ieee80211_band band; |
| 5380 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5381 | /* all channels */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5382 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 5383 | int j; |
| 5384 | if (!wiphy->bands[band]) |
| 5385 | continue; |
| 5386 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5387 | struct ieee80211_channel *chan; |
| 5388 | |
| 5389 | chan = &wiphy->bands[band]->channels[j]; |
| 5390 | |
| 5391 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5392 | continue; |
| 5393 | |
| 5394 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5395 | i++; |
| 5396 | } |
| 5397 | } |
| 5398 | } |
| 5399 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5400 | if (!i) { |
| 5401 | err = -EINVAL; |
| 5402 | goto out_free; |
| 5403 | } |
| 5404 | |
| 5405 | request->n_channels = i; |
| 5406 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5407 | i = 0; |
| 5408 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 5409 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5410 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5411 | err = -EINVAL; |
| 5412 | goto out_free; |
| 5413 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5414 | request->ssids[i].ssid_len = nla_len(attr); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5415 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5416 | i++; |
| 5417 | } |
| 5418 | } |
| 5419 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5420 | if (info->attrs[NL80211_ATTR_IE]) { |
| 5421 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Johannes Berg | de95a54 | 2009-04-01 11:58:36 +0200 | [diff] [blame] | 5422 | memcpy((void *)request->ie, |
| 5423 | nla_data(info->attrs[NL80211_ATTR_IE]), |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5424 | request->ie_len); |
| 5425 | } |
| 5426 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5427 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) |
Johannes Berg | a401d2b | 2011-07-20 00:52:16 +0200 | [diff] [blame] | 5428 | if (wiphy->bands[i]) |
| 5429 | request->rates[i] = |
| 5430 | (1 << wiphy->bands[i]->n_bitrates) - 1; |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5431 | |
| 5432 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { |
| 5433 | nla_for_each_nested(attr, |
| 5434 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], |
| 5435 | tmp) { |
| 5436 | enum ieee80211_band band = nla_type(attr); |
| 5437 | |
Dan Carpenter | 8440462 | 2011-07-29 11:52:18 +0300 | [diff] [blame] | 5438 | if (band < 0 || band >= IEEE80211_NUM_BANDS) { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5439 | err = -EINVAL; |
| 5440 | goto out_free; |
| 5441 | } |
Felix Fietkau | 1b09cd8 | 2013-11-20 19:40:41 +0100 | [diff] [blame] | 5442 | |
| 5443 | if (!wiphy->bands[band]) |
| 5444 | continue; |
| 5445 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5446 | err = ieee80211_get_ratemask(wiphy->bands[band], |
| 5447 | nla_data(attr), |
| 5448 | nla_len(attr), |
| 5449 | &request->rates[band]); |
| 5450 | if (err) |
| 5451 | goto out_free; |
| 5452 | } |
| 5453 | } |
| 5454 | |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5455 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5456 | request->flags = nla_get_u32( |
| 5457 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); |
Johannes Berg | 00c3a6e | 2013-10-26 17:14:38 +0200 | [diff] [blame] | 5458 | if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 5459 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) { |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5460 | err = -EOPNOTSUPP; |
| 5461 | goto out_free; |
| 5462 | } |
| 5463 | } |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5464 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 5465 | request->no_cck = |
| 5466 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 5467 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 5468 | request->wdev = wdev; |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5469 | request->wiphy = &rdev->wiphy; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 5470 | request->scan_start = jiffies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5471 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5472 | rdev->scan_req = request; |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5473 | err = rdev_scan(rdev, request); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5474 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5475 | if (!err) { |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 5476 | nl80211_send_scan_start(rdev, wdev); |
| 5477 | if (wdev->netdev) |
| 5478 | dev_hold(wdev->netdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5479 | } else { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5480 | out_free: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5481 | rdev->scan_req = NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5482 | kfree(request); |
| 5483 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 5484 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5485 | unlock: |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5486 | return err; |
| 5487 | } |
| 5488 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5489 | static int nl80211_start_sched_scan(struct sk_buff *skb, |
| 5490 | struct genl_info *info) |
| 5491 | { |
| 5492 | struct cfg80211_sched_scan_request *request; |
| 5493 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5494 | struct net_device *dev = info->user_ptr[1]; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5495 | struct nlattr *attr; |
| 5496 | struct wiphy *wiphy; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5497 | 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] | 5498 | u32 interval; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5499 | enum ieee80211_band band; |
| 5500 | size_t ie_len; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5501 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 5502 | s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5503 | |
| 5504 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 5505 | !rdev->ops->sched_scan_start) |
| 5506 | return -EOPNOTSUPP; |
| 5507 | |
| 5508 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5509 | return -EINVAL; |
| 5510 | |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 5511 | if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
| 5512 | return -EINVAL; |
| 5513 | |
| 5514 | interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); |
| 5515 | if (interval == 0) |
| 5516 | return -EINVAL; |
| 5517 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5518 | wiphy = &rdev->wiphy; |
| 5519 | |
| 5520 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 5521 | n_channels = validate_scan_freqs( |
| 5522 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
| 5523 | if (!n_channels) |
| 5524 | return -EINVAL; |
| 5525 | } else { |
Ilan Peer | bdfbec2 | 2014-01-09 11:37:23 +0200 | [diff] [blame] | 5526 | n_channels = ieee80211_get_num_supported_channels(wiphy); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5527 | } |
| 5528 | |
| 5529 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 5530 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 5531 | tmp) |
| 5532 | n_ssids++; |
| 5533 | |
Luciano Coelho | 93b6aa6 | 2011-07-13 14:57:28 +0300 | [diff] [blame] | 5534 | if (n_ssids > wiphy->max_sched_scan_ssids) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5535 | return -EINVAL; |
| 5536 | |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 5537 | /* |
| 5538 | * First, count the number of 'real' matchsets. Due to an issue with |
| 5539 | * the old implementation, matchsets containing only the RSSI attribute |
| 5540 | * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default' |
| 5541 | * RSSI for all matchsets, rather than their own matchset for reporting |
| 5542 | * all APs with a strong RSSI. This is needed to be compatible with |
| 5543 | * older userspace that treated a matchset with only the RSSI as the |
| 5544 | * global RSSI for all other matchsets - if there are other matchsets. |
| 5545 | */ |
| 5546 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5547 | nla_for_each_nested(attr, |
| 5548 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 5549 | tmp) { |
| 5550 | struct nlattr *rssi; |
| 5551 | |
| 5552 | err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
| 5553 | nla_data(attr), nla_len(attr), |
| 5554 | nl80211_match_policy); |
| 5555 | if (err) |
| 5556 | return err; |
| 5557 | /* add other standalone attributes here */ |
| 5558 | if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]) { |
| 5559 | n_match_sets++; |
| 5560 | continue; |
| 5561 | } |
| 5562 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; |
| 5563 | if (rssi) |
| 5564 | default_match_rssi = nla_get_s32(rssi); |
| 5565 | } |
| 5566 | } |
| 5567 | |
| 5568 | /* However, if there's no other matchset, add the RSSI one */ |
| 5569 | if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF) |
| 5570 | n_match_sets = 1; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5571 | |
| 5572 | if (n_match_sets > wiphy->max_match_sets) |
| 5573 | return -EINVAL; |
| 5574 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5575 | if (info->attrs[NL80211_ATTR_IE]) |
| 5576 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5577 | else |
| 5578 | ie_len = 0; |
| 5579 | |
Luciano Coelho | 5a865ba | 2011-07-13 14:57:29 +0300 | [diff] [blame] | 5580 | if (ie_len > wiphy->max_sched_scan_ie_len) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5581 | return -EINVAL; |
| 5582 | |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 5583 | if (rdev->sched_scan_req) { |
| 5584 | err = -EINPROGRESS; |
| 5585 | goto out; |
| 5586 | } |
| 5587 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5588 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 5589 | + sizeof(*request->ssids) * n_ssids |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5590 | + sizeof(*request->match_sets) * n_match_sets |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 5591 | + sizeof(*request->channels) * n_channels |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5592 | + ie_len, GFP_KERNEL); |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 5593 | if (!request) { |
| 5594 | err = -ENOMEM; |
| 5595 | goto out; |
| 5596 | } |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5597 | |
| 5598 | if (n_ssids) |
| 5599 | request->ssids = (void *)&request->channels[n_channels]; |
| 5600 | request->n_ssids = n_ssids; |
| 5601 | if (ie_len) { |
| 5602 | if (request->ssids) |
| 5603 | request->ie = (void *)(request->ssids + n_ssids); |
| 5604 | else |
| 5605 | request->ie = (void *)(request->channels + n_channels); |
| 5606 | } |
| 5607 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5608 | if (n_match_sets) { |
| 5609 | if (request->ie) |
| 5610 | request->match_sets = (void *)(request->ie + ie_len); |
| 5611 | else if (request->ssids) |
| 5612 | request->match_sets = |
| 5613 | (void *)(request->ssids + n_ssids); |
| 5614 | else |
| 5615 | request->match_sets = |
| 5616 | (void *)(request->channels + n_channels); |
| 5617 | } |
| 5618 | request->n_match_sets = n_match_sets; |
| 5619 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5620 | i = 0; |
| 5621 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 5622 | /* user specified, bail out if channel not found */ |
| 5623 | nla_for_each_nested(attr, |
| 5624 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], |
| 5625 | tmp) { |
| 5626 | struct ieee80211_channel *chan; |
| 5627 | |
| 5628 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 5629 | |
| 5630 | if (!chan) { |
| 5631 | err = -EINVAL; |
| 5632 | goto out_free; |
| 5633 | } |
| 5634 | |
| 5635 | /* ignore disabled channels */ |
| 5636 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5637 | continue; |
| 5638 | |
| 5639 | request->channels[i] = chan; |
| 5640 | i++; |
| 5641 | } |
| 5642 | } else { |
| 5643 | /* all channels */ |
| 5644 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 5645 | int j; |
| 5646 | if (!wiphy->bands[band]) |
| 5647 | continue; |
| 5648 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
| 5649 | struct ieee80211_channel *chan; |
| 5650 | |
| 5651 | chan = &wiphy->bands[band]->channels[j]; |
| 5652 | |
| 5653 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5654 | continue; |
| 5655 | |
| 5656 | request->channels[i] = chan; |
| 5657 | i++; |
| 5658 | } |
| 5659 | } |
| 5660 | } |
| 5661 | |
| 5662 | if (!i) { |
| 5663 | err = -EINVAL; |
| 5664 | goto out_free; |
| 5665 | } |
| 5666 | |
| 5667 | request->n_channels = i; |
| 5668 | |
| 5669 | i = 0; |
| 5670 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 5671 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 5672 | tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5673 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5674 | err = -EINVAL; |
| 5675 | goto out_free; |
| 5676 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5677 | request->ssids[i].ssid_len = nla_len(attr); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5678 | memcpy(request->ssids[i].ssid, nla_data(attr), |
| 5679 | nla_len(attr)); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5680 | i++; |
| 5681 | } |
| 5682 | } |
| 5683 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5684 | i = 0; |
| 5685 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
| 5686 | nla_for_each_nested(attr, |
| 5687 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
| 5688 | tmp) { |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 5689 | struct nlattr *ssid, *rssi; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5690 | |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 5691 | err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
| 5692 | nla_data(attr), nla_len(attr), |
| 5693 | nl80211_match_policy); |
| 5694 | if (err) |
| 5695 | goto out_free; |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 5696 | ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5697 | if (ssid) { |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 5698 | if (WARN_ON(i >= n_match_sets)) { |
| 5699 | /* this indicates a programming error, |
| 5700 | * the loop above should have verified |
| 5701 | * things properly |
| 5702 | */ |
| 5703 | err = -EINVAL; |
| 5704 | goto out_free; |
| 5705 | } |
| 5706 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5707 | if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) { |
| 5708 | err = -EINVAL; |
| 5709 | goto out_free; |
| 5710 | } |
| 5711 | memcpy(request->match_sets[i].ssid.ssid, |
| 5712 | nla_data(ssid), nla_len(ssid)); |
| 5713 | request->match_sets[i].ssid.ssid_len = |
| 5714 | nla_len(ssid); |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 5715 | /* special attribute - old implemenation w/a */ |
| 5716 | request->match_sets[i].rssi_thold = |
| 5717 | default_match_rssi; |
| 5718 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; |
| 5719 | if (rssi) |
| 5720 | request->match_sets[i].rssi_thold = |
| 5721 | nla_get_s32(rssi); |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5722 | } |
| 5723 | i++; |
| 5724 | } |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 5725 | |
| 5726 | /* there was no other matchset, so the RSSI one is alone */ |
| 5727 | if (i == 0) |
| 5728 | request->match_sets[0].rssi_thold = default_match_rssi; |
| 5729 | |
| 5730 | request->min_rssi_thold = INT_MAX; |
| 5731 | for (i = 0; i < n_match_sets; i++) |
| 5732 | request->min_rssi_thold = |
| 5733 | min(request->match_sets[i].rssi_thold, |
| 5734 | request->min_rssi_thold); |
| 5735 | } else { |
| 5736 | request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5737 | } |
| 5738 | |
Johannes Berg | 9900e48 | 2014-02-04 21:01:25 +0100 | [diff] [blame] | 5739 | if (ie_len) { |
| 5740 | request->ie_len = ie_len; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5741 | memcpy((void *)request->ie, |
| 5742 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 5743 | request->ie_len); |
| 5744 | } |
| 5745 | |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5746 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5747 | request->flags = nla_get_u32( |
| 5748 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); |
Johannes Berg | 00c3a6e | 2013-10-26 17:14:38 +0200 | [diff] [blame] | 5749 | if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 5750 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) { |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5751 | err = -EOPNOTSUPP; |
| 5752 | goto out_free; |
| 5753 | } |
| 5754 | } |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5755 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5756 | request->dev = dev; |
| 5757 | request->wiphy = &rdev->wiphy; |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 5758 | request->interval = interval; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 5759 | request->scan_start = jiffies; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5760 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5761 | err = rdev_sched_scan_start(rdev, dev, request); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5762 | if (!err) { |
| 5763 | rdev->sched_scan_req = request; |
| 5764 | nl80211_send_sched_scan(rdev, dev, |
| 5765 | NL80211_CMD_START_SCHED_SCAN); |
| 5766 | goto out; |
| 5767 | } |
| 5768 | |
| 5769 | out_free: |
| 5770 | kfree(request); |
| 5771 | out: |
| 5772 | return err; |
| 5773 | } |
| 5774 | |
| 5775 | static int nl80211_stop_sched_scan(struct sk_buff *skb, |
| 5776 | struct genl_info *info) |
| 5777 | { |
| 5778 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5779 | |
| 5780 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 5781 | !rdev->ops->sched_scan_stop) |
| 5782 | return -EOPNOTSUPP; |
| 5783 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5784 | return __cfg80211_stop_sched_scan(rdev, false); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5785 | } |
| 5786 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5787 | static int nl80211_start_radar_detection(struct sk_buff *skb, |
| 5788 | struct genl_info *info) |
| 5789 | { |
| 5790 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5791 | struct net_device *dev = info->user_ptr[1]; |
| 5792 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 5793 | struct cfg80211_chan_def chandef; |
Luis R. Rodriguez | 55f7435 | 2013-11-25 20:56:10 +0100 | [diff] [blame] | 5794 | enum nl80211_dfs_regions dfs_region; |
Janusz Dziedzic | 31559f3 | 2014-02-21 19:46:13 +0100 | [diff] [blame] | 5795 | unsigned int cac_time_ms; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5796 | int err; |
| 5797 | |
Luis R. Rodriguez | 55f7435 | 2013-11-25 20:56:10 +0100 | [diff] [blame] | 5798 | dfs_region = reg_get_dfs_region(wdev->wiphy); |
| 5799 | if (dfs_region == NL80211_DFS_UNSET) |
| 5800 | return -EINVAL; |
| 5801 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5802 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 5803 | if (err) |
| 5804 | return err; |
| 5805 | |
Simon Wunderlich | ff311bc | 2013-09-03 19:43:18 +0200 | [diff] [blame] | 5806 | if (netif_carrier_ok(dev)) |
| 5807 | return -EBUSY; |
| 5808 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5809 | if (wdev->cac_started) |
| 5810 | return -EBUSY; |
| 5811 | |
| 5812 | err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef); |
| 5813 | if (err < 0) |
| 5814 | return err; |
| 5815 | |
| 5816 | if (err == 0) |
| 5817 | return -EINVAL; |
| 5818 | |
Janusz Dziedzic | fe7c3a1 | 2013-11-05 14:48:48 +0100 | [diff] [blame] | 5819 | if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef)) |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5820 | return -EINVAL; |
| 5821 | |
| 5822 | if (!rdev->ops->start_radar_detection) |
| 5823 | return -EOPNOTSUPP; |
| 5824 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5825 | err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype, |
| 5826 | chandef.chan, CHAN_MODE_SHARED, |
| 5827 | BIT(chandef.width)); |
| 5828 | if (err) |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5829 | return err; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5830 | |
Janusz Dziedzic | 31559f3 | 2014-02-21 19:46:13 +0100 | [diff] [blame] | 5831 | cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef); |
| 5832 | if (WARN_ON(!cac_time_ms)) |
| 5833 | cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS; |
| 5834 | |
| 5835 | err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef, |
| 5836 | cac_time_ms); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5837 | if (!err) { |
Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 5838 | wdev->chandef = chandef; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5839 | wdev->cac_started = true; |
| 5840 | wdev->cac_start_time = jiffies; |
Janusz Dziedzic | 31559f3 | 2014-02-21 19:46:13 +0100 | [diff] [blame] | 5841 | wdev->cac_time_ms = cac_time_ms; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5842 | } |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5843 | return err; |
| 5844 | } |
| 5845 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5846 | static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info) |
| 5847 | { |
| 5848 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5849 | struct net_device *dev = info->user_ptr[1]; |
| 5850 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 5851 | struct cfg80211_csa_settings params; |
| 5852 | /* csa_attrs is defined static to avoid waste of stack size - this |
| 5853 | * function is called under RTNL lock, so this should not be a problem. |
| 5854 | */ |
| 5855 | static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1]; |
| 5856 | u8 radar_detect_width = 0; |
| 5857 | int err; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5858 | bool need_new_beacon = false; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5859 | |
| 5860 | if (!rdev->ops->channel_switch || |
| 5861 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)) |
| 5862 | return -EOPNOTSUPP; |
| 5863 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5864 | switch (dev->ieee80211_ptr->iftype) { |
| 5865 | case NL80211_IFTYPE_AP: |
| 5866 | case NL80211_IFTYPE_P2P_GO: |
| 5867 | need_new_beacon = true; |
| 5868 | |
| 5869 | /* useless if AP is not running */ |
| 5870 | if (!wdev->beacon_interval) |
Johannes Berg | 1ff79df | 2014-01-22 10:05:27 +0100 | [diff] [blame] | 5871 | return -ENOTCONN; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5872 | break; |
| 5873 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | 1ff79df | 2014-01-22 10:05:27 +0100 | [diff] [blame] | 5874 | if (!wdev->ssid_len) |
| 5875 | return -ENOTCONN; |
| 5876 | break; |
Chun-Yeow Yeoh | c6da674 | 2013-10-14 19:08:28 -0700 | [diff] [blame] | 5877 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 1ff79df | 2014-01-22 10:05:27 +0100 | [diff] [blame] | 5878 | if (!wdev->mesh_id_len) |
| 5879 | return -ENOTCONN; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5880 | break; |
| 5881 | default: |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5882 | return -EOPNOTSUPP; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5883 | } |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5884 | |
| 5885 | memset(¶ms, 0, sizeof(params)); |
| 5886 | |
| 5887 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 5888 | !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]) |
| 5889 | return -EINVAL; |
| 5890 | |
| 5891 | /* only important for AP, IBSS and mesh create IEs internally */ |
Andrei Otcheretianski | d0a361a | 2013-10-17 10:52:17 +0200 | [diff] [blame] | 5892 | if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES]) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5893 | return -EINVAL; |
| 5894 | |
| 5895 | params.count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]); |
| 5896 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5897 | if (!need_new_beacon) |
| 5898 | goto skip_beacons; |
| 5899 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5900 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon_after); |
| 5901 | if (err) |
| 5902 | return err; |
| 5903 | |
| 5904 | err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX, |
| 5905 | info->attrs[NL80211_ATTR_CSA_IES], |
| 5906 | nl80211_policy); |
| 5907 | if (err) |
| 5908 | return err; |
| 5909 | |
| 5910 | err = nl80211_parse_beacon(csa_attrs, ¶ms.beacon_csa); |
| 5911 | if (err) |
| 5912 | return err; |
| 5913 | |
| 5914 | if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]) |
| 5915 | return -EINVAL; |
| 5916 | |
| 5917 | params.counter_offset_beacon = |
| 5918 | nla_get_u16(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); |
| 5919 | if (params.counter_offset_beacon >= params.beacon_csa.tail_len) |
| 5920 | return -EINVAL; |
| 5921 | |
| 5922 | /* sanity check - counters should be the same */ |
| 5923 | if (params.beacon_csa.tail[params.counter_offset_beacon] != |
| 5924 | params.count) |
| 5925 | return -EINVAL; |
| 5926 | |
| 5927 | if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) { |
| 5928 | params.counter_offset_presp = |
| 5929 | nla_get_u16(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); |
| 5930 | if (params.counter_offset_presp >= |
| 5931 | params.beacon_csa.probe_resp_len) |
| 5932 | return -EINVAL; |
| 5933 | |
| 5934 | if (params.beacon_csa.probe_resp[params.counter_offset_presp] != |
| 5935 | params.count) |
| 5936 | return -EINVAL; |
| 5937 | } |
| 5938 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5939 | skip_beacons: |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5940 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
| 5941 | if (err) |
| 5942 | return err; |
| 5943 | |
| 5944 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, ¶ms.chandef)) |
| 5945 | return -EINVAL; |
| 5946 | |
Luciano Coelho | e5d2f95 | 2014-02-20 16:36:20 +0200 | [diff] [blame] | 5947 | switch (dev->ieee80211_ptr->iftype) { |
| 5948 | case NL80211_IFTYPE_AP: |
| 5949 | case NL80211_IFTYPE_P2P_GO: |
| 5950 | case NL80211_IFTYPE_ADHOC: |
| 5951 | case NL80211_IFTYPE_MESH_POINT: |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5952 | err = cfg80211_chandef_dfs_required(wdev->wiphy, |
| 5953 | ¶ms.chandef); |
Luciano Coelho | e5d2f95 | 2014-02-20 16:36:20 +0200 | [diff] [blame] | 5954 | if (err < 0) |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5955 | return err; |
Luciano Coelho | e5d2f95 | 2014-02-20 16:36:20 +0200 | [diff] [blame] | 5956 | if (err) { |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5957 | radar_detect_width = BIT(params.chandef.width); |
| 5958 | params.radar_required = true; |
| 5959 | } |
Luciano Coelho | e5d2f95 | 2014-02-20 16:36:20 +0200 | [diff] [blame] | 5960 | break; |
| 5961 | default: |
| 5962 | break; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5963 | } |
| 5964 | |
| 5965 | err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype, |
| 5966 | params.chandef.chan, |
| 5967 | CHAN_MODE_SHARED, |
| 5968 | radar_detect_width); |
| 5969 | if (err) |
| 5970 | return err; |
| 5971 | |
| 5972 | if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX]) |
| 5973 | params.block_tx = true; |
| 5974 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 5975 | wdev_lock(wdev); |
| 5976 | err = rdev_channel_switch(rdev, dev, ¶ms); |
| 5977 | wdev_unlock(wdev); |
| 5978 | |
| 5979 | return err; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5980 | } |
| 5981 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 5982 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
| 5983 | u32 seq, int flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5984 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5985 | struct wireless_dev *wdev, |
| 5986 | struct cfg80211_internal_bss *intbss) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5987 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5988 | struct cfg80211_bss *res = &intbss->pub; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5989 | const struct cfg80211_bss_ies *ies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5990 | void *hdr; |
| 5991 | struct nlattr *bss; |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5992 | bool tsf = false; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5993 | |
| 5994 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5995 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5996 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5997 | NL80211_CMD_NEW_SCAN_RESULTS); |
| 5998 | if (!hdr) |
| 5999 | return -1; |
| 6000 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 6001 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
| 6002 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6003 | if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation)) |
| 6004 | goto nla_put_failure; |
| 6005 | if (wdev->netdev && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6006 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex)) |
| 6007 | goto nla_put_failure; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6008 | if (nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 6009 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6010 | |
| 6011 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); |
| 6012 | if (!bss) |
| 6013 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6014 | if ((!is_zero_ether_addr(res->bssid) && |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 6015 | nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6016 | goto nla_put_failure; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 6017 | |
| 6018 | rcu_read_lock(); |
| 6019 | ies = rcu_dereference(res->ies); |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 6020 | if (ies) { |
| 6021 | if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf)) |
| 6022 | goto fail_unlock_rcu; |
| 6023 | tsf = true; |
| 6024 | if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS, |
| 6025 | ies->len, ies->data)) |
| 6026 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 6027 | } |
| 6028 | ies = rcu_dereference(res->beacon_ies); |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 6029 | if (ies) { |
| 6030 | if (!tsf && nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf)) |
| 6031 | goto fail_unlock_rcu; |
| 6032 | if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES, |
| 6033 | ies->len, ies->data)) |
| 6034 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 6035 | } |
| 6036 | rcu_read_unlock(); |
| 6037 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6038 | if (res->beacon_interval && |
| 6039 | nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval)) |
| 6040 | goto nla_put_failure; |
| 6041 | if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) || |
| 6042 | nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) || |
Simon Wunderlich | dcd6eac | 2013-07-08 16:55:49 +0200 | [diff] [blame] | 6043 | nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6044 | nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO, |
| 6045 | jiffies_to_msecs(jiffies - intbss->ts))) |
| 6046 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6047 | |
Johannes Berg | 77965c9 | 2009-02-18 18:45:06 +0100 | [diff] [blame] | 6048 | switch (rdev->wiphy.signal_type) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6049 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6050 | if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal)) |
| 6051 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6052 | break; |
| 6053 | case CFG80211_SIGNAL_TYPE_UNSPEC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6054 | if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal)) |
| 6055 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6056 | break; |
| 6057 | default: |
| 6058 | break; |
| 6059 | } |
| 6060 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6061 | switch (wdev->iftype) { |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6062 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6063 | case NL80211_IFTYPE_STATION: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6064 | if (intbss == wdev->current_bss && |
| 6065 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 6066 | NL80211_BSS_STATUS_ASSOCIATED)) |
| 6067 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6068 | break; |
| 6069 | case NL80211_IFTYPE_ADHOC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6070 | if (intbss == wdev->current_bss && |
| 6071 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 6072 | NL80211_BSS_STATUS_IBSS_JOINED)) |
| 6073 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6074 | break; |
| 6075 | default: |
| 6076 | break; |
| 6077 | } |
| 6078 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6079 | nla_nest_end(msg, bss); |
| 6080 | |
| 6081 | return genlmsg_end(msg, hdr); |
| 6082 | |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 6083 | fail_unlock_rcu: |
| 6084 | rcu_read_unlock(); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6085 | nla_put_failure: |
| 6086 | genlmsg_cancel(msg, hdr); |
| 6087 | return -EMSGSIZE; |
| 6088 | } |
| 6089 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6090 | 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] | 6091 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6092 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6093 | struct cfg80211_internal_bss *scan; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6094 | struct wireless_dev *wdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6095 | int start = cb->args[2], idx = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6096 | int err; |
| 6097 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6098 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 6099 | if (err) |
| 6100 | return err; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6101 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6102 | wdev_lock(wdev); |
| 6103 | spin_lock_bh(&rdev->bss_lock); |
| 6104 | cfg80211_bss_expire(rdev); |
| 6105 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 6106 | cb->seq = rdev->bss_generation; |
| 6107 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6108 | list_for_each_entry(scan, &rdev->bss_list, list) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6109 | if (++idx <= start) |
| 6110 | continue; |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 6111 | if (nl80211_send_bss(skb, cb, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6112 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6113 | rdev, wdev, scan) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6114 | idx--; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 6115 | break; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6116 | } |
| 6117 | } |
| 6118 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6119 | spin_unlock_bh(&rdev->bss_lock); |
| 6120 | wdev_unlock(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6121 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6122 | cb->args[2] = idx; |
| 6123 | nl80211_finish_wdev_dump(rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6124 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 6125 | return skb->len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6126 | } |
| 6127 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6128 | 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] | 6129 | int flags, struct net_device *dev, |
| 6130 | struct survey_info *survey) |
| 6131 | { |
| 6132 | void *hdr; |
| 6133 | struct nlattr *infoattr; |
| 6134 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6135 | hdr = nl80211hdr_put(msg, portid, seq, flags, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6136 | NL80211_CMD_NEW_SURVEY_RESULTS); |
| 6137 | if (!hdr) |
| 6138 | return -ENOMEM; |
| 6139 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6140 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
| 6141 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6142 | |
| 6143 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); |
| 6144 | if (!infoattr) |
| 6145 | goto nla_put_failure; |
| 6146 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6147 | if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY, |
| 6148 | survey->channel->center_freq)) |
| 6149 | goto nla_put_failure; |
| 6150 | |
| 6151 | if ((survey->filled & SURVEY_INFO_NOISE_DBM) && |
| 6152 | nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise)) |
| 6153 | goto nla_put_failure; |
| 6154 | if ((survey->filled & SURVEY_INFO_IN_USE) && |
| 6155 | nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE)) |
| 6156 | goto nla_put_failure; |
| 6157 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) && |
| 6158 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME, |
| 6159 | survey->channel_time)) |
| 6160 | goto nla_put_failure; |
| 6161 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) && |
| 6162 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY, |
| 6163 | survey->channel_time_busy)) |
| 6164 | goto nla_put_failure; |
| 6165 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) && |
| 6166 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY, |
| 6167 | survey->channel_time_ext_busy)) |
| 6168 | goto nla_put_failure; |
| 6169 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) && |
| 6170 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX, |
| 6171 | survey->channel_time_rx)) |
| 6172 | goto nla_put_failure; |
| 6173 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) && |
| 6174 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX, |
| 6175 | survey->channel_time_tx)) |
| 6176 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6177 | |
| 6178 | nla_nest_end(msg, infoattr); |
| 6179 | |
| 6180 | return genlmsg_end(msg, hdr); |
| 6181 | |
| 6182 | nla_put_failure: |
| 6183 | genlmsg_cancel(msg, hdr); |
| 6184 | return -EMSGSIZE; |
| 6185 | } |
| 6186 | |
| 6187 | static int nl80211_dump_survey(struct sk_buff *skb, |
| 6188 | struct netlink_callback *cb) |
| 6189 | { |
| 6190 | struct survey_info survey; |
| 6191 | struct cfg80211_registered_device *dev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6192 | struct wireless_dev *wdev; |
| 6193 | int survey_idx = cb->args[2]; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6194 | int res; |
| 6195 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6196 | res = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 6197 | if (res) |
| 6198 | return res; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6199 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6200 | if (!wdev->netdev) { |
| 6201 | res = -EINVAL; |
| 6202 | goto out_err; |
| 6203 | } |
| 6204 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6205 | if (!dev->ops->dump_survey) { |
| 6206 | res = -EOPNOTSUPP; |
| 6207 | goto out_err; |
| 6208 | } |
| 6209 | |
| 6210 | while (1) { |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 6211 | struct ieee80211_channel *chan; |
| 6212 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6213 | res = rdev_dump_survey(dev, wdev->netdev, survey_idx, &survey); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6214 | if (res == -ENOENT) |
| 6215 | break; |
| 6216 | if (res) |
| 6217 | goto out_err; |
| 6218 | |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 6219 | /* Survey without a channel doesn't make sense */ |
| 6220 | if (!survey.channel) { |
| 6221 | res = -EINVAL; |
| 6222 | goto out; |
| 6223 | } |
| 6224 | |
| 6225 | chan = ieee80211_get_channel(&dev->wiphy, |
| 6226 | survey.channel->center_freq); |
| 6227 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) { |
| 6228 | survey_idx++; |
| 6229 | continue; |
| 6230 | } |
| 6231 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6232 | if (nl80211_send_survey(skb, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6233 | NETLINK_CB(cb->skb).portid, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6234 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6235 | wdev->netdev, &survey) < 0) |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6236 | goto out; |
| 6237 | survey_idx++; |
| 6238 | } |
| 6239 | |
| 6240 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6241 | cb->args[2] = survey_idx; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6242 | res = skb->len; |
| 6243 | out_err: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6244 | nl80211_finish_wdev_dump(dev); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6245 | return res; |
| 6246 | } |
| 6247 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6248 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
| 6249 | { |
| 6250 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | |
| 6251 | NL80211_WPA_VERSION_2)); |
| 6252 | } |
| 6253 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6254 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
| 6255 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6256 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6257 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6258 | struct ieee80211_channel *chan; |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 6259 | const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL; |
| 6260 | int err, ssid_len, ie_len = 0, sae_data_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6261 | enum nl80211_auth_type auth_type; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6262 | struct key_parse key; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6263 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6264 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6265 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6266 | return -EINVAL; |
| 6267 | |
| 6268 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6269 | return -EINVAL; |
| 6270 | |
Jouni Malinen | 1778092 | 2009-03-27 20:52:47 +0200 | [diff] [blame] | 6271 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
| 6272 | return -EINVAL; |
| 6273 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6274 | if (!info->attrs[NL80211_ATTR_SSID]) |
| 6275 | return -EINVAL; |
| 6276 | |
| 6277 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 6278 | return -EINVAL; |
| 6279 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6280 | err = nl80211_parse_key(info, &key); |
| 6281 | if (err) |
| 6282 | return err; |
| 6283 | |
| 6284 | if (key.idx >= 0) { |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 6285 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
| 6286 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6287 | if (!key.p.key || !key.p.key_len) |
| 6288 | return -EINVAL; |
| 6289 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || |
| 6290 | key.p.key_len != WLAN_KEY_LEN_WEP40) && |
| 6291 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || |
| 6292 | key.p.key_len != WLAN_KEY_LEN_WEP104)) |
| 6293 | return -EINVAL; |
| 6294 | if (key.idx > 4) |
| 6295 | return -EINVAL; |
| 6296 | } else { |
| 6297 | key.p.key_len = 0; |
| 6298 | key.p.key = NULL; |
| 6299 | } |
| 6300 | |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 6301 | if (key.idx >= 0) { |
| 6302 | int i; |
| 6303 | bool ok = false; |
| 6304 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { |
| 6305 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { |
| 6306 | ok = true; |
| 6307 | break; |
| 6308 | } |
| 6309 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6310 | if (!ok) |
| 6311 | return -EINVAL; |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 6312 | } |
| 6313 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6314 | if (!rdev->ops->auth) |
| 6315 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6316 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6317 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6318 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6319 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6320 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6321 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 6322 | chan = nl80211_get_valid_chan(&rdev->wiphy, |
| 6323 | info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 6324 | if (!chan) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6325 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6326 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6327 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 6328 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 6329 | |
| 6330 | if (info->attrs[NL80211_ATTR_IE]) { |
| 6331 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6332 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 6333 | } |
| 6334 | |
| 6335 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 6336 | if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6337 | return -EINVAL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6338 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 6339 | if (auth_type == NL80211_AUTHTYPE_SAE && |
| 6340 | !info->attrs[NL80211_ATTR_SAE_DATA]) |
| 6341 | return -EINVAL; |
| 6342 | |
| 6343 | if (info->attrs[NL80211_ATTR_SAE_DATA]) { |
| 6344 | if (auth_type != NL80211_AUTHTYPE_SAE) |
| 6345 | return -EINVAL; |
| 6346 | sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]); |
| 6347 | sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]); |
| 6348 | /* need to include at least Auth Transaction and Status Code */ |
| 6349 | if (sae_data_len < 4) |
| 6350 | return -EINVAL; |
| 6351 | } |
| 6352 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6353 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 6354 | |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 6355 | /* |
| 6356 | * Since we no longer track auth state, ignore |
| 6357 | * requests to only change local state. |
| 6358 | */ |
| 6359 | if (local_state_change) |
| 6360 | return 0; |
| 6361 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6362 | wdev_lock(dev->ieee80211_ptr); |
| 6363 | err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, |
| 6364 | ssid, ssid_len, ie, ie_len, |
| 6365 | key.p.key, key.p.key_len, key.idx, |
| 6366 | sae_data, sae_data_len); |
| 6367 | wdev_unlock(dev->ieee80211_ptr); |
| 6368 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6369 | } |
| 6370 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 6371 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 6372 | struct genl_info *info, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 6373 | struct cfg80211_crypto_settings *settings, |
| 6374 | int cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6375 | { |
Johannes Berg | c0b2bbd | 2009-07-25 16:54:36 +0200 | [diff] [blame] | 6376 | memset(settings, 0, sizeof(*settings)); |
| 6377 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6378 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
| 6379 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 6380 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
| 6381 | u16 proto; |
| 6382 | proto = nla_get_u16( |
| 6383 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); |
| 6384 | settings->control_port_ethertype = cpu_to_be16(proto); |
| 6385 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 6386 | proto != ETH_P_PAE) |
| 6387 | return -EINVAL; |
| 6388 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) |
| 6389 | settings->control_port_no_encrypt = true; |
| 6390 | } else |
| 6391 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); |
| 6392 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6393 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
| 6394 | void *data; |
| 6395 | int len, i; |
| 6396 | |
| 6397 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 6398 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 6399 | settings->n_ciphers_pairwise = len / sizeof(u32); |
| 6400 | |
| 6401 | if (len % sizeof(u32)) |
| 6402 | return -EINVAL; |
| 6403 | |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 6404 | if (settings->n_ciphers_pairwise > cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6405 | return -EINVAL; |
| 6406 | |
| 6407 | memcpy(settings->ciphers_pairwise, data, len); |
| 6408 | |
| 6409 | for (i = 0; i < settings->n_ciphers_pairwise; i++) |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 6410 | if (!cfg80211_supported_cipher_suite( |
| 6411 | &rdev->wiphy, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6412 | settings->ciphers_pairwise[i])) |
| 6413 | return -EINVAL; |
| 6414 | } |
| 6415 | |
| 6416 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { |
| 6417 | settings->cipher_group = |
| 6418 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 6419 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
| 6420 | settings->cipher_group)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6421 | return -EINVAL; |
| 6422 | } |
| 6423 | |
| 6424 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { |
| 6425 | settings->wpa_versions = |
| 6426 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); |
| 6427 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) |
| 6428 | return -EINVAL; |
| 6429 | } |
| 6430 | |
| 6431 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { |
| 6432 | void *data; |
Jouni Malinen | 6d30240 | 2011-09-21 18:11:33 +0300 | [diff] [blame] | 6433 | int len; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6434 | |
| 6435 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 6436 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 6437 | settings->n_akm_suites = len / sizeof(u32); |
| 6438 | |
| 6439 | if (len % sizeof(u32)) |
| 6440 | return -EINVAL; |
| 6441 | |
Jouni Malinen | 1b9ca02 | 2011-09-21 16:13:07 +0300 | [diff] [blame] | 6442 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) |
| 6443 | return -EINVAL; |
| 6444 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6445 | memcpy(settings->akm_suites, data, len); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6446 | } |
| 6447 | |
| 6448 | return 0; |
| 6449 | } |
| 6450 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6451 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
| 6452 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6453 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6454 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 6455 | struct ieee80211_channel *chan; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6456 | struct cfg80211_assoc_request req = {}; |
| 6457 | const u8 *bssid, *ssid; |
| 6458 | int err, ssid_len = 0; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6459 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6460 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6461 | return -EINVAL; |
| 6462 | |
| 6463 | if (!info->attrs[NL80211_ATTR_MAC] || |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6464 | !info->attrs[NL80211_ATTR_SSID] || |
| 6465 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6466 | return -EINVAL; |
| 6467 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6468 | if (!rdev->ops->assoc) |
| 6469 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6470 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6471 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6472 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6473 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6474 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6475 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6476 | |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 6477 | chan = nl80211_get_valid_chan(&rdev->wiphy, |
| 6478 | info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 6479 | if (!chan) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6480 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6481 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6482 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 6483 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6484 | |
| 6485 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6486 | req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6487 | req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6488 | } |
| 6489 | |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 6490 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 6491 | enum nl80211_mfp mfp = |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 6492 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 6493 | if (mfp == NL80211_MFP_REQUIRED) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6494 | req.use_mfp = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6495 | else if (mfp != NL80211_MFP_NO) |
| 6496 | return -EINVAL; |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 6497 | } |
| 6498 | |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 6499 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6500 | req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 6501 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6502 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6503 | req.flags |= ASSOC_REQ_DISABLE_HT; |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6504 | |
| 6505 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6506 | memcpy(&req.ht_capa_mask, |
| 6507 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 6508 | sizeof(req.ht_capa_mask)); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6509 | |
| 6510 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6511 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6512 | return -EINVAL; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6513 | memcpy(&req.ht_capa, |
| 6514 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 6515 | sizeof(req.ht_capa)); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6516 | } |
| 6517 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6518 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6519 | req.flags |= ASSOC_REQ_DISABLE_VHT; |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6520 | |
| 6521 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6522 | memcpy(&req.vht_capa_mask, |
| 6523 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), |
| 6524 | sizeof(req.vht_capa_mask)); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6525 | |
| 6526 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6527 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6528 | return -EINVAL; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6529 | memcpy(&req.vht_capa, |
| 6530 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), |
| 6531 | sizeof(req.vht_capa)); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6532 | } |
| 6533 | |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6534 | err = nl80211_crypto_settings(rdev, info, &req.crypto, 1); |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6535 | if (!err) { |
| 6536 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6537 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, |
| 6538 | ssid, ssid_len, &req); |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6539 | wdev_unlock(dev->ieee80211_ptr); |
| 6540 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6541 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6542 | return err; |
| 6543 | } |
| 6544 | |
| 6545 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) |
| 6546 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6547 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6548 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6549 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6550 | int ie_len = 0, err; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6551 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6552 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6553 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6554 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6555 | return -EINVAL; |
| 6556 | |
| 6557 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6558 | return -EINVAL; |
| 6559 | |
| 6560 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 6561 | return -EINVAL; |
| 6562 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6563 | if (!rdev->ops->deauth) |
| 6564 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6565 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6566 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6567 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6568 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6569 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6570 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6571 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6572 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 6573 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6574 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6575 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 6576 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6577 | |
| 6578 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6579 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6580 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6581 | } |
| 6582 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6583 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 6584 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6585 | wdev_lock(dev->ieee80211_ptr); |
| 6586 | err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, |
| 6587 | local_state_change); |
| 6588 | wdev_unlock(dev->ieee80211_ptr); |
| 6589 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6590 | } |
| 6591 | |
| 6592 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) |
| 6593 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6594 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6595 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6596 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6597 | int ie_len = 0, err; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6598 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6599 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6600 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6601 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6602 | return -EINVAL; |
| 6603 | |
| 6604 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6605 | return -EINVAL; |
| 6606 | |
| 6607 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 6608 | return -EINVAL; |
| 6609 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6610 | if (!rdev->ops->disassoc) |
| 6611 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6612 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6613 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6614 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6615 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6616 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6617 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6618 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6619 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 6620 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6621 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6622 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 6623 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6624 | |
| 6625 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6626 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6627 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6628 | } |
| 6629 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6630 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 6631 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6632 | wdev_lock(dev->ieee80211_ptr); |
| 6633 | err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, |
| 6634 | local_state_change); |
| 6635 | wdev_unlock(dev->ieee80211_ptr); |
| 6636 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6637 | } |
| 6638 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 6639 | static bool |
| 6640 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, |
| 6641 | int mcast_rate[IEEE80211_NUM_BANDS], |
| 6642 | int rateval) |
| 6643 | { |
| 6644 | struct wiphy *wiphy = &rdev->wiphy; |
| 6645 | bool found = false; |
| 6646 | int band, i; |
| 6647 | |
| 6648 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 6649 | struct ieee80211_supported_band *sband; |
| 6650 | |
| 6651 | sband = wiphy->bands[band]; |
| 6652 | if (!sband) |
| 6653 | continue; |
| 6654 | |
| 6655 | for (i = 0; i < sband->n_bitrates; i++) { |
| 6656 | if (sband->bitrates[i].bitrate == rateval) { |
| 6657 | mcast_rate[band] = i + 1; |
| 6658 | found = true; |
| 6659 | break; |
| 6660 | } |
| 6661 | } |
| 6662 | } |
| 6663 | |
| 6664 | return found; |
| 6665 | } |
| 6666 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6667 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
| 6668 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6669 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6670 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6671 | struct cfg80211_ibss_params ibss; |
| 6672 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6673 | struct cfg80211_cached_keys *connkeys = NULL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6674 | int err; |
| 6675 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 6676 | memset(&ibss, 0, sizeof(ibss)); |
| 6677 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6678 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6679 | return -EINVAL; |
| 6680 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6681 | if (!info->attrs[NL80211_ATTR_SSID] || |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6682 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 6683 | return -EINVAL; |
| 6684 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 6685 | ibss.beacon_interval = 100; |
| 6686 | |
| 6687 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 6688 | ibss.beacon_interval = |
| 6689 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 6690 | if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000) |
| 6691 | return -EINVAL; |
| 6692 | } |
| 6693 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6694 | if (!rdev->ops->join_ibss) |
| 6695 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6696 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6697 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 6698 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6699 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 6700 | wiphy = &rdev->wiphy; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6701 | |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 6702 | if (info->attrs[NL80211_ATTR_MAC]) { |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6703 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 6704 | |
| 6705 | if (!is_valid_ether_addr(ibss.bssid)) |
| 6706 | return -EINVAL; |
| 6707 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6708 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 6709 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 6710 | |
| 6711 | if (info->attrs[NL80211_ATTR_IE]) { |
| 6712 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6713 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 6714 | } |
| 6715 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6716 | err = nl80211_parse_chandef(rdev, info, &ibss.chandef); |
| 6717 | if (err) |
| 6718 | return err; |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 6719 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6720 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef)) |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 6721 | return -EINVAL; |
| 6722 | |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 6723 | switch (ibss.chandef.width) { |
Simon Wunderlich | bf37264 | 2013-07-08 16:55:58 +0200 | [diff] [blame] | 6724 | case NL80211_CHAN_WIDTH_5: |
| 6725 | case NL80211_CHAN_WIDTH_10: |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 6726 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 6727 | break; |
| 6728 | case NL80211_CHAN_WIDTH_20: |
| 6729 | case NL80211_CHAN_WIDTH_40: |
| 6730 | if (rdev->wiphy.features & NL80211_FEATURE_HT_IBSS) |
| 6731 | break; |
| 6732 | default: |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 6733 | return -EINVAL; |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 6734 | } |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 6735 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6736 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6737 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6738 | |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 6739 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 6740 | u8 *rates = |
| 6741 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 6742 | int n_rates = |
| 6743 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 6744 | struct ieee80211_supported_band *sband = |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6745 | wiphy->bands[ibss.chandef.chan->band]; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 6746 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 6747 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 6748 | &ibss.basic_rates); |
| 6749 | if (err) |
| 6750 | return err; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 6751 | } |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 6752 | |
Simon Wunderlich | 803768f | 2013-06-28 10:39:58 +0200 | [diff] [blame] | 6753 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 6754 | memcpy(&ibss.ht_capa_mask, |
| 6755 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 6756 | sizeof(ibss.ht_capa_mask)); |
| 6757 | |
| 6758 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
| 6759 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 6760 | return -EINVAL; |
| 6761 | memcpy(&ibss.ht_capa, |
| 6762 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 6763 | sizeof(ibss.ht_capa)); |
| 6764 | } |
| 6765 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 6766 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 6767 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, |
| 6768 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 6769 | return -EINVAL; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 6770 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6771 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6772 | bool no_ht = false; |
| 6773 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6774 | connkeys = nl80211_parse_connkeys(rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6775 | info->attrs[NL80211_ATTR_KEYS], |
| 6776 | &no_ht); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6777 | if (IS_ERR(connkeys)) |
| 6778 | return PTR_ERR(connkeys); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6779 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 6780 | if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) && |
| 6781 | no_ht) { |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6782 | kfree(connkeys); |
| 6783 | return -EINVAL; |
| 6784 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6785 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6786 | |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 6787 | ibss.control_port = |
| 6788 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]); |
| 6789 | |
Simon Wunderlich | 5336fa8 | 2013-10-07 18:41:05 +0200 | [diff] [blame] | 6790 | ibss.userspace_handles_dfs = |
| 6791 | nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]); |
| 6792 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6793 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6794 | if (err) |
| 6795 | kfree(connkeys); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6796 | return err; |
| 6797 | } |
| 6798 | |
| 6799 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) |
| 6800 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6801 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6802 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6803 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6804 | if (!rdev->ops->leave_ibss) |
| 6805 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6806 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6807 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 6808 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6809 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6810 | return cfg80211_leave_ibss(rdev, dev, false); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6811 | } |
| 6812 | |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 6813 | static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info) |
| 6814 | { |
| 6815 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6816 | struct net_device *dev = info->user_ptr[1]; |
| 6817 | int mcast_rate[IEEE80211_NUM_BANDS]; |
| 6818 | u32 nla_rate; |
| 6819 | int err; |
| 6820 | |
| 6821 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
| 6822 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 6823 | return -EOPNOTSUPP; |
| 6824 | |
| 6825 | if (!rdev->ops->set_mcast_rate) |
| 6826 | return -EOPNOTSUPP; |
| 6827 | |
| 6828 | memset(mcast_rate, 0, sizeof(mcast_rate)); |
| 6829 | |
| 6830 | if (!info->attrs[NL80211_ATTR_MCAST_RATE]) |
| 6831 | return -EINVAL; |
| 6832 | |
| 6833 | nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]); |
| 6834 | if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate)) |
| 6835 | return -EINVAL; |
| 6836 | |
| 6837 | err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate); |
| 6838 | |
| 6839 | return err; |
| 6840 | } |
| 6841 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 6842 | static struct sk_buff * |
| 6843 | __cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev, |
| 6844 | int approxlen, u32 portid, u32 seq, |
| 6845 | enum nl80211_commands cmd, |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 6846 | enum nl80211_attrs attr, |
| 6847 | const struct nl80211_vendor_cmd_info *info, |
| 6848 | gfp_t gfp) |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 6849 | { |
| 6850 | struct sk_buff *skb; |
| 6851 | void *hdr; |
| 6852 | struct nlattr *data; |
| 6853 | |
| 6854 | skb = nlmsg_new(approxlen + 100, gfp); |
| 6855 | if (!skb) |
| 6856 | return NULL; |
| 6857 | |
| 6858 | hdr = nl80211hdr_put(skb, portid, seq, 0, cmd); |
| 6859 | if (!hdr) { |
| 6860 | kfree_skb(skb); |
| 6861 | return NULL; |
| 6862 | } |
| 6863 | |
| 6864 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 6865 | goto nla_put_failure; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 6866 | |
| 6867 | if (info) { |
| 6868 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID, |
| 6869 | info->vendor_id)) |
| 6870 | goto nla_put_failure; |
| 6871 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD, |
| 6872 | info->subcmd)) |
| 6873 | goto nla_put_failure; |
| 6874 | } |
| 6875 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 6876 | data = nla_nest_start(skb, attr); |
| 6877 | |
| 6878 | ((void **)skb->cb)[0] = rdev; |
| 6879 | ((void **)skb->cb)[1] = hdr; |
| 6880 | ((void **)skb->cb)[2] = data; |
| 6881 | |
| 6882 | return skb; |
| 6883 | |
| 6884 | nla_put_failure: |
| 6885 | kfree_skb(skb); |
| 6886 | return NULL; |
| 6887 | } |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 6888 | |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 6889 | struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy, |
| 6890 | enum nl80211_commands cmd, |
| 6891 | enum nl80211_attrs attr, |
| 6892 | int vendor_event_idx, |
| 6893 | int approxlen, gfp_t gfp) |
| 6894 | { |
| 6895 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 6896 | const struct nl80211_vendor_cmd_info *info; |
| 6897 | |
| 6898 | switch (cmd) { |
| 6899 | case NL80211_CMD_TESTMODE: |
| 6900 | if (WARN_ON(vendor_event_idx != -1)) |
| 6901 | return NULL; |
| 6902 | info = NULL; |
| 6903 | break; |
| 6904 | case NL80211_CMD_VENDOR: |
| 6905 | if (WARN_ON(vendor_event_idx < 0 || |
| 6906 | vendor_event_idx >= wiphy->n_vendor_events)) |
| 6907 | return NULL; |
| 6908 | info = &wiphy->vendor_events[vendor_event_idx]; |
| 6909 | break; |
| 6910 | default: |
| 6911 | WARN_ON(1); |
| 6912 | return NULL; |
| 6913 | } |
| 6914 | |
| 6915 | return __cfg80211_alloc_vendor_skb(rdev, approxlen, 0, 0, |
| 6916 | cmd, attr, info, gfp); |
| 6917 | } |
| 6918 | EXPORT_SYMBOL(__cfg80211_alloc_event_skb); |
| 6919 | |
| 6920 | void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp) |
| 6921 | { |
| 6922 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 6923 | void *hdr = ((void **)skb->cb)[1]; |
| 6924 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 6925 | enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE; |
| 6926 | |
| 6927 | nla_nest_end(skb, data); |
| 6928 | genlmsg_end(skb, hdr); |
| 6929 | |
| 6930 | if (data->nla_type == NL80211_ATTR_VENDOR_DATA) |
| 6931 | mcgrp = NL80211_MCGRP_VENDOR; |
| 6932 | |
| 6933 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0, |
| 6934 | mcgrp, gfp); |
| 6935 | } |
| 6936 | EXPORT_SYMBOL(__cfg80211_send_event_skb); |
| 6937 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6938 | #ifdef CONFIG_NL80211_TESTMODE |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6939 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
| 6940 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6941 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 6942 | struct wireless_dev *wdev = |
| 6943 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6944 | int err; |
| 6945 | |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 6946 | if (!rdev->ops->testmode_cmd) |
| 6947 | return -EOPNOTSUPP; |
| 6948 | |
| 6949 | if (IS_ERR(wdev)) { |
| 6950 | err = PTR_ERR(wdev); |
| 6951 | if (err != -EINVAL) |
| 6952 | return err; |
| 6953 | wdev = NULL; |
| 6954 | } else if (wdev->wiphy != &rdev->wiphy) { |
| 6955 | return -EINVAL; |
| 6956 | } |
| 6957 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6958 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
| 6959 | return -EINVAL; |
| 6960 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 6961 | rdev->cur_cmd_info = info; |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 6962 | err = rdev_testmode_cmd(rdev, wdev, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6963 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
| 6964 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 6965 | rdev->cur_cmd_info = NULL; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6966 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6967 | return err; |
| 6968 | } |
| 6969 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6970 | static int nl80211_testmode_dump(struct sk_buff *skb, |
| 6971 | struct netlink_callback *cb) |
| 6972 | { |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6973 | struct cfg80211_registered_device *rdev; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6974 | int err; |
| 6975 | long phy_idx; |
| 6976 | void *data = NULL; |
| 6977 | int data_len = 0; |
| 6978 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6979 | rtnl_lock(); |
| 6980 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6981 | if (cb->args[0]) { |
| 6982 | /* |
| 6983 | * 0 is a valid index, but not valid for args[0], |
| 6984 | * so we need to offset by 1. |
| 6985 | */ |
| 6986 | phy_idx = cb->args[0] - 1; |
| 6987 | } else { |
| 6988 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 6989 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 6990 | nl80211_policy); |
| 6991 | if (err) |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6992 | goto out_err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6993 | |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 6994 | rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), |
| 6995 | nl80211_fam.attrbuf); |
| 6996 | if (IS_ERR(rdev)) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6997 | err = PTR_ERR(rdev); |
| 6998 | goto out_err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6999 | } |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 7000 | phy_idx = rdev->wiphy_idx; |
| 7001 | rdev = NULL; |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 7002 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7003 | if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]) |
| 7004 | cb->args[1] = |
| 7005 | (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]; |
| 7006 | } |
| 7007 | |
| 7008 | if (cb->args[1]) { |
| 7009 | data = nla_data((void *)cb->args[1]); |
| 7010 | data_len = nla_len((void *)cb->args[1]); |
| 7011 | } |
| 7012 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 7013 | rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
| 7014 | if (!rdev) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 7015 | err = -ENOENT; |
| 7016 | goto out_err; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7017 | } |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7018 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 7019 | if (!rdev->ops->testmode_dump) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7020 | err = -EOPNOTSUPP; |
| 7021 | goto out_err; |
| 7022 | } |
| 7023 | |
| 7024 | while (1) { |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7025 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7026 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 7027 | NL80211_CMD_TESTMODE); |
| 7028 | struct nlattr *tmdata; |
| 7029 | |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 7030 | if (!hdr) |
| 7031 | break; |
| 7032 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7033 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7034 | genlmsg_cancel(skb, hdr); |
| 7035 | break; |
| 7036 | } |
| 7037 | |
| 7038 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 7039 | if (!tmdata) { |
| 7040 | genlmsg_cancel(skb, hdr); |
| 7041 | break; |
| 7042 | } |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7043 | err = rdev_testmode_dump(rdev, skb, cb, data, data_len); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7044 | nla_nest_end(skb, tmdata); |
| 7045 | |
| 7046 | if (err == -ENOBUFS || err == -ENOENT) { |
| 7047 | genlmsg_cancel(skb, hdr); |
| 7048 | break; |
| 7049 | } else if (err) { |
| 7050 | genlmsg_cancel(skb, hdr); |
| 7051 | goto out_err; |
| 7052 | } |
| 7053 | |
| 7054 | genlmsg_end(skb, hdr); |
| 7055 | } |
| 7056 | |
| 7057 | err = skb->len; |
| 7058 | /* see above */ |
| 7059 | cb->args[0] = phy_idx + 1; |
| 7060 | out_err: |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 7061 | rtnl_unlock(); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7062 | return err; |
| 7063 | } |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7064 | #endif |
| 7065 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7066 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
| 7067 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7068 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7069 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7070 | struct cfg80211_connect_params connect; |
| 7071 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7072 | struct cfg80211_cached_keys *connkeys = NULL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7073 | int err; |
| 7074 | |
| 7075 | memset(&connect, 0, sizeof(connect)); |
| 7076 | |
| 7077 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 7078 | return -EINVAL; |
| 7079 | |
| 7080 | if (!info->attrs[NL80211_ATTR_SSID] || |
| 7081 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 7082 | return -EINVAL; |
| 7083 | |
| 7084 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 7085 | connect.auth_type = |
| 7086 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 7087 | if (!nl80211_valid_auth_type(rdev, connect.auth_type, |
| 7088 | NL80211_CMD_CONNECT)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7089 | return -EINVAL; |
| 7090 | } else |
| 7091 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 7092 | |
| 7093 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; |
| 7094 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 7095 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 7096 | NL80211_MAX_NR_CIPHER_SUITES); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7097 | if (err) |
| 7098 | return err; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7099 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7100 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7101 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7102 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7103 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 7104 | wiphy = &rdev->wiphy; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7105 | |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 7106 | connect.bg_scan_period = -1; |
| 7107 | if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] && |
| 7108 | (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) { |
| 7109 | connect.bg_scan_period = |
| 7110 | nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]); |
| 7111 | } |
| 7112 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7113 | if (info->attrs[NL80211_ATTR_MAC]) |
| 7114 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 7115 | else if (info->attrs[NL80211_ATTR_MAC_HINT]) |
| 7116 | connect.bssid_hint = |
| 7117 | nla_data(info->attrs[NL80211_ATTR_MAC_HINT]); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7118 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 7119 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 7120 | |
| 7121 | if (info->attrs[NL80211_ATTR_IE]) { |
| 7122 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 7123 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 7124 | } |
| 7125 | |
Jouni Malinen | cee00a9 | 2013-01-15 17:15:57 +0200 | [diff] [blame] | 7126 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
| 7127 | connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
| 7128 | if (connect.mfp != NL80211_MFP_REQUIRED && |
| 7129 | connect.mfp != NL80211_MFP_NO) |
| 7130 | return -EINVAL; |
| 7131 | } else { |
| 7132 | connect.mfp = NL80211_MFP_NO; |
| 7133 | } |
| 7134 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7135 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 7136 | connect.channel = nl80211_get_valid_chan( |
| 7137 | wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 7138 | if (!connect.channel) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7139 | return -EINVAL; |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 7140 | } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) { |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 7141 | connect.channel_hint = nl80211_get_valid_chan( |
| 7142 | wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]); |
| 7143 | if (!connect.channel_hint) |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 7144 | return -EINVAL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7145 | } |
| 7146 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7147 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
| 7148 | connkeys = nl80211_parse_connkeys(rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 7149 | info->attrs[NL80211_ATTR_KEYS], NULL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7150 | if (IS_ERR(connkeys)) |
| 7151 | return PTR_ERR(connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7152 | } |
| 7153 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 7154 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
| 7155 | connect.flags |= ASSOC_REQ_DISABLE_HT; |
| 7156 | |
| 7157 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 7158 | memcpy(&connect.ht_capa_mask, |
| 7159 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 7160 | sizeof(connect.ht_capa_mask)); |
| 7161 | |
| 7162 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 7163 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) { |
| 7164 | kfree(connkeys); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 7165 | return -EINVAL; |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 7166 | } |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 7167 | memcpy(&connect.ht_capa, |
| 7168 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 7169 | sizeof(connect.ht_capa)); |
| 7170 | } |
| 7171 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 7172 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
| 7173 | connect.flags |= ASSOC_REQ_DISABLE_VHT; |
| 7174 | |
| 7175 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
| 7176 | memcpy(&connect.vht_capa_mask, |
| 7177 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), |
| 7178 | sizeof(connect.vht_capa_mask)); |
| 7179 | |
| 7180 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { |
| 7181 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) { |
| 7182 | kfree(connkeys); |
| 7183 | return -EINVAL; |
| 7184 | } |
| 7185 | memcpy(&connect.vht_capa, |
| 7186 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), |
| 7187 | sizeof(connect.vht_capa)); |
| 7188 | } |
| 7189 | |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7190 | wdev_lock(dev->ieee80211_ptr); |
| 7191 | err = cfg80211_connect(rdev, dev, &connect, connkeys, NULL); |
| 7192 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7193 | if (err) |
| 7194 | kfree(connkeys); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7195 | return err; |
| 7196 | } |
| 7197 | |
| 7198 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) |
| 7199 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7200 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7201 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7202 | u16 reason; |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7203 | int ret; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7204 | |
| 7205 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 7206 | reason = WLAN_REASON_DEAUTH_LEAVING; |
| 7207 | else |
| 7208 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 7209 | |
| 7210 | if (reason == 0) |
| 7211 | return -EINVAL; |
| 7212 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7213 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7214 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7215 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7216 | |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7217 | wdev_lock(dev->ieee80211_ptr); |
| 7218 | ret = cfg80211_disconnect(rdev, dev, reason, true); |
| 7219 | wdev_unlock(dev->ieee80211_ptr); |
| 7220 | return ret; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7221 | } |
| 7222 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7223 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
| 7224 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7225 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7226 | struct net *net; |
| 7227 | int err; |
| 7228 | u32 pid; |
| 7229 | |
| 7230 | if (!info->attrs[NL80211_ATTR_PID]) |
| 7231 | return -EINVAL; |
| 7232 | |
| 7233 | pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); |
| 7234 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7235 | net = get_net_ns_by_pid(pid); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7236 | if (IS_ERR(net)) |
| 7237 | return PTR_ERR(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7238 | |
| 7239 | err = 0; |
| 7240 | |
| 7241 | /* check if anything to do */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7242 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
| 7243 | err = cfg80211_switch_netns(rdev, net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7244 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7245 | put_net(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7246 | return err; |
| 7247 | } |
| 7248 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7249 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 7250 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7251 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7252 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
| 7253 | struct cfg80211_pmksa *pmksa) = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7254 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7255 | struct cfg80211_pmksa pmksa; |
| 7256 | |
| 7257 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); |
| 7258 | |
| 7259 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 7260 | return -EINVAL; |
| 7261 | |
| 7262 | if (!info->attrs[NL80211_ATTR_PMKID]) |
| 7263 | return -EINVAL; |
| 7264 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7265 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
| 7266 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 7267 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7268 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7269 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7270 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7271 | |
| 7272 | switch (info->genlhdr->cmd) { |
| 7273 | case NL80211_CMD_SET_PMKSA: |
| 7274 | rdev_ops = rdev->ops->set_pmksa; |
| 7275 | break; |
| 7276 | case NL80211_CMD_DEL_PMKSA: |
| 7277 | rdev_ops = rdev->ops->del_pmksa; |
| 7278 | break; |
| 7279 | default: |
| 7280 | WARN_ON(1); |
| 7281 | break; |
| 7282 | } |
| 7283 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7284 | if (!rdev_ops) |
| 7285 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7286 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7287 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7288 | } |
| 7289 | |
| 7290 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 7291 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7292 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7293 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7294 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7295 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7296 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7297 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7298 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7299 | if (!rdev->ops->flush_pmksa) |
| 7300 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7301 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7302 | return rdev_flush_pmksa(rdev, dev); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7303 | } |
| 7304 | |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7305 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) |
| 7306 | { |
| 7307 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7308 | struct net_device *dev = info->user_ptr[1]; |
| 7309 | u8 action_code, dialog_token; |
Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 7310 | u32 peer_capability = 0; |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7311 | u16 status_code; |
| 7312 | u8 *peer; |
| 7313 | |
| 7314 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 7315 | !rdev->ops->tdls_mgmt) |
| 7316 | return -EOPNOTSUPP; |
| 7317 | |
| 7318 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || |
| 7319 | !info->attrs[NL80211_ATTR_STATUS_CODE] || |
| 7320 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || |
| 7321 | !info->attrs[NL80211_ATTR_IE] || |
| 7322 | !info->attrs[NL80211_ATTR_MAC]) |
| 7323 | return -EINVAL; |
| 7324 | |
| 7325 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 7326 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); |
| 7327 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); |
| 7328 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); |
Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 7329 | if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]) |
| 7330 | peer_capability = |
| 7331 | nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7332 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7333 | return rdev_tdls_mgmt(rdev, dev, peer, action_code, |
Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 7334 | dialog_token, status_code, peer_capability, |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7335 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 7336 | nla_len(info->attrs[NL80211_ATTR_IE])); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7337 | } |
| 7338 | |
| 7339 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) |
| 7340 | { |
| 7341 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7342 | struct net_device *dev = info->user_ptr[1]; |
| 7343 | enum nl80211_tdls_operation operation; |
| 7344 | u8 *peer; |
| 7345 | |
| 7346 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 7347 | !rdev->ops->tdls_oper) |
| 7348 | return -EOPNOTSUPP; |
| 7349 | |
| 7350 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || |
| 7351 | !info->attrs[NL80211_ATTR_MAC]) |
| 7352 | return -EINVAL; |
| 7353 | |
| 7354 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); |
| 7355 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 7356 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7357 | return rdev_tdls_oper(rdev, dev, peer, operation); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7358 | } |
| 7359 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7360 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
| 7361 | struct genl_info *info) |
| 7362 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7363 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7364 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7365 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7366 | struct sk_buff *msg; |
| 7367 | void *hdr; |
| 7368 | u64 cookie; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7369 | u32 duration; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7370 | int err; |
| 7371 | |
| 7372 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 7373 | !info->attrs[NL80211_ATTR_DURATION]) |
| 7374 | return -EINVAL; |
| 7375 | |
| 7376 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
| 7377 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 7378 | if (!rdev->ops->remain_on_channel || |
| 7379 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7380 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7381 | |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 7382 | /* |
| 7383 | * We should be on that channel for at least a minimum amount of |
| 7384 | * time (10ms) but no longer than the driver supports. |
| 7385 | */ |
| 7386 | if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 7387 | duration > rdev->wiphy.max_remain_on_channel_duration) |
| 7388 | return -EINVAL; |
| 7389 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7390 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 7391 | if (err) |
| 7392 | return err; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7393 | |
| 7394 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7395 | if (!msg) |
| 7396 | return -ENOMEM; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7397 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7398 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7399 | NL80211_CMD_REMAIN_ON_CHANNEL); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 7400 | if (!hdr) { |
| 7401 | err = -ENOBUFS; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7402 | goto free_msg; |
| 7403 | } |
| 7404 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7405 | err = rdev_remain_on_channel(rdev, wdev, chandef.chan, |
| 7406 | duration, &cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7407 | |
| 7408 | if (err) |
| 7409 | goto free_msg; |
| 7410 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7411 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 7412 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7413 | |
| 7414 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7415 | |
| 7416 | return genlmsg_reply(msg, info); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7417 | |
| 7418 | nla_put_failure: |
| 7419 | err = -ENOBUFS; |
| 7420 | free_msg: |
| 7421 | nlmsg_free(msg); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7422 | return err; |
| 7423 | } |
| 7424 | |
| 7425 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, |
| 7426 | struct genl_info *info) |
| 7427 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7428 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7429 | struct wireless_dev *wdev = info->user_ptr[1]; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7430 | u64 cookie; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7431 | |
| 7432 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 7433 | return -EINVAL; |
| 7434 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7435 | if (!rdev->ops->cancel_remain_on_channel) |
| 7436 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7437 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7438 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 7439 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7440 | return rdev_cancel_remain_on_channel(rdev, wdev, cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7441 | } |
| 7442 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7443 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
| 7444 | u8 *rates, u8 rates_len) |
| 7445 | { |
| 7446 | u8 i; |
| 7447 | u32 mask = 0; |
| 7448 | |
| 7449 | for (i = 0; i < rates_len; i++) { |
| 7450 | int rate = (rates[i] & 0x7f) * 5; |
| 7451 | int ridx; |
| 7452 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { |
| 7453 | struct ieee80211_rate *srate = |
| 7454 | &sband->bitrates[ridx]; |
| 7455 | if (rate == srate->bitrate) { |
| 7456 | mask |= 1 << ridx; |
| 7457 | break; |
| 7458 | } |
| 7459 | } |
| 7460 | if (ridx == sband->n_bitrates) |
| 7461 | return 0; /* rate not found */ |
| 7462 | } |
| 7463 | |
| 7464 | return mask; |
| 7465 | } |
| 7466 | |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7467 | static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, |
| 7468 | u8 *rates, u8 rates_len, |
| 7469 | u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) |
| 7470 | { |
| 7471 | u8 i; |
| 7472 | |
| 7473 | memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); |
| 7474 | |
| 7475 | for (i = 0; i < rates_len; i++) { |
| 7476 | int ridx, rbit; |
| 7477 | |
| 7478 | ridx = rates[i] / 8; |
| 7479 | rbit = BIT(rates[i] % 8); |
| 7480 | |
| 7481 | /* check validity */ |
Dan Carpenter | 910570b5 | 2012-02-01 10:42:11 +0300 | [diff] [blame] | 7482 | if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7483 | return false; |
| 7484 | |
| 7485 | /* check availability */ |
| 7486 | if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) |
| 7487 | mcs[ridx] |= rbit; |
| 7488 | else |
| 7489 | return false; |
| 7490 | } |
| 7491 | |
| 7492 | return true; |
| 7493 | } |
| 7494 | |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 7495 | static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map) |
| 7496 | { |
| 7497 | u16 mcs_mask = 0; |
| 7498 | |
| 7499 | switch (vht_mcs_map) { |
| 7500 | case IEEE80211_VHT_MCS_NOT_SUPPORTED: |
| 7501 | break; |
| 7502 | case IEEE80211_VHT_MCS_SUPPORT_0_7: |
| 7503 | mcs_mask = 0x00FF; |
| 7504 | break; |
| 7505 | case IEEE80211_VHT_MCS_SUPPORT_0_8: |
| 7506 | mcs_mask = 0x01FF; |
| 7507 | break; |
| 7508 | case IEEE80211_VHT_MCS_SUPPORT_0_9: |
| 7509 | mcs_mask = 0x03FF; |
| 7510 | break; |
| 7511 | default: |
| 7512 | break; |
| 7513 | } |
| 7514 | |
| 7515 | return mcs_mask; |
| 7516 | } |
| 7517 | |
| 7518 | static void vht_build_mcs_mask(u16 vht_mcs_map, |
| 7519 | u16 vht_mcs_mask[NL80211_VHT_NSS_MAX]) |
| 7520 | { |
| 7521 | u8 nss; |
| 7522 | |
| 7523 | for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) { |
| 7524 | vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03); |
| 7525 | vht_mcs_map >>= 2; |
| 7526 | } |
| 7527 | } |
| 7528 | |
| 7529 | static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband, |
| 7530 | struct nl80211_txrate_vht *txrate, |
| 7531 | u16 mcs[NL80211_VHT_NSS_MAX]) |
| 7532 | { |
| 7533 | u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); |
| 7534 | u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {}; |
| 7535 | u8 i; |
| 7536 | |
| 7537 | if (!sband->vht_cap.vht_supported) |
| 7538 | return false; |
| 7539 | |
| 7540 | memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX); |
| 7541 | |
| 7542 | /* Build vht_mcs_mask from VHT capabilities */ |
| 7543 | vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask); |
| 7544 | |
| 7545 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) { |
| 7546 | if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i]) |
| 7547 | mcs[i] = txrate->mcs[i]; |
| 7548 | else |
| 7549 | return false; |
| 7550 | } |
| 7551 | |
| 7552 | return true; |
| 7553 | } |
| 7554 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 7555 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7556 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
| 7557 | .len = NL80211_MAX_SUPP_RATES }, |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 7558 | [NL80211_TXRATE_HT] = { .type = NLA_BINARY, |
| 7559 | .len = NL80211_MAX_SUPP_HT_RATES }, |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 7560 | [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)}, |
Janusz Dziedzic | 0b9323f | 2014-01-08 08:46:02 +0100 | [diff] [blame] | 7561 | [NL80211_TXRATE_GI] = { .type = NLA_U8 }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7562 | }; |
| 7563 | |
| 7564 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, |
| 7565 | struct genl_info *info) |
| 7566 | { |
| 7567 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7568 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7569 | struct cfg80211_bitrate_mask mask; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7570 | int rem, i; |
| 7571 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7572 | struct nlattr *tx_rates; |
| 7573 | struct ieee80211_supported_band *sband; |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 7574 | u16 vht_tx_mcs_map; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7575 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7576 | if (!rdev->ops->set_bitrate_mask) |
| 7577 | return -EOPNOTSUPP; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7578 | |
| 7579 | memset(&mask, 0, sizeof(mask)); |
| 7580 | /* Default to all rates enabled */ |
| 7581 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) { |
| 7582 | sband = rdev->wiphy.bands[i]; |
Janusz Dziedzic | 7869303 | 2013-12-03 09:50:44 +0100 | [diff] [blame] | 7583 | |
| 7584 | if (!sband) |
| 7585 | continue; |
| 7586 | |
| 7587 | mask.control[i].legacy = (1 << sband->n_bitrates) - 1; |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 7588 | memcpy(mask.control[i].ht_mcs, |
Janusz Dziedzic | 7869303 | 2013-12-03 09:50:44 +0100 | [diff] [blame] | 7589 | sband->ht_cap.mcs.rx_mask, |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 7590 | sizeof(mask.control[i].ht_mcs)); |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 7591 | |
| 7592 | if (!sband->vht_cap.vht_supported) |
| 7593 | continue; |
| 7594 | |
| 7595 | vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); |
| 7596 | 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] | 7597 | } |
| 7598 | |
Janusz Dziedzic | b9243ab | 2013-12-05 10:02:14 +0100 | [diff] [blame] | 7599 | /* if no rates are given set it back to the defaults */ |
| 7600 | if (!info->attrs[NL80211_ATTR_TX_RATES]) |
| 7601 | goto out; |
| 7602 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7603 | /* |
| 7604 | * The nested attribute uses enum nl80211_band as the index. This maps |
| 7605 | * directly to the enum ieee80211_band values used in cfg80211. |
| 7606 | */ |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7607 | BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8); |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 7608 | nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) { |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7609 | enum ieee80211_band band = nla_type(tx_rates); |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 7610 | int err; |
| 7611 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7612 | if (band < 0 || band >= IEEE80211_NUM_BANDS) |
| 7613 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7614 | sband = rdev->wiphy.bands[band]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7615 | if (sband == NULL) |
| 7616 | return -EINVAL; |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 7617 | err = nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), |
| 7618 | nla_len(tx_rates), nl80211_txattr_policy); |
| 7619 | if (err) |
| 7620 | return err; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7621 | if (tb[NL80211_TXRATE_LEGACY]) { |
| 7622 | mask.control[band].legacy = rateset_to_mask( |
| 7623 | sband, |
| 7624 | nla_data(tb[NL80211_TXRATE_LEGACY]), |
| 7625 | nla_len(tb[NL80211_TXRATE_LEGACY])); |
Bala Shanmugam | 218d2e2 | 2012-04-20 19:12:58 +0530 | [diff] [blame] | 7626 | if ((mask.control[band].legacy == 0) && |
| 7627 | nla_len(tb[NL80211_TXRATE_LEGACY])) |
| 7628 | return -EINVAL; |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7629 | } |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 7630 | if (tb[NL80211_TXRATE_HT]) { |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7631 | if (!ht_rateset_to_mask( |
| 7632 | sband, |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 7633 | nla_data(tb[NL80211_TXRATE_HT]), |
| 7634 | nla_len(tb[NL80211_TXRATE_HT]), |
| 7635 | mask.control[band].ht_mcs)) |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7636 | return -EINVAL; |
| 7637 | } |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 7638 | if (tb[NL80211_TXRATE_VHT]) { |
| 7639 | if (!vht_set_mcs_mask( |
| 7640 | sband, |
| 7641 | nla_data(tb[NL80211_TXRATE_VHT]), |
| 7642 | mask.control[band].vht_mcs)) |
| 7643 | return -EINVAL; |
| 7644 | } |
Janusz Dziedzic | 0b9323f | 2014-01-08 08:46:02 +0100 | [diff] [blame] | 7645 | if (tb[NL80211_TXRATE_GI]) { |
| 7646 | mask.control[band].gi = |
| 7647 | nla_get_u8(tb[NL80211_TXRATE_GI]); |
| 7648 | if (mask.control[band].gi > NL80211_TXRATE_FORCE_LGI) |
| 7649 | return -EINVAL; |
| 7650 | } |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7651 | |
| 7652 | if (mask.control[band].legacy == 0) { |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 7653 | /* don't allow empty legacy rates if HT or VHT |
| 7654 | * are not even supported. |
| 7655 | */ |
| 7656 | if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported || |
| 7657 | rdev->wiphy.bands[band]->vht_cap.vht_supported)) |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7658 | return -EINVAL; |
| 7659 | |
| 7660 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 7661 | if (mask.control[band].ht_mcs[i]) |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 7662 | goto out; |
| 7663 | |
| 7664 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) |
| 7665 | if (mask.control[band].vht_mcs[i]) |
| 7666 | goto out; |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7667 | |
| 7668 | /* legacy and mcs rates may not be both empty */ |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 7669 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7670 | } |
| 7671 | } |
| 7672 | |
Janusz Dziedzic | b9243ab | 2013-12-05 10:02:14 +0100 | [diff] [blame] | 7673 | out: |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7674 | return rdev_set_bitrate_mask(rdev, dev, NULL, &mask); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7675 | } |
| 7676 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7677 | 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] | 7678 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7679 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7680 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7681 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7682 | |
| 7683 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) |
| 7684 | return -EINVAL; |
| 7685 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7686 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
| 7687 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7688 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7689 | switch (wdev->iftype) { |
| 7690 | case NL80211_IFTYPE_STATION: |
| 7691 | case NL80211_IFTYPE_ADHOC: |
| 7692 | case NL80211_IFTYPE_P2P_CLIENT: |
| 7693 | case NL80211_IFTYPE_AP: |
| 7694 | case NL80211_IFTYPE_AP_VLAN: |
| 7695 | case NL80211_IFTYPE_MESH_POINT: |
| 7696 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7697 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7698 | break; |
| 7699 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7700 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7701 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7702 | |
| 7703 | /* not much point in registering if we can't reply */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7704 | if (!rdev->ops->mgmt_tx) |
| 7705 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7706 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7707 | return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7708 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
| 7709 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7710 | } |
| 7711 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7712 | 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] | 7713 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7714 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7715 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7716 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7717 | int err; |
Johannes Berg | d64d373 | 2011-11-10 09:44:46 +0100 | [diff] [blame] | 7718 | void *hdr = NULL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7719 | u64 cookie; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7720 | struct sk_buff *msg = NULL; |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7721 | struct cfg80211_mgmt_tx_params params = { |
| 7722 | .dont_wait_for_ack = |
| 7723 | info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK], |
| 7724 | }; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7725 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7726 | if (!info->attrs[NL80211_ATTR_FRAME]) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7727 | return -EINVAL; |
| 7728 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7729 | if (!rdev->ops->mgmt_tx) |
| 7730 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7731 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7732 | switch (wdev->iftype) { |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 7733 | case NL80211_IFTYPE_P2P_DEVICE: |
| 7734 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 7735 | return -EINVAL; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7736 | case NL80211_IFTYPE_STATION: |
| 7737 | case NL80211_IFTYPE_ADHOC: |
| 7738 | case NL80211_IFTYPE_P2P_CLIENT: |
| 7739 | case NL80211_IFTYPE_AP: |
| 7740 | case NL80211_IFTYPE_AP_VLAN: |
| 7741 | case NL80211_IFTYPE_MESH_POINT: |
| 7742 | case NL80211_IFTYPE_P2P_GO: |
| 7743 | break; |
| 7744 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7745 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7746 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7747 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7748 | if (info->attrs[NL80211_ATTR_DURATION]) { |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 7749 | if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7750 | return -EINVAL; |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7751 | params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 7752 | |
| 7753 | /* |
| 7754 | * We should wait on the channel for at least a minimum amount |
| 7755 | * of time (10ms) but no longer than the driver supports. |
| 7756 | */ |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7757 | if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 7758 | params.wait > rdev->wiphy.max_remain_on_channel_duration) |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 7759 | return -EINVAL; |
| 7760 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7761 | } |
| 7762 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7763 | params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7764 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7765 | if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 7766 | return -EINVAL; |
| 7767 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7768 | 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] | 7769 | |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 7770 | /* get the channel if any has been specified, otherwise pass NULL to |
| 7771 | * the driver. The latter will use the current one |
| 7772 | */ |
| 7773 | chandef.chan = NULL; |
| 7774 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 7775 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 7776 | if (err) |
| 7777 | return err; |
| 7778 | } |
| 7779 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7780 | if (!chandef.chan && params.offchan) |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 7781 | return -EINVAL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7782 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7783 | if (!params.dont_wait_for_ack) { |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7784 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 7785 | if (!msg) |
| 7786 | return -ENOMEM; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7787 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7788 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7789 | NL80211_CMD_FRAME); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 7790 | if (!hdr) { |
| 7791 | err = -ENOBUFS; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7792 | goto free_msg; |
| 7793 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7794 | } |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7795 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7796 | params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]); |
| 7797 | params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]); |
| 7798 | params.chan = chandef.chan; |
| 7799 | err = cfg80211_mlme_mgmt_tx(rdev, wdev, ¶ms, &cookie); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7800 | if (err) |
| 7801 | goto free_msg; |
| 7802 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7803 | if (msg) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7804 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 7805 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7806 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7807 | genlmsg_end(msg, hdr); |
| 7808 | return genlmsg_reply(msg, info); |
| 7809 | } |
| 7810 | |
| 7811 | return 0; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7812 | |
| 7813 | nla_put_failure: |
| 7814 | err = -ENOBUFS; |
| 7815 | free_msg: |
| 7816 | nlmsg_free(msg); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7817 | return err; |
| 7818 | } |
| 7819 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7820 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
| 7821 | { |
| 7822 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7823 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7824 | u64 cookie; |
| 7825 | |
| 7826 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 7827 | return -EINVAL; |
| 7828 | |
| 7829 | if (!rdev->ops->mgmt_tx_cancel_wait) |
| 7830 | return -EOPNOTSUPP; |
| 7831 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7832 | switch (wdev->iftype) { |
| 7833 | case NL80211_IFTYPE_STATION: |
| 7834 | case NL80211_IFTYPE_ADHOC: |
| 7835 | case NL80211_IFTYPE_P2P_CLIENT: |
| 7836 | case NL80211_IFTYPE_AP: |
| 7837 | case NL80211_IFTYPE_AP_VLAN: |
| 7838 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7839 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7840 | break; |
| 7841 | default: |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7842 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7843 | } |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7844 | |
| 7845 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 7846 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7847 | return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie); |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7848 | } |
| 7849 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7850 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
| 7851 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7852 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7853 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7854 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7855 | u8 ps_state; |
| 7856 | bool state; |
| 7857 | int err; |
| 7858 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7859 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
| 7860 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7861 | |
| 7862 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); |
| 7863 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7864 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
| 7865 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7866 | |
| 7867 | wdev = dev->ieee80211_ptr; |
| 7868 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7869 | if (!rdev->ops->set_power_mgmt) |
| 7870 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7871 | |
| 7872 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; |
| 7873 | |
| 7874 | if (state == wdev->ps) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7875 | return 0; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7876 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7877 | err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7878 | if (!err) |
| 7879 | wdev->ps = state; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7880 | return err; |
| 7881 | } |
| 7882 | |
| 7883 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) |
| 7884 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7885 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7886 | enum nl80211_ps_state ps_state; |
| 7887 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7888 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7889 | struct sk_buff *msg; |
| 7890 | void *hdr; |
| 7891 | int err; |
| 7892 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7893 | wdev = dev->ieee80211_ptr; |
| 7894 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7895 | if (!rdev->ops->set_power_mgmt) |
| 7896 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7897 | |
| 7898 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7899 | if (!msg) |
| 7900 | return -ENOMEM; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7901 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7902 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7903 | NL80211_CMD_GET_POWER_SAVE); |
| 7904 | if (!hdr) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7905 | err = -ENOBUFS; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7906 | goto free_msg; |
| 7907 | } |
| 7908 | |
| 7909 | if (wdev->ps) |
| 7910 | ps_state = NL80211_PS_ENABLED; |
| 7911 | else |
| 7912 | ps_state = NL80211_PS_DISABLED; |
| 7913 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7914 | if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) |
| 7915 | goto nla_put_failure; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7916 | |
| 7917 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7918 | return genlmsg_reply(msg, info); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7919 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7920 | nla_put_failure: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7921 | err = -ENOBUFS; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7922 | free_msg: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7923 | nlmsg_free(msg); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7924 | return err; |
| 7925 | } |
| 7926 | |
Johannes Berg | 94e860f | 2014-01-20 23:58:15 +0100 | [diff] [blame] | 7927 | static const struct nla_policy |
| 7928 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = { |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7929 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, |
| 7930 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, |
| 7931 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7932 | [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 }, |
| 7933 | [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 }, |
| 7934 | [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7935 | }; |
| 7936 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7937 | static int nl80211_set_cqm_txe(struct genl_info *info, |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 7938 | u32 rate, u32 pkts, u32 intvl) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7939 | { |
| 7940 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7941 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 7942 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7943 | |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 7944 | if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7945 | return -EINVAL; |
| 7946 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7947 | if (!rdev->ops->set_cqm_txe_config) |
| 7948 | return -EOPNOTSUPP; |
| 7949 | |
| 7950 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
| 7951 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7952 | return -EOPNOTSUPP; |
| 7953 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7954 | return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7955 | } |
| 7956 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7957 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
| 7958 | s32 threshold, u32 hysteresis) |
| 7959 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7960 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7961 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 7962 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7963 | |
| 7964 | if (threshold > 0) |
| 7965 | return -EINVAL; |
| 7966 | |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 7967 | /* disabling - hysteresis should also be zero then */ |
| 7968 | if (threshold == 0) |
| 7969 | hysteresis = 0; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7970 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7971 | if (!rdev->ops->set_cqm_rssi_config) |
| 7972 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7973 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7974 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7975 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7976 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7977 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7978 | return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7979 | } |
| 7980 | |
| 7981 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) |
| 7982 | { |
| 7983 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; |
| 7984 | struct nlattr *cqm; |
| 7985 | int err; |
| 7986 | |
| 7987 | cqm = info->attrs[NL80211_ATTR_CQM]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 7988 | if (!cqm) |
| 7989 | return -EINVAL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7990 | |
| 7991 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, |
| 7992 | nl80211_attr_cqm_policy); |
| 7993 | if (err) |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 7994 | return err; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7995 | |
| 7996 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && |
| 7997 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 7998 | s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
| 7999 | u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8000 | |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 8001 | return nl80211_set_cqm_rssi(info, threshold, hysteresis); |
| 8002 | } |
| 8003 | |
| 8004 | if (attrs[NL80211_ATTR_CQM_TXE_RATE] && |
| 8005 | attrs[NL80211_ATTR_CQM_TXE_PKTS] && |
| 8006 | attrs[NL80211_ATTR_CQM_TXE_INTVL]) { |
| 8007 | u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]); |
| 8008 | u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]); |
| 8009 | u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]); |
| 8010 | |
| 8011 | return nl80211_set_cqm_txe(info, rate, pkts, intvl); |
| 8012 | } |
| 8013 | |
| 8014 | return -EINVAL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8015 | } |
| 8016 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8017 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
| 8018 | { |
| 8019 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8020 | struct net_device *dev = info->user_ptr[1]; |
| 8021 | struct mesh_config cfg; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 8022 | struct mesh_setup setup; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8023 | int err; |
| 8024 | |
| 8025 | /* start with default */ |
| 8026 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 8027 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8028 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 8029 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8030 | /* and parse parameters if given */ |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 8031 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8032 | if (err) |
| 8033 | return err; |
| 8034 | } |
| 8035 | |
| 8036 | if (!info->attrs[NL80211_ATTR_MESH_ID] || |
| 8037 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) |
| 8038 | return -EINVAL; |
| 8039 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 8040 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
| 8041 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 8042 | |
Chun-Yeow Yeoh | 4bb6234 | 2011-11-24 17:15:20 -0800 | [diff] [blame] | 8043 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 8044 | !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, |
| 8045 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 8046 | return -EINVAL; |
| 8047 | |
Marco Porsch | 9bdbf04 | 2013-01-07 16:04:51 +0100 | [diff] [blame] | 8048 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 8049 | setup.beacon_interval = |
| 8050 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 8051 | if (setup.beacon_interval < 10 || |
| 8052 | setup.beacon_interval > 10000) |
| 8053 | return -EINVAL; |
| 8054 | } |
| 8055 | |
| 8056 | if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) { |
| 8057 | setup.dtim_period = |
| 8058 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 8059 | if (setup.dtim_period < 1 || setup.dtim_period > 100) |
| 8060 | return -EINVAL; |
| 8061 | } |
| 8062 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 8063 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
| 8064 | /* parse additional setup parameters if given */ |
| 8065 | err = nl80211_parse_mesh_setup(info, &setup); |
| 8066 | if (err) |
| 8067 | return err; |
| 8068 | } |
| 8069 | |
Thomas Pedersen | d37bb18 | 2013-03-04 13:06:13 -0800 | [diff] [blame] | 8070 | if (setup.user_mpm) |
| 8071 | cfg.auto_open_plinks = false; |
| 8072 | |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 8073 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 8074 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
| 8075 | if (err) |
| 8076 | return err; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 8077 | } else { |
| 8078 | /* cfg80211_join_mesh() will sort it out */ |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 8079 | setup.chandef.chan = NULL; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 8080 | } |
| 8081 | |
Ashok Nagarajan | ffb3cf3 | 2013-06-03 10:33:36 -0700 | [diff] [blame] | 8082 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 8083 | u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 8084 | int n_rates = |
| 8085 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 8086 | struct ieee80211_supported_band *sband; |
| 8087 | |
| 8088 | if (!setup.chandef.chan) |
| 8089 | return -EINVAL; |
| 8090 | |
| 8091 | sband = rdev->wiphy.bands[setup.chandef.chan->band]; |
| 8092 | |
| 8093 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 8094 | &setup.basic_rates); |
| 8095 | if (err) |
| 8096 | return err; |
| 8097 | } |
| 8098 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 8099 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8100 | } |
| 8101 | |
| 8102 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) |
| 8103 | { |
| 8104 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8105 | struct net_device *dev = info->user_ptr[1]; |
| 8106 | |
| 8107 | return cfg80211_leave_mesh(rdev, dev); |
| 8108 | } |
| 8109 | |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 8110 | #ifdef CONFIG_PM |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8111 | static int nl80211_send_wowlan_patterns(struct sk_buff *msg, |
| 8112 | struct cfg80211_registered_device *rdev) |
| 8113 | { |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8114 | struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config; |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8115 | struct nlattr *nl_pats, *nl_pat; |
| 8116 | int i, pat_len; |
| 8117 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8118 | if (!wowlan->n_patterns) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8119 | return 0; |
| 8120 | |
| 8121 | nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN); |
| 8122 | if (!nl_pats) |
| 8123 | return -ENOBUFS; |
| 8124 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8125 | for (i = 0; i < wowlan->n_patterns; i++) { |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8126 | nl_pat = nla_nest_start(msg, i + 1); |
| 8127 | if (!nl_pat) |
| 8128 | return -ENOBUFS; |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8129 | pat_len = wowlan->patterns[i].pattern_len; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8130 | 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] | 8131 | wowlan->patterns[i].mask) || |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8132 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
| 8133 | wowlan->patterns[i].pattern) || |
| 8134 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8135 | wowlan->patterns[i].pkt_offset)) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8136 | return -ENOBUFS; |
| 8137 | nla_nest_end(msg, nl_pat); |
| 8138 | } |
| 8139 | nla_nest_end(msg, nl_pats); |
| 8140 | |
| 8141 | return 0; |
| 8142 | } |
| 8143 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8144 | static int nl80211_send_wowlan_tcp(struct sk_buff *msg, |
| 8145 | struct cfg80211_wowlan_tcp *tcp) |
| 8146 | { |
| 8147 | struct nlattr *nl_tcp; |
| 8148 | |
| 8149 | if (!tcp) |
| 8150 | return 0; |
| 8151 | |
| 8152 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); |
| 8153 | if (!nl_tcp) |
| 8154 | return -ENOBUFS; |
| 8155 | |
| 8156 | if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) || |
| 8157 | nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) || |
| 8158 | nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) || |
| 8159 | nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) || |
| 8160 | nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) || |
| 8161 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 8162 | tcp->payload_len, tcp->payload) || |
| 8163 | nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, |
| 8164 | tcp->data_interval) || |
| 8165 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, |
| 8166 | tcp->wake_len, tcp->wake_data) || |
| 8167 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK, |
| 8168 | DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask)) |
| 8169 | return -ENOBUFS; |
| 8170 | |
| 8171 | if (tcp->payload_seq.len && |
| 8172 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ, |
| 8173 | sizeof(tcp->payload_seq), &tcp->payload_seq)) |
| 8174 | return -ENOBUFS; |
| 8175 | |
| 8176 | if (tcp->payload_tok.len && |
| 8177 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, |
| 8178 | sizeof(tcp->payload_tok) + tcp->tokens_size, |
| 8179 | &tcp->payload_tok)) |
| 8180 | return -ENOBUFS; |
| 8181 | |
Johannes Berg | e248ad3 | 2013-05-16 10:24:28 +0200 | [diff] [blame] | 8182 | nla_nest_end(msg, nl_tcp); |
| 8183 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8184 | return 0; |
| 8185 | } |
| 8186 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8187 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 8188 | { |
| 8189 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8190 | struct sk_buff *msg; |
| 8191 | void *hdr; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8192 | u32 size = NLMSG_DEFAULT_SIZE; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8193 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8194 | if (!rdev->wiphy.wowlan) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8195 | return -EOPNOTSUPP; |
| 8196 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8197 | if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) { |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8198 | /* adjust size to have room for all the data */ |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8199 | size += rdev->wiphy.wowlan_config->tcp->tokens_size + |
| 8200 | rdev->wiphy.wowlan_config->tcp->payload_len + |
| 8201 | rdev->wiphy.wowlan_config->tcp->wake_len + |
| 8202 | rdev->wiphy.wowlan_config->tcp->wake_len / 8; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8203 | } |
| 8204 | |
| 8205 | msg = nlmsg_new(size, GFP_KERNEL); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8206 | if (!msg) |
| 8207 | return -ENOMEM; |
| 8208 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8209 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8210 | NL80211_CMD_GET_WOWLAN); |
| 8211 | if (!hdr) |
| 8212 | goto nla_put_failure; |
| 8213 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8214 | if (rdev->wiphy.wowlan_config) { |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8215 | struct nlattr *nl_wowlan; |
| 8216 | |
| 8217 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
| 8218 | if (!nl_wowlan) |
| 8219 | goto nla_put_failure; |
| 8220 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8221 | if ((rdev->wiphy.wowlan_config->any && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8222 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8223 | (rdev->wiphy.wowlan_config->disconnect && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8224 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8225 | (rdev->wiphy.wowlan_config->magic_pkt && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8226 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8227 | (rdev->wiphy.wowlan_config->gtk_rekey_failure && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8228 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8229 | (rdev->wiphy.wowlan_config->eap_identity_req && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8230 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8231 | (rdev->wiphy.wowlan_config->four_way_handshake && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8232 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8233 | (rdev->wiphy.wowlan_config->rfkill_release && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8234 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 8235 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8236 | |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8237 | if (nl80211_send_wowlan_patterns(msg, rdev)) |
| 8238 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8239 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8240 | if (nl80211_send_wowlan_tcp(msg, |
| 8241 | rdev->wiphy.wowlan_config->tcp)) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8242 | goto nla_put_failure; |
| 8243 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8244 | nla_nest_end(msg, nl_wowlan); |
| 8245 | } |
| 8246 | |
| 8247 | genlmsg_end(msg, hdr); |
| 8248 | return genlmsg_reply(msg, info); |
| 8249 | |
| 8250 | nla_put_failure: |
| 8251 | nlmsg_free(msg); |
| 8252 | return -ENOBUFS; |
| 8253 | } |
| 8254 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8255 | static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev, |
| 8256 | struct nlattr *attr, |
| 8257 | struct cfg80211_wowlan *trig) |
| 8258 | { |
| 8259 | struct nlattr *tb[NUM_NL80211_WOWLAN_TCP]; |
| 8260 | struct cfg80211_wowlan_tcp *cfg; |
| 8261 | struct nl80211_wowlan_tcp_data_token *tok = NULL; |
| 8262 | struct nl80211_wowlan_tcp_data_seq *seq = NULL; |
| 8263 | u32 size; |
| 8264 | u32 data_size, wake_size, tokens_size = 0, wake_mask_size; |
| 8265 | int err, port; |
| 8266 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8267 | if (!rdev->wiphy.wowlan->tcp) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8268 | return -EINVAL; |
| 8269 | |
| 8270 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP, |
| 8271 | nla_data(attr), nla_len(attr), |
| 8272 | nl80211_wowlan_tcp_policy); |
| 8273 | if (err) |
| 8274 | return err; |
| 8275 | |
| 8276 | if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] || |
| 8277 | !tb[NL80211_WOWLAN_TCP_DST_IPV4] || |
| 8278 | !tb[NL80211_WOWLAN_TCP_DST_MAC] || |
| 8279 | !tb[NL80211_WOWLAN_TCP_DST_PORT] || |
| 8280 | !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] || |
| 8281 | !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] || |
| 8282 | !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] || |
| 8283 | !tb[NL80211_WOWLAN_TCP_WAKE_MASK]) |
| 8284 | return -EINVAL; |
| 8285 | |
| 8286 | data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8287 | if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8288 | return -EINVAL; |
| 8289 | |
| 8290 | if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) > |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8291 | rdev->wiphy.wowlan->tcp->data_interval_max || |
Johannes Berg | 723d568 | 2013-02-26 13:56:40 +0100 | [diff] [blame] | 8292 | nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8293 | return -EINVAL; |
| 8294 | |
| 8295 | wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8296 | if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8297 | return -EINVAL; |
| 8298 | |
| 8299 | wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]); |
| 8300 | if (wake_mask_size != DIV_ROUND_UP(wake_size, 8)) |
| 8301 | return -EINVAL; |
| 8302 | |
| 8303 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) { |
| 8304 | u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 8305 | |
| 8306 | tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 8307 | tokens_size = tokln - sizeof(*tok); |
| 8308 | |
| 8309 | if (!tok->len || tokens_size % tok->len) |
| 8310 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8311 | if (!rdev->wiphy.wowlan->tcp->tok) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8312 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8313 | if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8314 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8315 | if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8316 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8317 | if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8318 | return -EINVAL; |
| 8319 | if (tok->offset + tok->len > data_size) |
| 8320 | return -EINVAL; |
| 8321 | } |
| 8322 | |
| 8323 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) { |
| 8324 | seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8325 | if (!rdev->wiphy.wowlan->tcp->seq) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8326 | return -EINVAL; |
| 8327 | if (seq->len == 0 || seq->len > 4) |
| 8328 | return -EINVAL; |
| 8329 | if (seq->len + seq->offset > data_size) |
| 8330 | return -EINVAL; |
| 8331 | } |
| 8332 | |
| 8333 | size = sizeof(*cfg); |
| 8334 | size += data_size; |
| 8335 | size += wake_size + wake_mask_size; |
| 8336 | size += tokens_size; |
| 8337 | |
| 8338 | cfg = kzalloc(size, GFP_KERNEL); |
| 8339 | if (!cfg) |
| 8340 | return -ENOMEM; |
| 8341 | cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]); |
| 8342 | cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]); |
| 8343 | memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]), |
| 8344 | ETH_ALEN); |
| 8345 | if (tb[NL80211_WOWLAN_TCP_SRC_PORT]) |
| 8346 | port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]); |
| 8347 | else |
| 8348 | port = 0; |
| 8349 | #ifdef CONFIG_INET |
| 8350 | /* allocate a socket and port for it and use it */ |
| 8351 | err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM, |
| 8352 | IPPROTO_TCP, &cfg->sock, 1); |
| 8353 | if (err) { |
| 8354 | kfree(cfg); |
| 8355 | return err; |
| 8356 | } |
| 8357 | if (inet_csk_get_port(cfg->sock->sk, port)) { |
| 8358 | sock_release(cfg->sock); |
| 8359 | kfree(cfg); |
| 8360 | return -EADDRINUSE; |
| 8361 | } |
| 8362 | cfg->src_port = inet_sk(cfg->sock->sk)->inet_num; |
| 8363 | #else |
| 8364 | if (!port) { |
| 8365 | kfree(cfg); |
| 8366 | return -EINVAL; |
| 8367 | } |
| 8368 | cfg->src_port = port; |
| 8369 | #endif |
| 8370 | |
| 8371 | cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]); |
| 8372 | cfg->payload_len = data_size; |
| 8373 | cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size; |
| 8374 | memcpy((void *)cfg->payload, |
| 8375 | nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]), |
| 8376 | data_size); |
| 8377 | if (seq) |
| 8378 | cfg->payload_seq = *seq; |
| 8379 | cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]); |
| 8380 | cfg->wake_len = wake_size; |
| 8381 | cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size; |
| 8382 | memcpy((void *)cfg->wake_data, |
| 8383 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]), |
| 8384 | wake_size); |
| 8385 | cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size + |
| 8386 | data_size + wake_size; |
| 8387 | memcpy((void *)cfg->wake_mask, |
| 8388 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]), |
| 8389 | wake_mask_size); |
| 8390 | if (tok) { |
| 8391 | cfg->tokens_size = tokens_size; |
| 8392 | memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size); |
| 8393 | } |
| 8394 | |
| 8395 | trig->tcp = cfg; |
| 8396 | |
| 8397 | return 0; |
| 8398 | } |
| 8399 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8400 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 8401 | { |
| 8402 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8403 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8404 | struct cfg80211_wowlan new_triggers = {}; |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8405 | struct cfg80211_wowlan *ntrig; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8406 | const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8407 | int err, i; |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8408 | bool prev_enabled = rdev->wiphy.wowlan_config; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8409 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8410 | if (!wowlan) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8411 | return -EOPNOTSUPP; |
| 8412 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8413 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) { |
| 8414 | cfg80211_rdev_free_wowlan(rdev); |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8415 | rdev->wiphy.wowlan_config = NULL; |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8416 | goto set_wakeup; |
| 8417 | } |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8418 | |
| 8419 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG, |
| 8420 | nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 8421 | nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 8422 | nl80211_wowlan_policy); |
| 8423 | if (err) |
| 8424 | return err; |
| 8425 | |
| 8426 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { |
| 8427 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) |
| 8428 | return -EINVAL; |
| 8429 | new_triggers.any = true; |
| 8430 | } |
| 8431 | |
| 8432 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { |
| 8433 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) |
| 8434 | return -EINVAL; |
| 8435 | new_triggers.disconnect = true; |
| 8436 | } |
| 8437 | |
| 8438 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { |
| 8439 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) |
| 8440 | return -EINVAL; |
| 8441 | new_triggers.magic_pkt = true; |
| 8442 | } |
| 8443 | |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 8444 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
| 8445 | return -EINVAL; |
| 8446 | |
| 8447 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { |
| 8448 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) |
| 8449 | return -EINVAL; |
| 8450 | new_triggers.gtk_rekey_failure = true; |
| 8451 | } |
| 8452 | |
| 8453 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { |
| 8454 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) |
| 8455 | return -EINVAL; |
| 8456 | new_triggers.eap_identity_req = true; |
| 8457 | } |
| 8458 | |
| 8459 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { |
| 8460 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) |
| 8461 | return -EINVAL; |
| 8462 | new_triggers.four_way_handshake = true; |
| 8463 | } |
| 8464 | |
| 8465 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { |
| 8466 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) |
| 8467 | return -EINVAL; |
| 8468 | new_triggers.rfkill_release = true; |
| 8469 | } |
| 8470 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8471 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
| 8472 | struct nlattr *pat; |
| 8473 | int n_patterns = 0; |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8474 | int rem, pat_len, mask_len, pkt_offset; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8475 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8476 | |
| 8477 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 8478 | rem) |
| 8479 | n_patterns++; |
| 8480 | if (n_patterns > wowlan->n_patterns) |
| 8481 | return -EINVAL; |
| 8482 | |
| 8483 | new_triggers.patterns = kcalloc(n_patterns, |
| 8484 | sizeof(new_triggers.patterns[0]), |
| 8485 | GFP_KERNEL); |
| 8486 | if (!new_triggers.patterns) |
| 8487 | return -ENOMEM; |
| 8488 | |
| 8489 | new_triggers.n_patterns = n_patterns; |
| 8490 | i = 0; |
| 8491 | |
| 8492 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 8493 | rem) { |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8494 | nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat), |
| 8495 | nla_len(pat), NULL); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8496 | err = -EINVAL; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8497 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
| 8498 | !pat_tb[NL80211_PKTPAT_PATTERN]) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8499 | goto error; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8500 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8501 | mask_len = DIV_ROUND_UP(pat_len, 8); |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8502 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8503 | goto error; |
| 8504 | if (pat_len > wowlan->pattern_max_len || |
| 8505 | pat_len < wowlan->pattern_min_len) |
| 8506 | goto error; |
| 8507 | |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8508 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8509 | pkt_offset = 0; |
| 8510 | else |
| 8511 | pkt_offset = nla_get_u32( |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8512 | pat_tb[NL80211_PKTPAT_OFFSET]); |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8513 | if (pkt_offset > wowlan->max_pkt_offset) |
| 8514 | goto error; |
| 8515 | new_triggers.patterns[i].pkt_offset = pkt_offset; |
| 8516 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8517 | new_triggers.patterns[i].mask = |
| 8518 | kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 8519 | if (!new_triggers.patterns[i].mask) { |
| 8520 | err = -ENOMEM; |
| 8521 | goto error; |
| 8522 | } |
| 8523 | new_triggers.patterns[i].pattern = |
| 8524 | new_triggers.patterns[i].mask + mask_len; |
| 8525 | memcpy(new_triggers.patterns[i].mask, |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8526 | nla_data(pat_tb[NL80211_PKTPAT_MASK]), |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8527 | mask_len); |
| 8528 | new_triggers.patterns[i].pattern_len = pat_len; |
| 8529 | memcpy(new_triggers.patterns[i].pattern, |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8530 | nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8531 | pat_len); |
| 8532 | i++; |
| 8533 | } |
| 8534 | } |
| 8535 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8536 | if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) { |
| 8537 | err = nl80211_parse_wowlan_tcp( |
| 8538 | rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION], |
| 8539 | &new_triggers); |
| 8540 | if (err) |
| 8541 | goto error; |
| 8542 | } |
| 8543 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8544 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL); |
| 8545 | if (!ntrig) { |
| 8546 | err = -ENOMEM; |
| 8547 | goto error; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8548 | } |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8549 | cfg80211_rdev_free_wowlan(rdev); |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8550 | rdev->wiphy.wowlan_config = ntrig; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8551 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8552 | set_wakeup: |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8553 | if (rdev->ops->set_wakeup && |
| 8554 | prev_enabled != !!rdev->wiphy.wowlan_config) |
| 8555 | rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config); |
Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame] | 8556 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8557 | return 0; |
| 8558 | error: |
| 8559 | for (i = 0; i < new_triggers.n_patterns; i++) |
| 8560 | kfree(new_triggers.patterns[i].mask); |
| 8561 | kfree(new_triggers.patterns); |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8562 | if (new_triggers.tcp && new_triggers.tcp->sock) |
| 8563 | sock_release(new_triggers.tcp->sock); |
| 8564 | kfree(new_triggers.tcp); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8565 | return err; |
| 8566 | } |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 8567 | #endif |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8568 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 8569 | static int nl80211_send_coalesce_rules(struct sk_buff *msg, |
| 8570 | struct cfg80211_registered_device *rdev) |
| 8571 | { |
| 8572 | struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules; |
| 8573 | int i, j, pat_len; |
| 8574 | struct cfg80211_coalesce_rules *rule; |
| 8575 | |
| 8576 | if (!rdev->coalesce->n_rules) |
| 8577 | return 0; |
| 8578 | |
| 8579 | nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE); |
| 8580 | if (!nl_rules) |
| 8581 | return -ENOBUFS; |
| 8582 | |
| 8583 | for (i = 0; i < rdev->coalesce->n_rules; i++) { |
| 8584 | nl_rule = nla_nest_start(msg, i + 1); |
| 8585 | if (!nl_rule) |
| 8586 | return -ENOBUFS; |
| 8587 | |
| 8588 | rule = &rdev->coalesce->rules[i]; |
| 8589 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY, |
| 8590 | rule->delay)) |
| 8591 | return -ENOBUFS; |
| 8592 | |
| 8593 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION, |
| 8594 | rule->condition)) |
| 8595 | return -ENOBUFS; |
| 8596 | |
| 8597 | nl_pats = nla_nest_start(msg, |
| 8598 | NL80211_ATTR_COALESCE_RULE_PKT_PATTERN); |
| 8599 | if (!nl_pats) |
| 8600 | return -ENOBUFS; |
| 8601 | |
| 8602 | for (j = 0; j < rule->n_patterns; j++) { |
| 8603 | nl_pat = nla_nest_start(msg, j + 1); |
| 8604 | if (!nl_pat) |
| 8605 | return -ENOBUFS; |
| 8606 | pat_len = rule->patterns[j].pattern_len; |
| 8607 | if (nla_put(msg, NL80211_PKTPAT_MASK, |
| 8608 | DIV_ROUND_UP(pat_len, 8), |
| 8609 | rule->patterns[j].mask) || |
| 8610 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
| 8611 | rule->patterns[j].pattern) || |
| 8612 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, |
| 8613 | rule->patterns[j].pkt_offset)) |
| 8614 | return -ENOBUFS; |
| 8615 | nla_nest_end(msg, nl_pat); |
| 8616 | } |
| 8617 | nla_nest_end(msg, nl_pats); |
| 8618 | nla_nest_end(msg, nl_rule); |
| 8619 | } |
| 8620 | nla_nest_end(msg, nl_rules); |
| 8621 | |
| 8622 | return 0; |
| 8623 | } |
| 8624 | |
| 8625 | static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info) |
| 8626 | { |
| 8627 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8628 | struct sk_buff *msg; |
| 8629 | void *hdr; |
| 8630 | |
| 8631 | if (!rdev->wiphy.coalesce) |
| 8632 | return -EOPNOTSUPP; |
| 8633 | |
| 8634 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 8635 | if (!msg) |
| 8636 | return -ENOMEM; |
| 8637 | |
| 8638 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 8639 | NL80211_CMD_GET_COALESCE); |
| 8640 | if (!hdr) |
| 8641 | goto nla_put_failure; |
| 8642 | |
| 8643 | if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev)) |
| 8644 | goto nla_put_failure; |
| 8645 | |
| 8646 | genlmsg_end(msg, hdr); |
| 8647 | return genlmsg_reply(msg, info); |
| 8648 | |
| 8649 | nla_put_failure: |
| 8650 | nlmsg_free(msg); |
| 8651 | return -ENOBUFS; |
| 8652 | } |
| 8653 | |
| 8654 | void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev) |
| 8655 | { |
| 8656 | struct cfg80211_coalesce *coalesce = rdev->coalesce; |
| 8657 | int i, j; |
| 8658 | struct cfg80211_coalesce_rules *rule; |
| 8659 | |
| 8660 | if (!coalesce) |
| 8661 | return; |
| 8662 | |
| 8663 | for (i = 0; i < coalesce->n_rules; i++) { |
| 8664 | rule = &coalesce->rules[i]; |
| 8665 | for (j = 0; j < rule->n_patterns; j++) |
| 8666 | kfree(rule->patterns[j].mask); |
| 8667 | kfree(rule->patterns); |
| 8668 | } |
| 8669 | kfree(coalesce->rules); |
| 8670 | kfree(coalesce); |
| 8671 | rdev->coalesce = NULL; |
| 8672 | } |
| 8673 | |
| 8674 | static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev, |
| 8675 | struct nlattr *rule, |
| 8676 | struct cfg80211_coalesce_rules *new_rule) |
| 8677 | { |
| 8678 | int err, i; |
| 8679 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; |
| 8680 | struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat; |
| 8681 | int rem, pat_len, mask_len, pkt_offset, n_patterns = 0; |
| 8682 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
| 8683 | |
| 8684 | err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule), |
| 8685 | nla_len(rule), nl80211_coalesce_policy); |
| 8686 | if (err) |
| 8687 | return err; |
| 8688 | |
| 8689 | if (tb[NL80211_ATTR_COALESCE_RULE_DELAY]) |
| 8690 | new_rule->delay = |
| 8691 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]); |
| 8692 | if (new_rule->delay > coalesce->max_delay) |
| 8693 | return -EINVAL; |
| 8694 | |
| 8695 | if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION]) |
| 8696 | new_rule->condition = |
| 8697 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]); |
| 8698 | if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH && |
| 8699 | new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH) |
| 8700 | return -EINVAL; |
| 8701 | |
| 8702 | if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN]) |
| 8703 | return -EINVAL; |
| 8704 | |
| 8705 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], |
| 8706 | rem) |
| 8707 | n_patterns++; |
| 8708 | if (n_patterns > coalesce->n_patterns) |
| 8709 | return -EINVAL; |
| 8710 | |
| 8711 | new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]), |
| 8712 | GFP_KERNEL); |
| 8713 | if (!new_rule->patterns) |
| 8714 | return -ENOMEM; |
| 8715 | |
| 8716 | new_rule->n_patterns = n_patterns; |
| 8717 | i = 0; |
| 8718 | |
| 8719 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], |
| 8720 | rem) { |
| 8721 | nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat), |
| 8722 | nla_len(pat), NULL); |
| 8723 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
| 8724 | !pat_tb[NL80211_PKTPAT_PATTERN]) |
| 8725 | return -EINVAL; |
| 8726 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
| 8727 | mask_len = DIV_ROUND_UP(pat_len, 8); |
| 8728 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
| 8729 | return -EINVAL; |
| 8730 | if (pat_len > coalesce->pattern_max_len || |
| 8731 | pat_len < coalesce->pattern_min_len) |
| 8732 | return -EINVAL; |
| 8733 | |
| 8734 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
| 8735 | pkt_offset = 0; |
| 8736 | else |
| 8737 | pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]); |
| 8738 | if (pkt_offset > coalesce->max_pkt_offset) |
| 8739 | return -EINVAL; |
| 8740 | new_rule->patterns[i].pkt_offset = pkt_offset; |
| 8741 | |
| 8742 | new_rule->patterns[i].mask = |
| 8743 | kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 8744 | if (!new_rule->patterns[i].mask) |
| 8745 | return -ENOMEM; |
| 8746 | new_rule->patterns[i].pattern = |
| 8747 | new_rule->patterns[i].mask + mask_len; |
| 8748 | memcpy(new_rule->patterns[i].mask, |
| 8749 | nla_data(pat_tb[NL80211_PKTPAT_MASK]), mask_len); |
| 8750 | new_rule->patterns[i].pattern_len = pat_len; |
| 8751 | memcpy(new_rule->patterns[i].pattern, |
| 8752 | nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), pat_len); |
| 8753 | i++; |
| 8754 | } |
| 8755 | |
| 8756 | return 0; |
| 8757 | } |
| 8758 | |
| 8759 | static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info) |
| 8760 | { |
| 8761 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8762 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; |
| 8763 | struct cfg80211_coalesce new_coalesce = {}; |
| 8764 | struct cfg80211_coalesce *n_coalesce; |
| 8765 | int err, rem_rule, n_rules = 0, i, j; |
| 8766 | struct nlattr *rule; |
| 8767 | struct cfg80211_coalesce_rules *tmp_rule; |
| 8768 | |
| 8769 | if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce) |
| 8770 | return -EOPNOTSUPP; |
| 8771 | |
| 8772 | if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) { |
| 8773 | cfg80211_rdev_free_coalesce(rdev); |
| 8774 | rdev->ops->set_coalesce(&rdev->wiphy, NULL); |
| 8775 | return 0; |
| 8776 | } |
| 8777 | |
| 8778 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], |
| 8779 | rem_rule) |
| 8780 | n_rules++; |
| 8781 | if (n_rules > coalesce->n_rules) |
| 8782 | return -EINVAL; |
| 8783 | |
| 8784 | new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]), |
| 8785 | GFP_KERNEL); |
| 8786 | if (!new_coalesce.rules) |
| 8787 | return -ENOMEM; |
| 8788 | |
| 8789 | new_coalesce.n_rules = n_rules; |
| 8790 | i = 0; |
| 8791 | |
| 8792 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], |
| 8793 | rem_rule) { |
| 8794 | err = nl80211_parse_coalesce_rule(rdev, rule, |
| 8795 | &new_coalesce.rules[i]); |
| 8796 | if (err) |
| 8797 | goto error; |
| 8798 | |
| 8799 | i++; |
| 8800 | } |
| 8801 | |
| 8802 | err = rdev->ops->set_coalesce(&rdev->wiphy, &new_coalesce); |
| 8803 | if (err) |
| 8804 | goto error; |
| 8805 | |
| 8806 | n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL); |
| 8807 | if (!n_coalesce) { |
| 8808 | err = -ENOMEM; |
| 8809 | goto error; |
| 8810 | } |
| 8811 | cfg80211_rdev_free_coalesce(rdev); |
| 8812 | rdev->coalesce = n_coalesce; |
| 8813 | |
| 8814 | return 0; |
| 8815 | error: |
| 8816 | for (i = 0; i < new_coalesce.n_rules; i++) { |
| 8817 | tmp_rule = &new_coalesce.rules[i]; |
| 8818 | for (j = 0; j < tmp_rule->n_patterns; j++) |
| 8819 | kfree(tmp_rule->patterns[j].mask); |
| 8820 | kfree(tmp_rule->patterns); |
| 8821 | } |
| 8822 | kfree(new_coalesce.rules); |
| 8823 | |
| 8824 | return err; |
| 8825 | } |
| 8826 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 8827 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
| 8828 | { |
| 8829 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8830 | struct net_device *dev = info->user_ptr[1]; |
| 8831 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 8832 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; |
| 8833 | struct cfg80211_gtk_rekey_data rekey_data; |
| 8834 | int err; |
| 8835 | |
| 8836 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) |
| 8837 | return -EINVAL; |
| 8838 | |
| 8839 | err = nla_parse(tb, MAX_NL80211_REKEY_DATA, |
| 8840 | nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 8841 | nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 8842 | nl80211_rekey_policy); |
| 8843 | if (err) |
| 8844 | return err; |
| 8845 | |
| 8846 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) |
| 8847 | return -ERANGE; |
| 8848 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) |
| 8849 | return -ERANGE; |
| 8850 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) |
| 8851 | return -ERANGE; |
| 8852 | |
| 8853 | memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]), |
| 8854 | NL80211_KEK_LEN); |
| 8855 | memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]), |
| 8856 | NL80211_KCK_LEN); |
| 8857 | memcpy(rekey_data.replay_ctr, |
| 8858 | nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]), |
| 8859 | NL80211_REPLAY_CTR_LEN); |
| 8860 | |
| 8861 | wdev_lock(wdev); |
| 8862 | if (!wdev->current_bss) { |
| 8863 | err = -ENOTCONN; |
| 8864 | goto out; |
| 8865 | } |
| 8866 | |
| 8867 | if (!rdev->ops->set_rekey_data) { |
| 8868 | err = -EOPNOTSUPP; |
| 8869 | goto out; |
| 8870 | } |
| 8871 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8872 | err = rdev_set_rekey_data(rdev, dev, &rekey_data); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 8873 | out: |
| 8874 | wdev_unlock(wdev); |
| 8875 | return err; |
| 8876 | } |
| 8877 | |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8878 | static int nl80211_register_unexpected_frame(struct sk_buff *skb, |
| 8879 | struct genl_info *info) |
| 8880 | { |
| 8881 | struct net_device *dev = info->user_ptr[1]; |
| 8882 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 8883 | |
| 8884 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 8885 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 8886 | return -EINVAL; |
| 8887 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8888 | if (wdev->ap_unexpected_nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8889 | return -EBUSY; |
| 8890 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8891 | wdev->ap_unexpected_nlportid = info->snd_portid; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8892 | return 0; |
| 8893 | } |
| 8894 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8895 | static int nl80211_probe_client(struct sk_buff *skb, |
| 8896 | struct genl_info *info) |
| 8897 | { |
| 8898 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8899 | struct net_device *dev = info->user_ptr[1]; |
| 8900 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 8901 | struct sk_buff *msg; |
| 8902 | void *hdr; |
| 8903 | const u8 *addr; |
| 8904 | u64 cookie; |
| 8905 | int err; |
| 8906 | |
| 8907 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 8908 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 8909 | return -EOPNOTSUPP; |
| 8910 | |
| 8911 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 8912 | return -EINVAL; |
| 8913 | |
| 8914 | if (!rdev->ops->probe_client) |
| 8915 | return -EOPNOTSUPP; |
| 8916 | |
| 8917 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 8918 | if (!msg) |
| 8919 | return -ENOMEM; |
| 8920 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8921 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8922 | NL80211_CMD_PROBE_CLIENT); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 8923 | if (!hdr) { |
| 8924 | err = -ENOBUFS; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8925 | goto free_msg; |
| 8926 | } |
| 8927 | |
| 8928 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 8929 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8930 | err = rdev_probe_client(rdev, dev, addr, &cookie); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8931 | if (err) |
| 8932 | goto free_msg; |
| 8933 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8934 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 8935 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8936 | |
| 8937 | genlmsg_end(msg, hdr); |
| 8938 | |
| 8939 | return genlmsg_reply(msg, info); |
| 8940 | |
| 8941 | nla_put_failure: |
| 8942 | err = -ENOBUFS; |
| 8943 | free_msg: |
| 8944 | nlmsg_free(msg); |
| 8945 | return err; |
| 8946 | } |
| 8947 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8948 | static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) |
| 8949 | { |
| 8950 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 8951 | struct cfg80211_beacon_registration *reg, *nreg; |
| 8952 | int rv; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8953 | |
| 8954 | if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) |
| 8955 | return -EOPNOTSUPP; |
| 8956 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 8957 | nreg = kzalloc(sizeof(*nreg), GFP_KERNEL); |
| 8958 | if (!nreg) |
| 8959 | return -ENOMEM; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8960 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 8961 | /* First, check if already registered. */ |
| 8962 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 8963 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 8964 | if (reg->nlportid == info->snd_portid) { |
| 8965 | rv = -EALREADY; |
| 8966 | goto out_err; |
| 8967 | } |
| 8968 | } |
| 8969 | /* Add it to the list */ |
| 8970 | nreg->nlportid = info->snd_portid; |
| 8971 | list_add(&nreg->list, &rdev->beacon_registrations); |
| 8972 | |
| 8973 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8974 | |
| 8975 | return 0; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 8976 | out_err: |
| 8977 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 8978 | kfree(nreg); |
| 8979 | return rv; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8980 | } |
| 8981 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8982 | static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 8983 | { |
| 8984 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8985 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 8986 | int err; |
| 8987 | |
| 8988 | if (!rdev->ops->start_p2p_device) |
| 8989 | return -EOPNOTSUPP; |
| 8990 | |
| 8991 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 8992 | return -EOPNOTSUPP; |
| 8993 | |
| 8994 | if (wdev->p2p_started) |
| 8995 | return 0; |
| 8996 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8997 | err = cfg80211_can_add_interface(rdev, wdev->iftype); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8998 | if (err) |
| 8999 | return err; |
| 9000 | |
Johannes Berg | eeb126e | 2012-10-23 15:16:50 +0200 | [diff] [blame] | 9001 | err = rdev_start_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9002 | if (err) |
| 9003 | return err; |
| 9004 | |
| 9005 | wdev->p2p_started = true; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9006 | rdev->opencount++; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9007 | |
| 9008 | return 0; |
| 9009 | } |
| 9010 | |
| 9011 | static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 9012 | { |
| 9013 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9014 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 9015 | |
| 9016 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 9017 | return -EOPNOTSUPP; |
| 9018 | |
| 9019 | if (!rdev->ops->stop_p2p_device) |
| 9020 | return -EOPNOTSUPP; |
| 9021 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 9022 | cfg80211_stop_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9023 | |
| 9024 | return 0; |
| 9025 | } |
| 9026 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 9027 | static int nl80211_get_protocol_features(struct sk_buff *skb, |
| 9028 | struct genl_info *info) |
| 9029 | { |
| 9030 | void *hdr; |
| 9031 | struct sk_buff *msg; |
| 9032 | |
| 9033 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 9034 | if (!msg) |
| 9035 | return -ENOMEM; |
| 9036 | |
| 9037 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 9038 | NL80211_CMD_GET_PROTOCOL_FEATURES); |
| 9039 | if (!hdr) |
| 9040 | goto nla_put_failure; |
| 9041 | |
| 9042 | if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES, |
| 9043 | NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)) |
| 9044 | goto nla_put_failure; |
| 9045 | |
| 9046 | genlmsg_end(msg, hdr); |
| 9047 | return genlmsg_reply(msg, info); |
| 9048 | |
| 9049 | nla_put_failure: |
| 9050 | kfree_skb(msg); |
| 9051 | return -ENOBUFS; |
| 9052 | } |
| 9053 | |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 9054 | static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info) |
| 9055 | { |
| 9056 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9057 | struct cfg80211_update_ft_ies_params ft_params; |
| 9058 | struct net_device *dev = info->user_ptr[1]; |
| 9059 | |
| 9060 | if (!rdev->ops->update_ft_ies) |
| 9061 | return -EOPNOTSUPP; |
| 9062 | |
| 9063 | if (!info->attrs[NL80211_ATTR_MDID] || |
| 9064 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 9065 | return -EINVAL; |
| 9066 | |
| 9067 | memset(&ft_params, 0, sizeof(ft_params)); |
| 9068 | ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]); |
| 9069 | ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 9070 | ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 9071 | |
| 9072 | return rdev_update_ft_ies(rdev, dev, &ft_params); |
| 9073 | } |
| 9074 | |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 9075 | static int nl80211_crit_protocol_start(struct sk_buff *skb, |
| 9076 | struct genl_info *info) |
| 9077 | { |
| 9078 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9079 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 9080 | enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC; |
| 9081 | u16 duration; |
| 9082 | int ret; |
| 9083 | |
| 9084 | if (!rdev->ops->crit_proto_start) |
| 9085 | return -EOPNOTSUPP; |
| 9086 | |
| 9087 | if (WARN_ON(!rdev->ops->crit_proto_stop)) |
| 9088 | return -EINVAL; |
| 9089 | |
| 9090 | if (rdev->crit_proto_nlportid) |
| 9091 | return -EBUSY; |
| 9092 | |
| 9093 | /* determine protocol if provided */ |
| 9094 | if (info->attrs[NL80211_ATTR_CRIT_PROT_ID]) |
| 9095 | proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]); |
| 9096 | |
| 9097 | if (proto >= NUM_NL80211_CRIT_PROTO) |
| 9098 | return -EINVAL; |
| 9099 | |
| 9100 | /* timeout must be provided */ |
| 9101 | if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]) |
| 9102 | return -EINVAL; |
| 9103 | |
| 9104 | duration = |
| 9105 | nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]); |
| 9106 | |
| 9107 | if (duration > NL80211_CRIT_PROTO_MAX_DURATION) |
| 9108 | return -ERANGE; |
| 9109 | |
| 9110 | ret = rdev_crit_proto_start(rdev, wdev, proto, duration); |
| 9111 | if (!ret) |
| 9112 | rdev->crit_proto_nlportid = info->snd_portid; |
| 9113 | |
| 9114 | return ret; |
| 9115 | } |
| 9116 | |
| 9117 | static int nl80211_crit_protocol_stop(struct sk_buff *skb, |
| 9118 | struct genl_info *info) |
| 9119 | { |
| 9120 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9121 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 9122 | |
| 9123 | if (!rdev->ops->crit_proto_stop) |
| 9124 | return -EOPNOTSUPP; |
| 9125 | |
| 9126 | if (rdev->crit_proto_nlportid) { |
| 9127 | rdev->crit_proto_nlportid = 0; |
| 9128 | rdev_crit_proto_stop(rdev, wdev); |
| 9129 | } |
| 9130 | return 0; |
| 9131 | } |
| 9132 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 9133 | static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info) |
| 9134 | { |
| 9135 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9136 | struct wireless_dev *wdev = |
| 9137 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); |
| 9138 | int i, err; |
| 9139 | u32 vid, subcmd; |
| 9140 | |
| 9141 | if (!rdev->wiphy.vendor_commands) |
| 9142 | return -EOPNOTSUPP; |
| 9143 | |
| 9144 | if (IS_ERR(wdev)) { |
| 9145 | err = PTR_ERR(wdev); |
| 9146 | if (err != -EINVAL) |
| 9147 | return err; |
| 9148 | wdev = NULL; |
| 9149 | } else if (wdev->wiphy != &rdev->wiphy) { |
| 9150 | return -EINVAL; |
| 9151 | } |
| 9152 | |
| 9153 | if (!info->attrs[NL80211_ATTR_VENDOR_ID] || |
| 9154 | !info->attrs[NL80211_ATTR_VENDOR_SUBCMD]) |
| 9155 | return -EINVAL; |
| 9156 | |
| 9157 | vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]); |
| 9158 | subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]); |
| 9159 | for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { |
| 9160 | const struct wiphy_vendor_command *vcmd; |
| 9161 | void *data = NULL; |
| 9162 | int len = 0; |
| 9163 | |
| 9164 | vcmd = &rdev->wiphy.vendor_commands[i]; |
| 9165 | |
| 9166 | if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd) |
| 9167 | continue; |
| 9168 | |
| 9169 | if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV | |
| 9170 | WIPHY_VENDOR_CMD_NEED_NETDEV)) { |
| 9171 | if (!wdev) |
| 9172 | return -EINVAL; |
| 9173 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV && |
| 9174 | !wdev->netdev) |
| 9175 | return -EINVAL; |
| 9176 | |
| 9177 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) { |
| 9178 | if (wdev->netdev && |
| 9179 | !netif_running(wdev->netdev)) |
| 9180 | return -ENETDOWN; |
| 9181 | if (!wdev->netdev && !wdev->p2p_started) |
| 9182 | return -ENETDOWN; |
| 9183 | } |
| 9184 | } else { |
| 9185 | wdev = NULL; |
| 9186 | } |
| 9187 | |
| 9188 | if (info->attrs[NL80211_ATTR_VENDOR_DATA]) { |
| 9189 | data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]); |
| 9190 | len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]); |
| 9191 | } |
| 9192 | |
| 9193 | rdev->cur_cmd_info = info; |
| 9194 | err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev, |
| 9195 | data, len); |
| 9196 | rdev->cur_cmd_info = NULL; |
| 9197 | return err; |
| 9198 | } |
| 9199 | |
| 9200 | return -EOPNOTSUPP; |
| 9201 | } |
| 9202 | |
| 9203 | struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy, |
| 9204 | enum nl80211_commands cmd, |
| 9205 | enum nl80211_attrs attr, |
| 9206 | int approxlen) |
| 9207 | { |
| 9208 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 9209 | |
| 9210 | if (WARN_ON(!rdev->cur_cmd_info)) |
| 9211 | return NULL; |
| 9212 | |
| 9213 | return __cfg80211_alloc_vendor_skb(rdev, approxlen, |
| 9214 | rdev->cur_cmd_info->snd_portid, |
| 9215 | rdev->cur_cmd_info->snd_seq, |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 9216 | cmd, attr, NULL, GFP_KERNEL); |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 9217 | } |
| 9218 | EXPORT_SYMBOL(__cfg80211_alloc_reply_skb); |
| 9219 | |
| 9220 | int cfg80211_vendor_cmd_reply(struct sk_buff *skb) |
| 9221 | { |
| 9222 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 9223 | void *hdr = ((void **)skb->cb)[1]; |
| 9224 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 9225 | |
| 9226 | if (WARN_ON(!rdev->cur_cmd_info)) { |
| 9227 | kfree_skb(skb); |
| 9228 | return -EINVAL; |
| 9229 | } |
| 9230 | |
| 9231 | nla_nest_end(skb, data); |
| 9232 | genlmsg_end(skb, hdr); |
| 9233 | return genlmsg_reply(skb, rdev->cur_cmd_info); |
| 9234 | } |
| 9235 | EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply); |
| 9236 | |
| 9237 | |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 9238 | static int nl80211_set_qos_map(struct sk_buff *skb, |
| 9239 | struct genl_info *info) |
| 9240 | { |
| 9241 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9242 | struct cfg80211_qos_map *qos_map = NULL; |
| 9243 | struct net_device *dev = info->user_ptr[1]; |
| 9244 | u8 *pos, len, num_des, des_len, des; |
| 9245 | int ret; |
| 9246 | |
| 9247 | if (!rdev->ops->set_qos_map) |
| 9248 | return -EOPNOTSUPP; |
| 9249 | |
| 9250 | if (info->attrs[NL80211_ATTR_QOS_MAP]) { |
| 9251 | pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]); |
| 9252 | len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]); |
| 9253 | |
| 9254 | if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN || |
| 9255 | len > IEEE80211_QOS_MAP_LEN_MAX) |
| 9256 | return -EINVAL; |
| 9257 | |
| 9258 | qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL); |
| 9259 | if (!qos_map) |
| 9260 | return -ENOMEM; |
| 9261 | |
| 9262 | num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1; |
| 9263 | if (num_des) { |
| 9264 | des_len = num_des * |
| 9265 | sizeof(struct cfg80211_dscp_exception); |
| 9266 | memcpy(qos_map->dscp_exception, pos, des_len); |
| 9267 | qos_map->num_des = num_des; |
| 9268 | for (des = 0; des < num_des; des++) { |
| 9269 | if (qos_map->dscp_exception[des].up > 7) { |
| 9270 | kfree(qos_map); |
| 9271 | return -EINVAL; |
| 9272 | } |
| 9273 | } |
| 9274 | pos += des_len; |
| 9275 | } |
| 9276 | memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN); |
| 9277 | } |
| 9278 | |
| 9279 | wdev_lock(dev->ieee80211_ptr); |
| 9280 | ret = nl80211_key_allowed(dev->ieee80211_ptr); |
| 9281 | if (!ret) |
| 9282 | ret = rdev_set_qos_map(rdev, dev, qos_map); |
| 9283 | wdev_unlock(dev->ieee80211_ptr); |
| 9284 | |
| 9285 | kfree(qos_map); |
| 9286 | return ret; |
| 9287 | } |
| 9288 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9289 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
| 9290 | #define NL80211_FLAG_NEED_NETDEV 0x02 |
| 9291 | #define NL80211_FLAG_NEED_RTNL 0x04 |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9292 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
| 9293 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ |
| 9294 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 9295 | #define NL80211_FLAG_NEED_WDEV 0x10 |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9296 | /* 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] | 9297 | #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\ |
| 9298 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9299 | |
Johannes Berg | f84f771 | 2013-11-14 17:14:45 +0100 | [diff] [blame] | 9300 | 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] | 9301 | struct genl_info *info) |
| 9302 | { |
| 9303 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 9304 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9305 | struct net_device *dev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9306 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
| 9307 | |
| 9308 | if (rtnl) |
| 9309 | rtnl_lock(); |
| 9310 | |
| 9311 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 9312 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9313 | if (IS_ERR(rdev)) { |
| 9314 | if (rtnl) |
| 9315 | rtnl_unlock(); |
| 9316 | return PTR_ERR(rdev); |
| 9317 | } |
| 9318 | info->user_ptr[0] = rdev; |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 9319 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV || |
| 9320 | ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 9321 | ASSERT_RTNL(); |
| 9322 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 9323 | wdev = __cfg80211_wdev_from_attrs(genl_info_net(info), |
| 9324 | info->attrs); |
| 9325 | if (IS_ERR(wdev)) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9326 | if (rtnl) |
| 9327 | rtnl_unlock(); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 9328 | return PTR_ERR(wdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9329 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 9330 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 9331 | dev = wdev->netdev; |
| 9332 | rdev = wiphy_to_dev(wdev->wiphy); |
| 9333 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 9334 | if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
| 9335 | if (!dev) { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 9336 | if (rtnl) |
| 9337 | rtnl_unlock(); |
| 9338 | return -EINVAL; |
| 9339 | } |
| 9340 | |
| 9341 | info->user_ptr[1] = dev; |
| 9342 | } else { |
| 9343 | info->user_ptr[1] = wdev; |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9344 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 9345 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 9346 | if (dev) { |
| 9347 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && |
| 9348 | !netif_running(dev)) { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 9349 | if (rtnl) |
| 9350 | rtnl_unlock(); |
| 9351 | return -ENETDOWN; |
| 9352 | } |
| 9353 | |
| 9354 | dev_hold(dev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9355 | } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) { |
| 9356 | if (!wdev->p2p_started) { |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9357 | if (rtnl) |
| 9358 | rtnl_unlock(); |
| 9359 | return -ENETDOWN; |
| 9360 | } |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 9361 | } |
| 9362 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9363 | info->user_ptr[0] = rdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9364 | } |
| 9365 | |
| 9366 | return 0; |
| 9367 | } |
| 9368 | |
Johannes Berg | f84f771 | 2013-11-14 17:14:45 +0100 | [diff] [blame] | 9369 | 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] | 9370 | struct genl_info *info) |
| 9371 | { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 9372 | if (info->user_ptr[1]) { |
| 9373 | if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
| 9374 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 9375 | |
| 9376 | if (wdev->netdev) |
| 9377 | dev_put(wdev->netdev); |
| 9378 | } else { |
| 9379 | dev_put(info->user_ptr[1]); |
| 9380 | } |
| 9381 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9382 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
| 9383 | rtnl_unlock(); |
| 9384 | } |
| 9385 | |
Johannes Berg | 4534de8 | 2013-11-14 17:14:46 +0100 | [diff] [blame] | 9386 | static const struct genl_ops nl80211_ops[] = { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9387 | { |
| 9388 | .cmd = NL80211_CMD_GET_WIPHY, |
| 9389 | .doit = nl80211_get_wiphy, |
| 9390 | .dumpit = nl80211_dump_wiphy, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 9391 | .done = nl80211_dump_wiphy_done, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9392 | .policy = nl80211_policy, |
| 9393 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 9394 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9395 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9396 | }, |
| 9397 | { |
| 9398 | .cmd = NL80211_CMD_SET_WIPHY, |
| 9399 | .doit = nl80211_set_wiphy, |
| 9400 | .policy = nl80211_policy, |
| 9401 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9402 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9403 | }, |
| 9404 | { |
| 9405 | .cmd = NL80211_CMD_GET_INTERFACE, |
| 9406 | .doit = nl80211_get_interface, |
| 9407 | .dumpit = nl80211_dump_interface, |
| 9408 | .policy = nl80211_policy, |
| 9409 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 9410 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 9411 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9412 | }, |
| 9413 | { |
| 9414 | .cmd = NL80211_CMD_SET_INTERFACE, |
| 9415 | .doit = nl80211_set_interface, |
| 9416 | .policy = nl80211_policy, |
| 9417 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9418 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9419 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9420 | }, |
| 9421 | { |
| 9422 | .cmd = NL80211_CMD_NEW_INTERFACE, |
| 9423 | .doit = nl80211_new_interface, |
| 9424 | .policy = nl80211_policy, |
| 9425 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9426 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9427 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9428 | }, |
| 9429 | { |
| 9430 | .cmd = NL80211_CMD_DEL_INTERFACE, |
| 9431 | .doit = nl80211_del_interface, |
| 9432 | .policy = nl80211_policy, |
| 9433 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 9434 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9435 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9436 | }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 9437 | { |
| 9438 | .cmd = NL80211_CMD_GET_KEY, |
| 9439 | .doit = nl80211_get_key, |
| 9440 | .policy = nl80211_policy, |
| 9441 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9442 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9443 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 9444 | }, |
| 9445 | { |
| 9446 | .cmd = NL80211_CMD_SET_KEY, |
| 9447 | .doit = nl80211_set_key, |
| 9448 | .policy = nl80211_policy, |
| 9449 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9450 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9451 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 9452 | }, |
| 9453 | { |
| 9454 | .cmd = NL80211_CMD_NEW_KEY, |
| 9455 | .doit = nl80211_new_key, |
| 9456 | .policy = nl80211_policy, |
| 9457 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9458 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9459 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 9460 | }, |
| 9461 | { |
| 9462 | .cmd = NL80211_CMD_DEL_KEY, |
| 9463 | .doit = nl80211_del_key, |
| 9464 | .policy = nl80211_policy, |
| 9465 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9466 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9467 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 9468 | }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 9469 | { |
| 9470 | .cmd = NL80211_CMD_SET_BEACON, |
| 9471 | .policy = nl80211_policy, |
| 9472 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 9473 | .doit = nl80211_set_beacon, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9474 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9475 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 9476 | }, |
| 9477 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 9478 | .cmd = NL80211_CMD_START_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 9479 | .policy = nl80211_policy, |
| 9480 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 9481 | .doit = nl80211_start_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9482 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9483 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 9484 | }, |
| 9485 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 9486 | .cmd = NL80211_CMD_STOP_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 9487 | .policy = nl80211_policy, |
| 9488 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 9489 | .doit = nl80211_stop_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9490 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9491 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 9492 | }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 9493 | { |
| 9494 | .cmd = NL80211_CMD_GET_STATION, |
| 9495 | .doit = nl80211_get_station, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9496 | .dumpit = nl80211_dump_station, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 9497 | .policy = nl80211_policy, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9498 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9499 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 9500 | }, |
| 9501 | { |
| 9502 | .cmd = NL80211_CMD_SET_STATION, |
| 9503 | .doit = nl80211_set_station, |
| 9504 | .policy = nl80211_policy, |
| 9505 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9506 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9507 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 9508 | }, |
| 9509 | { |
| 9510 | .cmd = NL80211_CMD_NEW_STATION, |
| 9511 | .doit = nl80211_new_station, |
| 9512 | .policy = nl80211_policy, |
| 9513 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9514 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9515 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 9516 | }, |
| 9517 | { |
| 9518 | .cmd = NL80211_CMD_DEL_STATION, |
| 9519 | .doit = nl80211_del_station, |
| 9520 | .policy = nl80211_policy, |
| 9521 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9522 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9523 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 9524 | }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9525 | { |
| 9526 | .cmd = NL80211_CMD_GET_MPATH, |
| 9527 | .doit = nl80211_get_mpath, |
| 9528 | .dumpit = nl80211_dump_mpath, |
| 9529 | .policy = nl80211_policy, |
| 9530 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9531 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9532 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9533 | }, |
| 9534 | { |
| 9535 | .cmd = NL80211_CMD_SET_MPATH, |
| 9536 | .doit = nl80211_set_mpath, |
| 9537 | .policy = nl80211_policy, |
| 9538 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9539 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9540 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9541 | }, |
| 9542 | { |
| 9543 | .cmd = NL80211_CMD_NEW_MPATH, |
| 9544 | .doit = nl80211_new_mpath, |
| 9545 | .policy = nl80211_policy, |
| 9546 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9547 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9548 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9549 | }, |
| 9550 | { |
| 9551 | .cmd = NL80211_CMD_DEL_MPATH, |
| 9552 | .doit = nl80211_del_mpath, |
| 9553 | .policy = nl80211_policy, |
| 9554 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9555 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9556 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9557 | }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 9558 | { |
| 9559 | .cmd = NL80211_CMD_SET_BSS, |
| 9560 | .doit = nl80211_set_bss, |
| 9561 | .policy = nl80211_policy, |
| 9562 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9563 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9564 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 9565 | }, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 9566 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 9567 | .cmd = NL80211_CMD_GET_REG, |
| 9568 | .doit = nl80211_get_reg, |
| 9569 | .policy = nl80211_policy, |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 9570 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 9571 | /* can be retrieved by unprivileged users */ |
| 9572 | }, |
| 9573 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 9574 | .cmd = NL80211_CMD_SET_REG, |
| 9575 | .doit = nl80211_set_reg, |
| 9576 | .policy = nl80211_policy, |
| 9577 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 9578 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 9579 | }, |
| 9580 | { |
| 9581 | .cmd = NL80211_CMD_REQ_SET_REG, |
| 9582 | .doit = nl80211_req_set_reg, |
| 9583 | .policy = nl80211_policy, |
| 9584 | .flags = GENL_ADMIN_PERM, |
| 9585 | }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 9586 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 9587 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
| 9588 | .doit = nl80211_get_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 9589 | .policy = nl80211_policy, |
| 9590 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9591 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9592 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 9593 | }, |
| 9594 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 9595 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
| 9596 | .doit = nl80211_update_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 9597 | .policy = nl80211_policy, |
| 9598 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 9599 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9600 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 9601 | }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 9602 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9603 | .cmd = NL80211_CMD_TRIGGER_SCAN, |
| 9604 | .doit = nl80211_trigger_scan, |
| 9605 | .policy = nl80211_policy, |
| 9606 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9607 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9608 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9609 | }, |
| 9610 | { |
| 9611 | .cmd = NL80211_CMD_GET_SCAN, |
| 9612 | .policy = nl80211_policy, |
| 9613 | .dumpit = nl80211_dump_scan, |
| 9614 | }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9615 | { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9616 | .cmd = NL80211_CMD_START_SCHED_SCAN, |
| 9617 | .doit = nl80211_start_sched_scan, |
| 9618 | .policy = nl80211_policy, |
| 9619 | .flags = GENL_ADMIN_PERM, |
| 9620 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9621 | NL80211_FLAG_NEED_RTNL, |
| 9622 | }, |
| 9623 | { |
| 9624 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, |
| 9625 | .doit = nl80211_stop_sched_scan, |
| 9626 | .policy = nl80211_policy, |
| 9627 | .flags = GENL_ADMIN_PERM, |
| 9628 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9629 | NL80211_FLAG_NEED_RTNL, |
| 9630 | }, |
| 9631 | { |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9632 | .cmd = NL80211_CMD_AUTHENTICATE, |
| 9633 | .doit = nl80211_authenticate, |
| 9634 | .policy = nl80211_policy, |
| 9635 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9636 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9637 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9638 | }, |
| 9639 | { |
| 9640 | .cmd = NL80211_CMD_ASSOCIATE, |
| 9641 | .doit = nl80211_associate, |
| 9642 | .policy = nl80211_policy, |
| 9643 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9644 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9645 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9646 | }, |
| 9647 | { |
| 9648 | .cmd = NL80211_CMD_DEAUTHENTICATE, |
| 9649 | .doit = nl80211_deauthenticate, |
| 9650 | .policy = nl80211_policy, |
| 9651 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9652 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9653 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9654 | }, |
| 9655 | { |
| 9656 | .cmd = NL80211_CMD_DISASSOCIATE, |
| 9657 | .doit = nl80211_disassociate, |
| 9658 | .policy = nl80211_policy, |
| 9659 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9660 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9661 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9662 | }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9663 | { |
| 9664 | .cmd = NL80211_CMD_JOIN_IBSS, |
| 9665 | .doit = nl80211_join_ibss, |
| 9666 | .policy = nl80211_policy, |
| 9667 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9668 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9669 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9670 | }, |
| 9671 | { |
| 9672 | .cmd = NL80211_CMD_LEAVE_IBSS, |
| 9673 | .doit = nl80211_leave_ibss, |
| 9674 | .policy = nl80211_policy, |
| 9675 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9676 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9677 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9678 | }, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 9679 | #ifdef CONFIG_NL80211_TESTMODE |
| 9680 | { |
| 9681 | .cmd = NL80211_CMD_TESTMODE, |
| 9682 | .doit = nl80211_testmode_do, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 9683 | .dumpit = nl80211_testmode_dump, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 9684 | .policy = nl80211_policy, |
| 9685 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9686 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9687 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 9688 | }, |
| 9689 | #endif |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9690 | { |
| 9691 | .cmd = NL80211_CMD_CONNECT, |
| 9692 | .doit = nl80211_connect, |
| 9693 | .policy = nl80211_policy, |
| 9694 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9695 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9696 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9697 | }, |
| 9698 | { |
| 9699 | .cmd = NL80211_CMD_DISCONNECT, |
| 9700 | .doit = nl80211_disconnect, |
| 9701 | .policy = nl80211_policy, |
| 9702 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9703 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9704 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9705 | }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9706 | { |
| 9707 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, |
| 9708 | .doit = nl80211_wiphy_netns, |
| 9709 | .policy = nl80211_policy, |
| 9710 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9711 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9712 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9713 | }, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 9714 | { |
| 9715 | .cmd = NL80211_CMD_GET_SURVEY, |
| 9716 | .policy = nl80211_policy, |
| 9717 | .dumpit = nl80211_dump_survey, |
| 9718 | }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9719 | { |
| 9720 | .cmd = NL80211_CMD_SET_PMKSA, |
| 9721 | .doit = nl80211_setdel_pmksa, |
| 9722 | .policy = nl80211_policy, |
| 9723 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9724 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9725 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9726 | }, |
| 9727 | { |
| 9728 | .cmd = NL80211_CMD_DEL_PMKSA, |
| 9729 | .doit = nl80211_setdel_pmksa, |
| 9730 | .policy = nl80211_policy, |
| 9731 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9732 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9733 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9734 | }, |
| 9735 | { |
| 9736 | .cmd = NL80211_CMD_FLUSH_PMKSA, |
| 9737 | .doit = nl80211_flush_pmksa, |
| 9738 | .policy = nl80211_policy, |
| 9739 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9740 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9741 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9742 | }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9743 | { |
| 9744 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, |
| 9745 | .doit = nl80211_remain_on_channel, |
| 9746 | .policy = nl80211_policy, |
| 9747 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9748 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9749 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9750 | }, |
| 9751 | { |
| 9752 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
| 9753 | .doit = nl80211_cancel_remain_on_channel, |
| 9754 | .policy = nl80211_policy, |
| 9755 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9756 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9757 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9758 | }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 9759 | { |
| 9760 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, |
| 9761 | .doit = nl80211_set_tx_bitrate_mask, |
| 9762 | .policy = nl80211_policy, |
| 9763 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9764 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9765 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 9766 | }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9767 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9768 | .cmd = NL80211_CMD_REGISTER_FRAME, |
| 9769 | .doit = nl80211_register_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9770 | .policy = nl80211_policy, |
| 9771 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9772 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9773 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9774 | }, |
| 9775 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9776 | .cmd = NL80211_CMD_FRAME, |
| 9777 | .doit = nl80211_tx_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9778 | .policy = nl80211_policy, |
| 9779 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9780 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9781 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9782 | }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9783 | { |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 9784 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, |
| 9785 | .doit = nl80211_tx_mgmt_cancel_wait, |
| 9786 | .policy = nl80211_policy, |
| 9787 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9788 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 9789 | NL80211_FLAG_NEED_RTNL, |
| 9790 | }, |
| 9791 | { |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9792 | .cmd = NL80211_CMD_SET_POWER_SAVE, |
| 9793 | .doit = nl80211_set_power_save, |
| 9794 | .policy = nl80211_policy, |
| 9795 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9796 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9797 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9798 | }, |
| 9799 | { |
| 9800 | .cmd = NL80211_CMD_GET_POWER_SAVE, |
| 9801 | .doit = nl80211_get_power_save, |
| 9802 | .policy = nl80211_policy, |
| 9803 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9804 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9805 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9806 | }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9807 | { |
| 9808 | .cmd = NL80211_CMD_SET_CQM, |
| 9809 | .doit = nl80211_set_cqm, |
| 9810 | .policy = nl80211_policy, |
| 9811 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9812 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9813 | NL80211_FLAG_NEED_RTNL, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9814 | }, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 9815 | { |
| 9816 | .cmd = NL80211_CMD_SET_CHANNEL, |
| 9817 | .doit = nl80211_set_channel, |
| 9818 | .policy = nl80211_policy, |
| 9819 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9820 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9821 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 9822 | }, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 9823 | { |
| 9824 | .cmd = NL80211_CMD_SET_WDS_PEER, |
| 9825 | .doit = nl80211_set_wds_peer, |
| 9826 | .policy = nl80211_policy, |
| 9827 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 9828 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9829 | NL80211_FLAG_NEED_RTNL, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 9830 | }, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 9831 | { |
| 9832 | .cmd = NL80211_CMD_JOIN_MESH, |
| 9833 | .doit = nl80211_join_mesh, |
| 9834 | .policy = nl80211_policy, |
| 9835 | .flags = GENL_ADMIN_PERM, |
| 9836 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9837 | NL80211_FLAG_NEED_RTNL, |
| 9838 | }, |
| 9839 | { |
| 9840 | .cmd = NL80211_CMD_LEAVE_MESH, |
| 9841 | .doit = nl80211_leave_mesh, |
| 9842 | .policy = nl80211_policy, |
| 9843 | .flags = GENL_ADMIN_PERM, |
| 9844 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9845 | NL80211_FLAG_NEED_RTNL, |
| 9846 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 9847 | #ifdef CONFIG_PM |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9848 | { |
| 9849 | .cmd = NL80211_CMD_GET_WOWLAN, |
| 9850 | .doit = nl80211_get_wowlan, |
| 9851 | .policy = nl80211_policy, |
| 9852 | /* can be retrieved by unprivileged users */ |
| 9853 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9854 | NL80211_FLAG_NEED_RTNL, |
| 9855 | }, |
| 9856 | { |
| 9857 | .cmd = NL80211_CMD_SET_WOWLAN, |
| 9858 | .doit = nl80211_set_wowlan, |
| 9859 | .policy = nl80211_policy, |
| 9860 | .flags = GENL_ADMIN_PERM, |
| 9861 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9862 | NL80211_FLAG_NEED_RTNL, |
| 9863 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 9864 | #endif |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 9865 | { |
| 9866 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, |
| 9867 | .doit = nl80211_set_rekey_data, |
| 9868 | .policy = nl80211_policy, |
| 9869 | .flags = GENL_ADMIN_PERM, |
| 9870 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9871 | NL80211_FLAG_NEED_RTNL, |
| 9872 | }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 9873 | { |
| 9874 | .cmd = NL80211_CMD_TDLS_MGMT, |
| 9875 | .doit = nl80211_tdls_mgmt, |
| 9876 | .policy = nl80211_policy, |
| 9877 | .flags = GENL_ADMIN_PERM, |
| 9878 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9879 | NL80211_FLAG_NEED_RTNL, |
| 9880 | }, |
| 9881 | { |
| 9882 | .cmd = NL80211_CMD_TDLS_OPER, |
| 9883 | .doit = nl80211_tdls_oper, |
| 9884 | .policy = nl80211_policy, |
| 9885 | .flags = GENL_ADMIN_PERM, |
| 9886 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9887 | NL80211_FLAG_NEED_RTNL, |
| 9888 | }, |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9889 | { |
| 9890 | .cmd = NL80211_CMD_UNEXPECTED_FRAME, |
| 9891 | .doit = nl80211_register_unexpected_frame, |
| 9892 | .policy = nl80211_policy, |
| 9893 | .flags = GENL_ADMIN_PERM, |
| 9894 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9895 | NL80211_FLAG_NEED_RTNL, |
| 9896 | }, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9897 | { |
| 9898 | .cmd = NL80211_CMD_PROBE_CLIENT, |
| 9899 | .doit = nl80211_probe_client, |
| 9900 | .policy = nl80211_policy, |
| 9901 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9902 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9903 | NL80211_FLAG_NEED_RTNL, |
| 9904 | }, |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9905 | { |
| 9906 | .cmd = NL80211_CMD_REGISTER_BEACONS, |
| 9907 | .doit = nl80211_register_beacons, |
| 9908 | .policy = nl80211_policy, |
| 9909 | .flags = GENL_ADMIN_PERM, |
| 9910 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9911 | NL80211_FLAG_NEED_RTNL, |
| 9912 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 9913 | { |
| 9914 | .cmd = NL80211_CMD_SET_NOACK_MAP, |
| 9915 | .doit = nl80211_set_noack_map, |
| 9916 | .policy = nl80211_policy, |
| 9917 | .flags = GENL_ADMIN_PERM, |
| 9918 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9919 | NL80211_FLAG_NEED_RTNL, |
| 9920 | }, |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9921 | { |
| 9922 | .cmd = NL80211_CMD_START_P2P_DEVICE, |
| 9923 | .doit = nl80211_start_p2p_device, |
| 9924 | .policy = nl80211_policy, |
| 9925 | .flags = GENL_ADMIN_PERM, |
| 9926 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 9927 | NL80211_FLAG_NEED_RTNL, |
| 9928 | }, |
| 9929 | { |
| 9930 | .cmd = NL80211_CMD_STOP_P2P_DEVICE, |
| 9931 | .doit = nl80211_stop_p2p_device, |
| 9932 | .policy = nl80211_policy, |
| 9933 | .flags = GENL_ADMIN_PERM, |
| 9934 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 9935 | NL80211_FLAG_NEED_RTNL, |
| 9936 | }, |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 9937 | { |
| 9938 | .cmd = NL80211_CMD_SET_MCAST_RATE, |
| 9939 | .doit = nl80211_set_mcast_rate, |
| 9940 | .policy = nl80211_policy, |
| 9941 | .flags = GENL_ADMIN_PERM, |
| 9942 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9943 | NL80211_FLAG_NEED_RTNL, |
| 9944 | }, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 9945 | { |
| 9946 | .cmd = NL80211_CMD_SET_MAC_ACL, |
| 9947 | .doit = nl80211_set_mac_acl, |
| 9948 | .policy = nl80211_policy, |
| 9949 | .flags = GENL_ADMIN_PERM, |
| 9950 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9951 | NL80211_FLAG_NEED_RTNL, |
| 9952 | }, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 9953 | { |
| 9954 | .cmd = NL80211_CMD_RADAR_DETECT, |
| 9955 | .doit = nl80211_start_radar_detection, |
| 9956 | .policy = nl80211_policy, |
| 9957 | .flags = GENL_ADMIN_PERM, |
| 9958 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9959 | NL80211_FLAG_NEED_RTNL, |
| 9960 | }, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 9961 | { |
| 9962 | .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES, |
| 9963 | .doit = nl80211_get_protocol_features, |
| 9964 | .policy = nl80211_policy, |
| 9965 | }, |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 9966 | { |
| 9967 | .cmd = NL80211_CMD_UPDATE_FT_IES, |
| 9968 | .doit = nl80211_update_ft_ies, |
| 9969 | .policy = nl80211_policy, |
| 9970 | .flags = GENL_ADMIN_PERM, |
| 9971 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9972 | NL80211_FLAG_NEED_RTNL, |
| 9973 | }, |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 9974 | { |
| 9975 | .cmd = NL80211_CMD_CRIT_PROTOCOL_START, |
| 9976 | .doit = nl80211_crit_protocol_start, |
| 9977 | .policy = nl80211_policy, |
| 9978 | .flags = GENL_ADMIN_PERM, |
| 9979 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 9980 | NL80211_FLAG_NEED_RTNL, |
| 9981 | }, |
| 9982 | { |
| 9983 | .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP, |
| 9984 | .doit = nl80211_crit_protocol_stop, |
| 9985 | .policy = nl80211_policy, |
| 9986 | .flags = GENL_ADMIN_PERM, |
| 9987 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 9988 | NL80211_FLAG_NEED_RTNL, |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 9989 | }, |
| 9990 | { |
| 9991 | .cmd = NL80211_CMD_GET_COALESCE, |
| 9992 | .doit = nl80211_get_coalesce, |
| 9993 | .policy = nl80211_policy, |
| 9994 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9995 | NL80211_FLAG_NEED_RTNL, |
| 9996 | }, |
| 9997 | { |
| 9998 | .cmd = NL80211_CMD_SET_COALESCE, |
| 9999 | .doit = nl80211_set_coalesce, |
| 10000 | .policy = nl80211_policy, |
| 10001 | .flags = GENL_ADMIN_PERM, |
| 10002 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 10003 | NL80211_FLAG_NEED_RTNL, |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 10004 | }, |
| 10005 | { |
| 10006 | .cmd = NL80211_CMD_CHANNEL_SWITCH, |
| 10007 | .doit = nl80211_channel_switch, |
| 10008 | .policy = nl80211_policy, |
| 10009 | .flags = GENL_ADMIN_PERM, |
| 10010 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10011 | NL80211_FLAG_NEED_RTNL, |
| 10012 | }, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 10013 | { |
| 10014 | .cmd = NL80211_CMD_VENDOR, |
| 10015 | .doit = nl80211_vendor_cmd, |
| 10016 | .policy = nl80211_policy, |
| 10017 | .flags = GENL_ADMIN_PERM, |
| 10018 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 10019 | NL80211_FLAG_NEED_RTNL, |
| 10020 | }, |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 10021 | { |
| 10022 | .cmd = NL80211_CMD_SET_QOS_MAP, |
| 10023 | .doit = nl80211_set_qos_map, |
| 10024 | .policy = nl80211_policy, |
| 10025 | .flags = GENL_ADMIN_PERM, |
| 10026 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10027 | NL80211_FLAG_NEED_RTNL, |
| 10028 | }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10029 | }; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10030 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10031 | /* notification functions */ |
| 10032 | |
| 10033 | void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev) |
| 10034 | { |
| 10035 | struct sk_buff *msg; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 10036 | struct nl80211_dump_wiphy_state state = {}; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10037 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 10038 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10039 | if (!msg) |
| 10040 | return; |
| 10041 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 10042 | if (nl80211_send_wiphy(rdev, msg, 0, 0, 0, &state) < 0) { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 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_CONFIG, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10049 | } |
| 10050 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 10051 | static int nl80211_add_scan_req(struct sk_buff *msg, |
| 10052 | struct cfg80211_registered_device *rdev) |
| 10053 | { |
| 10054 | struct cfg80211_scan_request *req = rdev->scan_req; |
| 10055 | struct nlattr *nest; |
| 10056 | int i; |
| 10057 | |
| 10058 | if (WARN_ON(!req)) |
| 10059 | return 0; |
| 10060 | |
| 10061 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); |
| 10062 | if (!nest) |
| 10063 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10064 | for (i = 0; i < req->n_ssids; i++) { |
| 10065 | if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) |
| 10066 | goto nla_put_failure; |
| 10067 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 10068 | nla_nest_end(msg, nest); |
| 10069 | |
| 10070 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 10071 | if (!nest) |
| 10072 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10073 | for (i = 0; i < req->n_channels; i++) { |
| 10074 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) |
| 10075 | goto nla_put_failure; |
| 10076 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 10077 | nla_nest_end(msg, nest); |
| 10078 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10079 | if (req->ie && |
| 10080 | nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie)) |
| 10081 | goto nla_put_failure; |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 10082 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 10083 | if (req->flags && |
| 10084 | nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags)) |
| 10085 | goto nla_put_failure; |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 10086 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 10087 | return 0; |
| 10088 | nla_put_failure: |
| 10089 | return -ENOBUFS; |
| 10090 | } |
| 10091 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 10092 | static int nl80211_send_scan_msg(struct sk_buff *msg, |
| 10093 | struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 10094 | struct wireless_dev *wdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10095 | u32 portid, u32 seq, int flags, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 10096 | u32 cmd) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10097 | { |
| 10098 | void *hdr; |
| 10099 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10100 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10101 | if (!hdr) |
| 10102 | return -1; |
| 10103 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10104 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 10105 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 10106 | wdev->netdev->ifindex)) || |
| 10107 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10108 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10109 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 10110 | /* ignore errors and send incomplete event anyway */ |
| 10111 | nl80211_add_scan_req(msg, rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10112 | |
| 10113 | return genlmsg_end(msg, hdr); |
| 10114 | |
| 10115 | nla_put_failure: |
| 10116 | genlmsg_cancel(msg, hdr); |
| 10117 | return -EMSGSIZE; |
| 10118 | } |
| 10119 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 10120 | static int |
| 10121 | nl80211_send_sched_scan_msg(struct sk_buff *msg, |
| 10122 | struct cfg80211_registered_device *rdev, |
| 10123 | struct net_device *netdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10124 | u32 portid, u32 seq, int flags, u32 cmd) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 10125 | { |
| 10126 | void *hdr; |
| 10127 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10128 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 10129 | if (!hdr) |
| 10130 | return -1; |
| 10131 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10132 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10133 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 10134 | goto nla_put_failure; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 10135 | |
| 10136 | return genlmsg_end(msg, hdr); |
| 10137 | |
| 10138 | nla_put_failure: |
| 10139 | genlmsg_cancel(msg, hdr); |
| 10140 | return -EMSGSIZE; |
| 10141 | } |
| 10142 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 10143 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 10144 | struct wireless_dev *wdev) |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 10145 | { |
| 10146 | struct sk_buff *msg; |
| 10147 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10148 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 10149 | if (!msg) |
| 10150 | return; |
| 10151 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 10152 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 10153 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
| 10154 | nlmsg_free(msg); |
| 10155 | return; |
| 10156 | } |
| 10157 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10158 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10159 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 10160 | } |
| 10161 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 10162 | struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev, |
| 10163 | struct wireless_dev *wdev, bool aborted) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10164 | { |
| 10165 | struct sk_buff *msg; |
| 10166 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 10167 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10168 | if (!msg) |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 10169 | return NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10170 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 10171 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 10172 | aborted ? NL80211_CMD_SCAN_ABORTED : |
| 10173 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10174 | nlmsg_free(msg); |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 10175 | return NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10176 | } |
| 10177 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 10178 | return msg; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10179 | } |
| 10180 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 10181 | void nl80211_send_scan_result(struct cfg80211_registered_device *rdev, |
| 10182 | struct sk_buff *msg) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10183 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10184 | if (!msg) |
| 10185 | return; |
| 10186 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10187 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10188 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10189 | } |
| 10190 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 10191 | void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev, |
| 10192 | struct net_device *netdev) |
| 10193 | { |
| 10194 | struct sk_buff *msg; |
| 10195 | |
| 10196 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 10197 | if (!msg) |
| 10198 | return; |
| 10199 | |
| 10200 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 10201 | NL80211_CMD_SCHED_SCAN_RESULTS) < 0) { |
| 10202 | nlmsg_free(msg); |
| 10203 | return; |
| 10204 | } |
| 10205 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10206 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10207 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 10208 | } |
| 10209 | |
| 10210 | void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev, |
| 10211 | struct net_device *netdev, u32 cmd) |
| 10212 | { |
| 10213 | struct sk_buff *msg; |
| 10214 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10215 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 10216 | if (!msg) |
| 10217 | return; |
| 10218 | |
| 10219 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) { |
| 10220 | nlmsg_free(msg); |
| 10221 | return; |
| 10222 | } |
| 10223 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10224 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10225 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 10226 | } |
| 10227 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 10228 | /* |
| 10229 | * This can happen on global regulatory changes or device specific settings |
| 10230 | * based on custom world regulatory domains. |
| 10231 | */ |
| 10232 | void nl80211_send_reg_change_event(struct regulatory_request *request) |
| 10233 | { |
| 10234 | struct sk_buff *msg; |
| 10235 | void *hdr; |
| 10236 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 10237 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 10238 | if (!msg) |
| 10239 | return; |
| 10240 | |
| 10241 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE); |
| 10242 | if (!hdr) { |
| 10243 | nlmsg_free(msg); |
| 10244 | return; |
| 10245 | } |
| 10246 | |
| 10247 | /* Userspace can always count this one always being set */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10248 | if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator)) |
| 10249 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 10250 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10251 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') { |
| 10252 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 10253 | NL80211_REGDOM_TYPE_WORLD)) |
| 10254 | goto nla_put_failure; |
| 10255 | } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') { |
| 10256 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 10257 | NL80211_REGDOM_TYPE_CUSTOM_WORLD)) |
| 10258 | goto nla_put_failure; |
| 10259 | } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || |
| 10260 | request->intersect) { |
| 10261 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 10262 | NL80211_REGDOM_TYPE_INTERSECTION)) |
| 10263 | goto nla_put_failure; |
| 10264 | } else { |
| 10265 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 10266 | NL80211_REGDOM_TYPE_COUNTRY) || |
| 10267 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, |
| 10268 | request->alpha2)) |
| 10269 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 10270 | } |
| 10271 | |
Johannes Berg | f417376 | 2012-12-03 18:23:37 +0100 | [diff] [blame] | 10272 | if (request->wiphy_idx != WIPHY_IDX_INVALID && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10273 | nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) |
| 10274 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 10275 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10276 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 10277 | |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 10278 | rcu_read_lock(); |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10279 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10280 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 10281 | rcu_read_unlock(); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 10282 | |
| 10283 | return; |
| 10284 | |
| 10285 | nla_put_failure: |
| 10286 | genlmsg_cancel(msg, hdr); |
| 10287 | nlmsg_free(msg); |
| 10288 | } |
| 10289 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10290 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
| 10291 | struct net_device *netdev, |
| 10292 | const u8 *buf, size_t len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10293 | enum nl80211_commands cmd, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10294 | { |
| 10295 | struct sk_buff *msg; |
| 10296 | void *hdr; |
| 10297 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10298 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10299 | if (!msg) |
| 10300 | return; |
| 10301 | |
| 10302 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 10303 | if (!hdr) { |
| 10304 | nlmsg_free(msg); |
| 10305 | return; |
| 10306 | } |
| 10307 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10308 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10309 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10310 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) |
| 10311 | goto nla_put_failure; |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10312 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10313 | genlmsg_end(msg, hdr); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10314 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10315 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10316 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10317 | return; |
| 10318 | |
| 10319 | nla_put_failure: |
| 10320 | genlmsg_cancel(msg, hdr); |
| 10321 | nlmsg_free(msg); |
| 10322 | } |
| 10323 | |
| 10324 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10325 | struct net_device *netdev, const u8 *buf, |
| 10326 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10327 | { |
| 10328 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10329 | NL80211_CMD_AUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10330 | } |
| 10331 | |
| 10332 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, |
| 10333 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10334 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10335 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10336 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 10337 | NL80211_CMD_ASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10338 | } |
| 10339 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 10340 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10341 | struct net_device *netdev, const u8 *buf, |
| 10342 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10343 | { |
| 10344 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10345 | NL80211_CMD_DEAUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10346 | } |
| 10347 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 10348 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
| 10349 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10350 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10351 | { |
| 10352 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10353 | NL80211_CMD_DISASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10354 | } |
| 10355 | |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 10356 | void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf, |
| 10357 | size_t len) |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 10358 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10359 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10360 | struct wiphy *wiphy = wdev->wiphy; |
| 10361 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 10362 | const struct ieee80211_mgmt *mgmt = (void *)buf; |
| 10363 | u32 cmd; |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 10364 | |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 10365 | if (WARN_ON(len < 2)) |
| 10366 | return; |
| 10367 | |
| 10368 | if (ieee80211_is_deauth(mgmt->frame_control)) |
| 10369 | cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE; |
| 10370 | else |
| 10371 | cmd = NL80211_CMD_UNPROT_DISASSOCIATE; |
| 10372 | |
| 10373 | trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len); |
| 10374 | nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC); |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 10375 | } |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 10376 | EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt); |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 10377 | |
Luis R. Rodriguez | 1b06bb4 | 2009-05-02 00:34:48 -0400 | [diff] [blame] | 10378 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
| 10379 | struct net_device *netdev, int cmd, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10380 | const u8 *addr, gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10381 | { |
| 10382 | struct sk_buff *msg; |
| 10383 | void *hdr; |
| 10384 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10385 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10386 | if (!msg) |
| 10387 | return; |
| 10388 | |
| 10389 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 10390 | if (!hdr) { |
| 10391 | nlmsg_free(msg); |
| 10392 | return; |
| 10393 | } |
| 10394 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10395 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10396 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10397 | nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || |
| 10398 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 10399 | goto nla_put_failure; |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10400 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10401 | genlmsg_end(msg, hdr); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10402 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10403 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10404 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10405 | return; |
| 10406 | |
| 10407 | nla_put_failure: |
| 10408 | genlmsg_cancel(msg, hdr); |
| 10409 | nlmsg_free(msg); |
| 10410 | } |
| 10411 | |
| 10412 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10413 | struct net_device *netdev, const u8 *addr, |
| 10414 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10415 | { |
| 10416 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10417 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10418 | } |
| 10419 | |
| 10420 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10421 | struct net_device *netdev, const u8 *addr, |
| 10422 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10423 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10424 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
| 10425 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10426 | } |
| 10427 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10428 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
| 10429 | struct net_device *netdev, const u8 *bssid, |
| 10430 | const u8 *req_ie, size_t req_ie_len, |
| 10431 | const u8 *resp_ie, size_t resp_ie_len, |
| 10432 | u16 status, gfp_t gfp) |
| 10433 | { |
| 10434 | struct sk_buff *msg; |
| 10435 | void *hdr; |
| 10436 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10437 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10438 | if (!msg) |
| 10439 | return; |
| 10440 | |
| 10441 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); |
| 10442 | if (!hdr) { |
| 10443 | nlmsg_free(msg); |
| 10444 | return; |
| 10445 | } |
| 10446 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10447 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10448 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10449 | (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) || |
| 10450 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) || |
| 10451 | (req_ie && |
| 10452 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 10453 | (resp_ie && |
| 10454 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 10455 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10456 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10457 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10458 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10459 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10460 | NL80211_MCGRP_MLME, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10461 | return; |
| 10462 | |
| 10463 | nla_put_failure: |
| 10464 | genlmsg_cancel(msg, hdr); |
| 10465 | nlmsg_free(msg); |
| 10466 | |
| 10467 | } |
| 10468 | |
| 10469 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, |
| 10470 | struct net_device *netdev, const u8 *bssid, |
| 10471 | const u8 *req_ie, size_t req_ie_len, |
| 10472 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) |
| 10473 | { |
| 10474 | struct sk_buff *msg; |
| 10475 | void *hdr; |
| 10476 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10477 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10478 | if (!msg) |
| 10479 | return; |
| 10480 | |
| 10481 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); |
| 10482 | if (!hdr) { |
| 10483 | nlmsg_free(msg); |
| 10484 | return; |
| 10485 | } |
| 10486 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10487 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10488 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10489 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) || |
| 10490 | (req_ie && |
| 10491 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 10492 | (resp_ie && |
| 10493 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 10494 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10495 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10496 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10497 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10498 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10499 | NL80211_MCGRP_MLME, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10500 | return; |
| 10501 | |
| 10502 | nla_put_failure: |
| 10503 | genlmsg_cancel(msg, hdr); |
| 10504 | nlmsg_free(msg); |
| 10505 | |
| 10506 | } |
| 10507 | |
| 10508 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, |
| 10509 | struct net_device *netdev, u16 reason, |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 10510 | const u8 *ie, size_t ie_len, bool from_ap) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10511 | { |
| 10512 | struct sk_buff *msg; |
| 10513 | void *hdr; |
| 10514 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10515 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10516 | if (!msg) |
| 10517 | return; |
| 10518 | |
| 10519 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); |
| 10520 | if (!hdr) { |
| 10521 | nlmsg_free(msg); |
| 10522 | return; |
| 10523 | } |
| 10524 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10525 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10526 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10527 | (from_ap && reason && |
| 10528 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) || |
| 10529 | (from_ap && |
| 10530 | nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) || |
| 10531 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) |
| 10532 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10533 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10534 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10535 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10536 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10537 | NL80211_MCGRP_MLME, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10538 | return; |
| 10539 | |
| 10540 | nla_put_failure: |
| 10541 | genlmsg_cancel(msg, hdr); |
| 10542 | nlmsg_free(msg); |
| 10543 | |
| 10544 | } |
| 10545 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10546 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
| 10547 | struct net_device *netdev, const u8 *bssid, |
| 10548 | gfp_t gfp) |
| 10549 | { |
| 10550 | struct sk_buff *msg; |
| 10551 | void *hdr; |
| 10552 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 10553 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10554 | if (!msg) |
| 10555 | return; |
| 10556 | |
| 10557 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); |
| 10558 | if (!hdr) { |
| 10559 | nlmsg_free(msg); |
| 10560 | return; |
| 10561 | } |
| 10562 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10563 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10564 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10565 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 10566 | goto nla_put_failure; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10567 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10568 | genlmsg_end(msg, hdr); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10569 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10570 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10571 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10572 | return; |
| 10573 | |
| 10574 | nla_put_failure: |
| 10575 | genlmsg_cancel(msg, hdr); |
| 10576 | nlmsg_free(msg); |
| 10577 | } |
| 10578 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10579 | void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr, |
| 10580 | const u8* ie, u8 ie_len, gfp_t gfp) |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10581 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10582 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10583 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10584 | struct sk_buff *msg; |
| 10585 | void *hdr; |
| 10586 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10587 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT)) |
| 10588 | return; |
| 10589 | |
| 10590 | trace_cfg80211_notify_new_peer_candidate(dev, addr); |
| 10591 | |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10592 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 10593 | if (!msg) |
| 10594 | return; |
| 10595 | |
| 10596 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); |
| 10597 | if (!hdr) { |
| 10598 | nlmsg_free(msg); |
| 10599 | return; |
| 10600 | } |
| 10601 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10602 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10603 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 10604 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10605 | (ie_len && ie && |
| 10606 | nla_put(msg, NL80211_ATTR_IE, ie_len , ie))) |
| 10607 | goto nla_put_failure; |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10608 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10609 | genlmsg_end(msg, hdr); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10610 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10611 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10612 | NL80211_MCGRP_MLME, gfp); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10613 | return; |
| 10614 | |
| 10615 | nla_put_failure: |
| 10616 | genlmsg_cancel(msg, hdr); |
| 10617 | nlmsg_free(msg); |
| 10618 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10619 | EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10620 | |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 10621 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
| 10622 | struct net_device *netdev, const u8 *addr, |
| 10623 | enum nl80211_key_type key_type, int key_id, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10624 | const u8 *tsc, gfp_t gfp) |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 10625 | { |
| 10626 | struct sk_buff *msg; |
| 10627 | void *hdr; |
| 10628 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10629 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 10630 | if (!msg) |
| 10631 | return; |
| 10632 | |
| 10633 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); |
| 10634 | if (!hdr) { |
| 10635 | nlmsg_free(msg); |
| 10636 | return; |
| 10637 | } |
| 10638 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10639 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10640 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10641 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
| 10642 | nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) || |
| 10643 | (key_id != -1 && |
| 10644 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) || |
| 10645 | (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc))) |
| 10646 | goto nla_put_failure; |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 10647 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10648 | genlmsg_end(msg, hdr); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 10649 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10650 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10651 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 10652 | return; |
| 10653 | |
| 10654 | nla_put_failure: |
| 10655 | genlmsg_cancel(msg, hdr); |
| 10656 | nlmsg_free(msg); |
| 10657 | } |
| 10658 | |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10659 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
| 10660 | struct ieee80211_channel *channel_before, |
| 10661 | struct ieee80211_channel *channel_after) |
| 10662 | { |
| 10663 | struct sk_buff *msg; |
| 10664 | void *hdr; |
| 10665 | struct nlattr *nl_freq; |
| 10666 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 10667 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10668 | if (!msg) |
| 10669 | return; |
| 10670 | |
| 10671 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); |
| 10672 | if (!hdr) { |
| 10673 | nlmsg_free(msg); |
| 10674 | return; |
| 10675 | } |
| 10676 | |
| 10677 | /* |
| 10678 | * Since we are applying the beacon hint to a wiphy we know its |
| 10679 | * wiphy_idx is valid |
| 10680 | */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10681 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 10682 | goto nla_put_failure; |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10683 | |
| 10684 | /* Before */ |
| 10685 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); |
| 10686 | if (!nl_freq) |
| 10687 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 10688 | if (nl80211_msg_put_channel(msg, channel_before, false)) |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10689 | goto nla_put_failure; |
| 10690 | nla_nest_end(msg, nl_freq); |
| 10691 | |
| 10692 | /* After */ |
| 10693 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); |
| 10694 | if (!nl_freq) |
| 10695 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 10696 | if (nl80211_msg_put_channel(msg, channel_after, false)) |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10697 | goto nla_put_failure; |
| 10698 | nla_nest_end(msg, nl_freq); |
| 10699 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10700 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10701 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 10702 | rcu_read_lock(); |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10703 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10704 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 10705 | rcu_read_unlock(); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10706 | |
| 10707 | return; |
| 10708 | |
| 10709 | nla_put_failure: |
| 10710 | genlmsg_cancel(msg, hdr); |
| 10711 | nlmsg_free(msg); |
| 10712 | } |
| 10713 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10714 | static void nl80211_send_remain_on_chan_event( |
| 10715 | int cmd, struct cfg80211_registered_device *rdev, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10716 | struct wireless_dev *wdev, u64 cookie, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10717 | struct ieee80211_channel *chan, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10718 | unsigned int duration, gfp_t gfp) |
| 10719 | { |
| 10720 | struct sk_buff *msg; |
| 10721 | void *hdr; |
| 10722 | |
| 10723 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 10724 | if (!msg) |
| 10725 | return; |
| 10726 | |
| 10727 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 10728 | if (!hdr) { |
| 10729 | nlmsg_free(msg); |
| 10730 | return; |
| 10731 | } |
| 10732 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10733 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10734 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 10735 | wdev->netdev->ifindex)) || |
Johannes Berg | 00f5335 | 2012-07-17 11:53:12 +0200 | [diff] [blame] | 10736 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10737 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) || |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 10738 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 10739 | NL80211_CHAN_NO_HT) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10740 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 10741 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10742 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10743 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL && |
| 10744 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) |
| 10745 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10746 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10747 | genlmsg_end(msg, hdr); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10748 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10749 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10750 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10751 | return; |
| 10752 | |
| 10753 | nla_put_failure: |
| 10754 | genlmsg_cancel(msg, hdr); |
| 10755 | nlmsg_free(msg); |
| 10756 | } |
| 10757 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10758 | void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie, |
| 10759 | struct ieee80211_channel *chan, |
| 10760 | unsigned int duration, gfp_t gfp) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10761 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10762 | struct wiphy *wiphy = wdev->wiphy; |
| 10763 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 10764 | |
| 10765 | trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10766 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10767 | rdev, wdev, cookie, chan, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 10768 | duration, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10769 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10770 | EXPORT_SYMBOL(cfg80211_ready_on_channel); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10771 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10772 | void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie, |
| 10773 | struct ieee80211_channel *chan, |
| 10774 | gfp_t gfp) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10775 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10776 | struct wiphy *wiphy = wdev->wiphy; |
| 10777 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 10778 | |
| 10779 | trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10780 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 10781 | rdev, wdev, cookie, chan, 0, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10782 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10783 | EXPORT_SYMBOL(cfg80211_remain_on_channel_expired); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10784 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10785 | void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr, |
| 10786 | struct station_info *sinfo, gfp_t gfp) |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 10787 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10788 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
| 10789 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 10790 | struct sk_buff *msg; |
| 10791 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10792 | trace_cfg80211_new_sta(dev, mac_addr, sinfo); |
| 10793 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10794 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 10795 | if (!msg) |
| 10796 | return; |
| 10797 | |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 10798 | if (nl80211_send_station(msg, 0, 0, 0, |
| 10799 | rdev, dev, mac_addr, sinfo) < 0) { |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 10800 | nlmsg_free(msg); |
| 10801 | return; |
| 10802 | } |
| 10803 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10804 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10805 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 10806 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10807 | EXPORT_SYMBOL(cfg80211_new_sta); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 10808 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10809 | 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] | 10810 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10811 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
| 10812 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 10813 | struct sk_buff *msg; |
| 10814 | void *hdr; |
| 10815 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10816 | trace_cfg80211_del_sta(dev, mac_addr); |
| 10817 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10818 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 10819 | if (!msg) |
| 10820 | return; |
| 10821 | |
| 10822 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION); |
| 10823 | if (!hdr) { |
| 10824 | nlmsg_free(msg); |
| 10825 | return; |
| 10826 | } |
| 10827 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10828 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 10829 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 10830 | goto nla_put_failure; |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 10831 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10832 | genlmsg_end(msg, hdr); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 10833 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10834 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10835 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 10836 | return; |
| 10837 | |
| 10838 | nla_put_failure: |
| 10839 | genlmsg_cancel(msg, hdr); |
| 10840 | nlmsg_free(msg); |
| 10841 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10842 | EXPORT_SYMBOL(cfg80211_del_sta); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 10843 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10844 | void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr, |
| 10845 | enum nl80211_connect_failed_reason reason, |
| 10846 | gfp_t gfp) |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 10847 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10848 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
| 10849 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 10850 | struct sk_buff *msg; |
| 10851 | void *hdr; |
| 10852 | |
| 10853 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 10854 | if (!msg) |
| 10855 | return; |
| 10856 | |
| 10857 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED); |
| 10858 | if (!hdr) { |
| 10859 | nlmsg_free(msg); |
| 10860 | return; |
| 10861 | } |
| 10862 | |
| 10863 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 10864 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 10865 | nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason)) |
| 10866 | goto nla_put_failure; |
| 10867 | |
| 10868 | genlmsg_end(msg, hdr); |
| 10869 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10870 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10871 | NL80211_MCGRP_MLME, gfp); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 10872 | return; |
| 10873 | |
| 10874 | nla_put_failure: |
| 10875 | genlmsg_cancel(msg, hdr); |
| 10876 | nlmsg_free(msg); |
| 10877 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10878 | EXPORT_SYMBOL(cfg80211_conn_failed); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 10879 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 10880 | static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, |
| 10881 | const u8 *addr, gfp_t gfp) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10882 | { |
| 10883 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10884 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 10885 | struct sk_buff *msg; |
| 10886 | void *hdr; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10887 | u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10888 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10889 | if (!nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10890 | return false; |
| 10891 | |
| 10892 | msg = nlmsg_new(100, gfp); |
| 10893 | if (!msg) |
| 10894 | return true; |
| 10895 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 10896 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10897 | if (!hdr) { |
| 10898 | nlmsg_free(msg); |
| 10899 | return true; |
| 10900 | } |
| 10901 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10902 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10903 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 10904 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 10905 | goto nla_put_failure; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10906 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 10907 | genlmsg_end(msg, hdr); |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10908 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10909 | return true; |
| 10910 | |
| 10911 | nla_put_failure: |
| 10912 | genlmsg_cancel(msg, hdr); |
| 10913 | nlmsg_free(msg); |
| 10914 | return true; |
| 10915 | } |
| 10916 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10917 | bool cfg80211_rx_spurious_frame(struct net_device *dev, |
| 10918 | const u8 *addr, gfp_t gfp) |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 10919 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10920 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10921 | bool ret; |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 10922 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10923 | trace_cfg80211_rx_spurious_frame(dev, addr); |
| 10924 | |
| 10925 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 10926 | wdev->iftype != NL80211_IFTYPE_P2P_GO)) { |
| 10927 | trace_cfg80211_return_bool(false); |
| 10928 | return false; |
| 10929 | } |
| 10930 | ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, |
| 10931 | addr, gfp); |
| 10932 | trace_cfg80211_return_bool(ret); |
| 10933 | return ret; |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 10934 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10935 | EXPORT_SYMBOL(cfg80211_rx_spurious_frame); |
| 10936 | |
| 10937 | bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev, |
| 10938 | const u8 *addr, gfp_t gfp) |
| 10939 | { |
| 10940 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10941 | bool ret; |
| 10942 | |
| 10943 | trace_cfg80211_rx_unexpected_4addr_frame(dev, addr); |
| 10944 | |
| 10945 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 10946 | wdev->iftype != NL80211_IFTYPE_P2P_GO && |
| 10947 | wdev->iftype != NL80211_IFTYPE_AP_VLAN)) { |
| 10948 | trace_cfg80211_return_bool(false); |
| 10949 | return false; |
| 10950 | } |
| 10951 | ret = __nl80211_unexpected_frame(dev, |
| 10952 | NL80211_CMD_UNEXPECTED_4ADDR_FRAME, |
| 10953 | addr, gfp); |
| 10954 | trace_cfg80211_return_bool(ret); |
| 10955 | return ret; |
| 10956 | } |
| 10957 | EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame); |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 10958 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 10959 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10960 | struct wireless_dev *wdev, u32 nlportid, |
Johannes Berg | 804483e | 2012-03-05 22:18:41 +0100 | [diff] [blame] | 10961 | int freq, int sig_dbm, |
Vladimir Kondratiev | 19504cf | 2013-08-15 14:51:28 +0300 | [diff] [blame] | 10962 | const u8 *buf, size_t len, u32 flags, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10963 | { |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10964 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10965 | struct sk_buff *msg; |
| 10966 | void *hdr; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10967 | |
| 10968 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 10969 | if (!msg) |
| 10970 | return -ENOMEM; |
| 10971 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 10972 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10973 | if (!hdr) { |
| 10974 | nlmsg_free(msg); |
| 10975 | return -ENOMEM; |
| 10976 | } |
| 10977 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10978 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10979 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 10980 | netdev->ifindex)) || |
Ilan Peer | a838490 | 2013-05-08 16:35:55 +0300 | [diff] [blame] | 10981 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10982 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
| 10983 | (sig_dbm && |
| 10984 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
Vladimir Kondratiev | 19504cf | 2013-08-15 14:51:28 +0300 | [diff] [blame] | 10985 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
| 10986 | (flags && |
| 10987 | nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10988 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10989 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10990 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10991 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10992 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10993 | |
| 10994 | nla_put_failure: |
| 10995 | genlmsg_cancel(msg, hdr); |
| 10996 | nlmsg_free(msg); |
| 10997 | return -ENOBUFS; |
| 10998 | } |
| 10999 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11000 | void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie, |
| 11001 | const u8 *buf, size_t len, bool ack, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11002 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11003 | struct wiphy *wiphy = wdev->wiphy; |
| 11004 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11005 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11006 | struct sk_buff *msg; |
| 11007 | void *hdr; |
| 11008 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11009 | trace_cfg80211_mgmt_tx_status(wdev, cookie, ack); |
| 11010 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11011 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 11012 | if (!msg) |
| 11013 | return; |
| 11014 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 11015 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11016 | if (!hdr) { |
| 11017 | nlmsg_free(msg); |
| 11018 | return; |
| 11019 | } |
| 11020 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11021 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11022 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 11023 | netdev->ifindex)) || |
Ilan Peer | a838490 | 2013-05-08 16:35:55 +0300 | [diff] [blame] | 11024 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11025 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
| 11026 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || |
| 11027 | (ack && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 11028 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11029 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11030 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11031 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11032 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11033 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11034 | return; |
| 11035 | |
| 11036 | nla_put_failure: |
| 11037 | genlmsg_cancel(msg, hdr); |
| 11038 | nlmsg_free(msg); |
| 11039 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11040 | EXPORT_SYMBOL(cfg80211_mgmt_tx_status); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11041 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11042 | void cfg80211_cqm_rssi_notify(struct net_device *dev, |
| 11043 | enum nl80211_cqm_rssi_threshold_event rssi_event, |
| 11044 | gfp_t gfp) |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11045 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11046 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11047 | struct wiphy *wiphy = wdev->wiphy; |
| 11048 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11049 | struct sk_buff *msg; |
| 11050 | struct nlattr *pinfoattr; |
| 11051 | void *hdr; |
| 11052 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11053 | trace_cfg80211_cqm_rssi_notify(dev, rssi_event); |
| 11054 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11055 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11056 | if (!msg) |
| 11057 | return; |
| 11058 | |
| 11059 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 11060 | if (!hdr) { |
| 11061 | nlmsg_free(msg); |
| 11062 | return; |
| 11063 | } |
| 11064 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11065 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11066 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11067 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11068 | |
| 11069 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 11070 | if (!pinfoattr) |
| 11071 | goto nla_put_failure; |
| 11072 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11073 | if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, |
| 11074 | rssi_event)) |
| 11075 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11076 | |
| 11077 | nla_nest_end(msg, pinfoattr); |
| 11078 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11079 | genlmsg_end(msg, hdr); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11080 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11081 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11082 | NL80211_MCGRP_MLME, gfp); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11083 | return; |
| 11084 | |
| 11085 | nla_put_failure: |
| 11086 | genlmsg_cancel(msg, hdr); |
| 11087 | nlmsg_free(msg); |
| 11088 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11089 | EXPORT_SYMBOL(cfg80211_cqm_rssi_notify); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11090 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11091 | static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
| 11092 | struct net_device *netdev, const u8 *bssid, |
| 11093 | const u8 *replay_ctr, gfp_t gfp) |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 11094 | { |
| 11095 | struct sk_buff *msg; |
| 11096 | struct nlattr *rekey_attr; |
| 11097 | void *hdr; |
| 11098 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11099 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 11100 | if (!msg) |
| 11101 | return; |
| 11102 | |
| 11103 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); |
| 11104 | if (!hdr) { |
| 11105 | nlmsg_free(msg); |
| 11106 | return; |
| 11107 | } |
| 11108 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11109 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11110 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 11111 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 11112 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 11113 | |
| 11114 | rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); |
| 11115 | if (!rekey_attr) |
| 11116 | goto nla_put_failure; |
| 11117 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11118 | if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
| 11119 | NL80211_REPLAY_CTR_LEN, replay_ctr)) |
| 11120 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 11121 | |
| 11122 | nla_nest_end(msg, rekey_attr); |
| 11123 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11124 | genlmsg_end(msg, hdr); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 11125 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11126 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11127 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 11128 | return; |
| 11129 | |
| 11130 | nla_put_failure: |
| 11131 | genlmsg_cancel(msg, hdr); |
| 11132 | nlmsg_free(msg); |
| 11133 | } |
| 11134 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11135 | void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid, |
| 11136 | const u8 *replay_ctr, gfp_t gfp) |
| 11137 | { |
| 11138 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11139 | struct wiphy *wiphy = wdev->wiphy; |
| 11140 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 11141 | |
| 11142 | trace_cfg80211_gtk_rekey_notify(dev, bssid); |
| 11143 | nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp); |
| 11144 | } |
| 11145 | EXPORT_SYMBOL(cfg80211_gtk_rekey_notify); |
| 11146 | |
| 11147 | static void |
| 11148 | nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, |
| 11149 | struct net_device *netdev, int index, |
| 11150 | const u8 *bssid, bool preauth, gfp_t gfp) |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 11151 | { |
| 11152 | struct sk_buff *msg; |
| 11153 | struct nlattr *attr; |
| 11154 | void *hdr; |
| 11155 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11156 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 11157 | if (!msg) |
| 11158 | return; |
| 11159 | |
| 11160 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); |
| 11161 | if (!hdr) { |
| 11162 | nlmsg_free(msg); |
| 11163 | return; |
| 11164 | } |
| 11165 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11166 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11167 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 11168 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 11169 | |
| 11170 | attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE); |
| 11171 | if (!attr) |
| 11172 | goto nla_put_failure; |
| 11173 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11174 | if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) || |
| 11175 | nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) || |
| 11176 | (preauth && |
| 11177 | nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH))) |
| 11178 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 11179 | |
| 11180 | nla_nest_end(msg, attr); |
| 11181 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11182 | genlmsg_end(msg, hdr); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 11183 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11184 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11185 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 11186 | return; |
| 11187 | |
| 11188 | nla_put_failure: |
| 11189 | genlmsg_cancel(msg, hdr); |
| 11190 | nlmsg_free(msg); |
| 11191 | } |
| 11192 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11193 | void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index, |
| 11194 | const u8 *bssid, bool preauth, gfp_t gfp) |
| 11195 | { |
| 11196 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11197 | struct wiphy *wiphy = wdev->wiphy; |
| 11198 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 11199 | |
| 11200 | trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth); |
| 11201 | nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp); |
| 11202 | } |
| 11203 | EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify); |
| 11204 | |
| 11205 | static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev, |
| 11206 | struct net_device *netdev, |
| 11207 | struct cfg80211_chan_def *chandef, |
| 11208 | gfp_t gfp) |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 11209 | { |
| 11210 | struct sk_buff *msg; |
| 11211 | void *hdr; |
| 11212 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11213 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 11214 | if (!msg) |
| 11215 | return; |
| 11216 | |
| 11217 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY); |
| 11218 | if (!hdr) { |
| 11219 | nlmsg_free(msg); |
| 11220 | return; |
| 11221 | } |
| 11222 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 11223 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 11224 | goto nla_put_failure; |
| 11225 | |
| 11226 | if (nl80211_send_chandef(msg, chandef)) |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 11227 | goto nla_put_failure; |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 11228 | |
| 11229 | genlmsg_end(msg, hdr); |
| 11230 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11231 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11232 | NL80211_MCGRP_MLME, gfp); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 11233 | return; |
| 11234 | |
| 11235 | nla_put_failure: |
| 11236 | genlmsg_cancel(msg, hdr); |
| 11237 | nlmsg_free(msg); |
| 11238 | } |
| 11239 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11240 | void cfg80211_ch_switch_notify(struct net_device *dev, |
| 11241 | struct cfg80211_chan_def *chandef) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 11242 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11243 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11244 | struct wiphy *wiphy = wdev->wiphy; |
| 11245 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 11246 | |
Simon Wunderlich | e487eae | 2013-11-21 18:19:51 +0100 | [diff] [blame] | 11247 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11248 | |
Simon Wunderlich | e487eae | 2013-11-21 18:19:51 +0100 | [diff] [blame] | 11249 | trace_cfg80211_ch_switch_notify(dev, chandef); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11250 | |
| 11251 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 11252 | wdev->iftype != NL80211_IFTYPE_P2P_GO && |
Chun-Yeow Yeoh | b8456a1 | 2013-10-17 15:55:02 -0700 | [diff] [blame] | 11253 | wdev->iftype != NL80211_IFTYPE_ADHOC && |
| 11254 | wdev->iftype != NL80211_IFTYPE_MESH_POINT)) |
Simon Wunderlich | e487eae | 2013-11-21 18:19:51 +0100 | [diff] [blame] | 11255 | return; |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11256 | |
Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 11257 | wdev->chandef = *chandef; |
Janusz Dziedzic | 96f55f1 | 2014-01-24 14:29:21 +0100 | [diff] [blame] | 11258 | wdev->preset_chandef = *chandef; |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11259 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11260 | } |
| 11261 | EXPORT_SYMBOL(cfg80211_ch_switch_notify); |
| 11262 | |
| 11263 | void cfg80211_cqm_txe_notify(struct net_device *dev, |
| 11264 | const u8 *peer, u32 num_packets, |
| 11265 | u32 rate, u32 intvl, gfp_t gfp) |
| 11266 | { |
| 11267 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11268 | struct wiphy *wiphy = wdev->wiphy; |
| 11269 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 11270 | struct sk_buff *msg; |
| 11271 | struct nlattr *pinfoattr; |
| 11272 | void *hdr; |
| 11273 | |
| 11274 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 11275 | if (!msg) |
| 11276 | return; |
| 11277 | |
| 11278 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 11279 | if (!hdr) { |
| 11280 | nlmsg_free(msg); |
| 11281 | return; |
| 11282 | } |
| 11283 | |
| 11284 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11285 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 11286 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
| 11287 | goto nla_put_failure; |
| 11288 | |
| 11289 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 11290 | if (!pinfoattr) |
| 11291 | goto nla_put_failure; |
| 11292 | |
| 11293 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets)) |
| 11294 | goto nla_put_failure; |
| 11295 | |
| 11296 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate)) |
| 11297 | goto nla_put_failure; |
| 11298 | |
| 11299 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl)) |
| 11300 | goto nla_put_failure; |
| 11301 | |
| 11302 | nla_nest_end(msg, pinfoattr); |
| 11303 | |
| 11304 | genlmsg_end(msg, hdr); |
| 11305 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11306 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11307 | NL80211_MCGRP_MLME, gfp); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 11308 | return; |
| 11309 | |
| 11310 | nla_put_failure: |
| 11311 | genlmsg_cancel(msg, hdr); |
| 11312 | nlmsg_free(msg); |
| 11313 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11314 | EXPORT_SYMBOL(cfg80211_cqm_txe_notify); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 11315 | |
| 11316 | void |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 11317 | nl80211_radar_notify(struct cfg80211_registered_device *rdev, |
Janusz Dziedzic | d2859df | 2013-11-06 13:55:51 +0100 | [diff] [blame] | 11318 | const struct cfg80211_chan_def *chandef, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 11319 | enum nl80211_radar_event event, |
| 11320 | struct net_device *netdev, gfp_t gfp) |
| 11321 | { |
| 11322 | struct sk_buff *msg; |
| 11323 | void *hdr; |
| 11324 | |
| 11325 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 11326 | if (!msg) |
| 11327 | return; |
| 11328 | |
| 11329 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT); |
| 11330 | if (!hdr) { |
| 11331 | nlmsg_free(msg); |
| 11332 | return; |
| 11333 | } |
| 11334 | |
| 11335 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 11336 | goto nla_put_failure; |
| 11337 | |
| 11338 | /* NOP and radar events don't need a netdev parameter */ |
| 11339 | if (netdev) { |
| 11340 | struct wireless_dev *wdev = netdev->ieee80211_ptr; |
| 11341 | |
| 11342 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 11343 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 11344 | goto nla_put_failure; |
| 11345 | } |
| 11346 | |
| 11347 | if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event)) |
| 11348 | goto nla_put_failure; |
| 11349 | |
| 11350 | if (nl80211_send_chandef(msg, chandef)) |
| 11351 | goto nla_put_failure; |
| 11352 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 11353 | genlmsg_end(msg, hdr); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 11354 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11355 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11356 | NL80211_MCGRP_MLME, gfp); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 11357 | return; |
| 11358 | |
| 11359 | nla_put_failure: |
| 11360 | genlmsg_cancel(msg, hdr); |
| 11361 | nlmsg_free(msg); |
| 11362 | } |
| 11363 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11364 | void cfg80211_cqm_pktloss_notify(struct net_device *dev, |
| 11365 | const u8 *peer, u32 num_packets, gfp_t gfp) |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 11366 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11367 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11368 | struct wiphy *wiphy = wdev->wiphy; |
| 11369 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 11370 | struct sk_buff *msg; |
| 11371 | struct nlattr *pinfoattr; |
| 11372 | void *hdr; |
| 11373 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11374 | trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets); |
| 11375 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11376 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 11377 | if (!msg) |
| 11378 | return; |
| 11379 | |
| 11380 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 11381 | if (!hdr) { |
| 11382 | nlmsg_free(msg); |
| 11383 | return; |
| 11384 | } |
| 11385 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11386 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11387 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11388 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
| 11389 | goto nla_put_failure; |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 11390 | |
| 11391 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 11392 | if (!pinfoattr) |
| 11393 | goto nla_put_failure; |
| 11394 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11395 | if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets)) |
| 11396 | goto nla_put_failure; |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 11397 | |
| 11398 | nla_nest_end(msg, pinfoattr); |
| 11399 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11400 | genlmsg_end(msg, hdr); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 11401 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11402 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11403 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 11404 | return; |
| 11405 | |
| 11406 | nla_put_failure: |
| 11407 | genlmsg_cancel(msg, hdr); |
| 11408 | nlmsg_free(msg); |
| 11409 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11410 | EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 11411 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11412 | void cfg80211_probe_status(struct net_device *dev, const u8 *addr, |
| 11413 | u64 cookie, bool acked, gfp_t gfp) |
| 11414 | { |
| 11415 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11416 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 11417 | struct sk_buff *msg; |
| 11418 | void *hdr; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11419 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 11420 | trace_cfg80211_probe_status(dev, addr, cookie, acked); |
| 11421 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11422 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 11423 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11424 | if (!msg) |
| 11425 | return; |
| 11426 | |
| 11427 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); |
| 11428 | if (!hdr) { |
| 11429 | nlmsg_free(msg); |
| 11430 | return; |
| 11431 | } |
| 11432 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11433 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11434 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 11435 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 11436 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || |
| 11437 | (acked && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 11438 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11439 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 11440 | genlmsg_end(msg, hdr); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11441 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11442 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11443 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11444 | return; |
| 11445 | |
| 11446 | nla_put_failure: |
| 11447 | genlmsg_cancel(msg, hdr); |
| 11448 | nlmsg_free(msg); |
| 11449 | } |
| 11450 | EXPORT_SYMBOL(cfg80211_probe_status); |
| 11451 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11452 | void cfg80211_report_obss_beacon(struct wiphy *wiphy, |
| 11453 | const u8 *frame, size_t len, |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11454 | int freq, int sig_dbm) |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11455 | { |
| 11456 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 11457 | struct sk_buff *msg; |
| 11458 | void *hdr; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11459 | struct cfg80211_beacon_registration *reg; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11460 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 11461 | trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm); |
| 11462 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11463 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 11464 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 11465 | msg = nlmsg_new(len + 100, GFP_ATOMIC); |
| 11466 | if (!msg) { |
| 11467 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 11468 | return; |
| 11469 | } |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11470 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11471 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
| 11472 | if (!hdr) |
| 11473 | goto nla_put_failure; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11474 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11475 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11476 | (freq && |
| 11477 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || |
| 11478 | (sig_dbm && |
| 11479 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
| 11480 | nla_put(msg, NL80211_ATTR_FRAME, len, frame)) |
| 11481 | goto nla_put_failure; |
| 11482 | |
| 11483 | genlmsg_end(msg, hdr); |
| 11484 | |
| 11485 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11486 | } |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11487 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11488 | return; |
| 11489 | |
| 11490 | nla_put_failure: |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11491 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 11492 | if (hdr) |
| 11493 | genlmsg_cancel(msg, hdr); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11494 | nlmsg_free(msg); |
| 11495 | } |
| 11496 | EXPORT_SYMBOL(cfg80211_report_obss_beacon); |
| 11497 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 11498 | #ifdef CONFIG_PM |
| 11499 | void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev, |
| 11500 | struct cfg80211_wowlan_wakeup *wakeup, |
| 11501 | gfp_t gfp) |
| 11502 | { |
| 11503 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 11504 | struct sk_buff *msg; |
| 11505 | void *hdr; |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 11506 | int size = 200; |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 11507 | |
| 11508 | trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup); |
| 11509 | |
| 11510 | if (wakeup) |
| 11511 | size += wakeup->packet_present_len; |
| 11512 | |
| 11513 | msg = nlmsg_new(size, gfp); |
| 11514 | if (!msg) |
| 11515 | return; |
| 11516 | |
| 11517 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN); |
| 11518 | if (!hdr) |
| 11519 | goto free_msg; |
| 11520 | |
| 11521 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11522 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 11523 | goto free_msg; |
| 11524 | |
| 11525 | if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 11526 | wdev->netdev->ifindex)) |
| 11527 | goto free_msg; |
| 11528 | |
| 11529 | if (wakeup) { |
| 11530 | struct nlattr *reasons; |
| 11531 | |
| 11532 | reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
Johannes Berg | 7fa322c | 2013-10-25 11:16:58 +0200 | [diff] [blame] | 11533 | if (!reasons) |
| 11534 | goto free_msg; |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 11535 | |
| 11536 | if (wakeup->disconnect && |
| 11537 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) |
| 11538 | goto free_msg; |
| 11539 | if (wakeup->magic_pkt && |
| 11540 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) |
| 11541 | goto free_msg; |
| 11542 | if (wakeup->gtk_rekey_failure && |
| 11543 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) |
| 11544 | goto free_msg; |
| 11545 | if (wakeup->eap_identity_req && |
| 11546 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) |
| 11547 | goto free_msg; |
| 11548 | if (wakeup->four_way_handshake && |
| 11549 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) |
| 11550 | goto free_msg; |
| 11551 | if (wakeup->rfkill_release && |
| 11552 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)) |
| 11553 | goto free_msg; |
| 11554 | |
| 11555 | if (wakeup->pattern_idx >= 0 && |
| 11556 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 11557 | wakeup->pattern_idx)) |
| 11558 | goto free_msg; |
| 11559 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 11560 | if (wakeup->tcp_match && |
| 11561 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH)) |
| 11562 | goto free_msg; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11563 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 11564 | if (wakeup->tcp_connlost && |
| 11565 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST)) |
| 11566 | goto free_msg; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11567 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 11568 | if (wakeup->tcp_nomoretokens && |
| 11569 | nla_put_flag(msg, |
| 11570 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS)) |
| 11571 | goto free_msg; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11572 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 11573 | if (wakeup->packet) { |
| 11574 | u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211; |
| 11575 | u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN; |
| 11576 | |
| 11577 | if (!wakeup->packet_80211) { |
| 11578 | pkt_attr = |
| 11579 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023; |
| 11580 | len_attr = |
| 11581 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN; |
| 11582 | } |
| 11583 | |
| 11584 | if (wakeup->packet_len && |
| 11585 | nla_put_u32(msg, len_attr, wakeup->packet_len)) |
| 11586 | goto free_msg; |
| 11587 | |
| 11588 | if (nla_put(msg, pkt_attr, wakeup->packet_present_len, |
| 11589 | wakeup->packet)) |
| 11590 | goto free_msg; |
| 11591 | } |
| 11592 | |
| 11593 | nla_nest_end(msg, reasons); |
| 11594 | } |
| 11595 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 11596 | genlmsg_end(msg, hdr); |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 11597 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11598 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11599 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 11600 | return; |
| 11601 | |
| 11602 | free_msg: |
| 11603 | nlmsg_free(msg); |
| 11604 | } |
| 11605 | EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup); |
| 11606 | #endif |
| 11607 | |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 11608 | void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer, |
| 11609 | enum nl80211_tdls_operation oper, |
| 11610 | u16 reason_code, gfp_t gfp) |
| 11611 | { |
| 11612 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11613 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 11614 | struct sk_buff *msg; |
| 11615 | void *hdr; |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 11616 | |
| 11617 | trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper, |
| 11618 | reason_code); |
| 11619 | |
| 11620 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 11621 | if (!msg) |
| 11622 | return; |
| 11623 | |
| 11624 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER); |
| 11625 | if (!hdr) { |
| 11626 | nlmsg_free(msg); |
| 11627 | return; |
| 11628 | } |
| 11629 | |
| 11630 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11631 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 11632 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) || |
| 11633 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) || |
| 11634 | (reason_code > 0 && |
| 11635 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) |
| 11636 | goto nla_put_failure; |
| 11637 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 11638 | genlmsg_end(msg, hdr); |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 11639 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11640 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11641 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 11642 | return; |
| 11643 | |
| 11644 | nla_put_failure: |
| 11645 | genlmsg_cancel(msg, hdr); |
| 11646 | nlmsg_free(msg); |
| 11647 | } |
| 11648 | EXPORT_SYMBOL(cfg80211_tdls_oper_request); |
| 11649 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11650 | static int nl80211_netlink_notify(struct notifier_block * nb, |
| 11651 | unsigned long state, |
| 11652 | void *_notify) |
| 11653 | { |
| 11654 | struct netlink_notify *notify = _notify; |
| 11655 | struct cfg80211_registered_device *rdev; |
| 11656 | struct wireless_dev *wdev; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11657 | struct cfg80211_beacon_registration *reg, *tmp; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11658 | |
| 11659 | if (state != NETLINK_URELEASE) |
| 11660 | return NOTIFY_DONE; |
| 11661 | |
| 11662 | rcu_read_lock(); |
| 11663 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11664 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 11665 | bool schedule_destroy_work = false; |
| 11666 | |
| 11667 | list_for_each_entry_rcu(wdev, &rdev->wdev_list, list) { |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11668 | cfg80211_mlme_unregister_socket(wdev, notify->portid); |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11669 | |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 11670 | if (wdev->owner_nlportid == notify->portid) |
| 11671 | schedule_destroy_work = true; |
| 11672 | } |
| 11673 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11674 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 11675 | list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations, |
| 11676 | list) { |
| 11677 | if (reg->nlportid == notify->portid) { |
| 11678 | list_del(®->list); |
| 11679 | kfree(reg); |
| 11680 | break; |
| 11681 | } |
| 11682 | } |
| 11683 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 11684 | |
| 11685 | if (schedule_destroy_work) { |
| 11686 | struct cfg80211_iface_destroy *destroy; |
| 11687 | |
| 11688 | destroy = kzalloc(sizeof(*destroy), GFP_ATOMIC); |
| 11689 | if (destroy) { |
| 11690 | destroy->nlportid = notify->portid; |
| 11691 | spin_lock(&rdev->destroy_list_lock); |
| 11692 | list_add(&destroy->list, &rdev->destroy_list); |
| 11693 | spin_unlock(&rdev->destroy_list_lock); |
| 11694 | schedule_work(&rdev->destroy_work); |
| 11695 | } |
| 11696 | } |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11697 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11698 | |
| 11699 | rcu_read_unlock(); |
| 11700 | |
| 11701 | return NOTIFY_DONE; |
| 11702 | } |
| 11703 | |
| 11704 | static struct notifier_block nl80211_netlink_notifier = { |
| 11705 | .notifier_call = nl80211_netlink_notify, |
| 11706 | }; |
| 11707 | |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 11708 | void cfg80211_ft_event(struct net_device *netdev, |
| 11709 | struct cfg80211_ft_event_params *ft_event) |
| 11710 | { |
| 11711 | struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy; |
| 11712 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 11713 | struct sk_buff *msg; |
| 11714 | void *hdr; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 11715 | |
| 11716 | trace_cfg80211_ft_event(wiphy, netdev, ft_event); |
| 11717 | |
| 11718 | if (!ft_event->target_ap) |
| 11719 | return; |
| 11720 | |
| 11721 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 11722 | if (!msg) |
| 11723 | return; |
| 11724 | |
| 11725 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT); |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 11726 | if (!hdr) |
| 11727 | goto out; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 11728 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 11729 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11730 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 11731 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap)) |
| 11732 | goto out; |
| 11733 | |
| 11734 | if (ft_event->ies && |
| 11735 | nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies)) |
| 11736 | goto out; |
| 11737 | if (ft_event->ric_ies && |
| 11738 | nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len, |
| 11739 | ft_event->ric_ies)) |
| 11740 | goto out; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 11741 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 11742 | genlmsg_end(msg, hdr); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 11743 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11744 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11745 | NL80211_MCGRP_MLME, GFP_KERNEL); |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 11746 | return; |
| 11747 | out: |
| 11748 | nlmsg_free(msg); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 11749 | } |
| 11750 | EXPORT_SYMBOL(cfg80211_ft_event); |
| 11751 | |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 11752 | void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp) |
| 11753 | { |
| 11754 | struct cfg80211_registered_device *rdev; |
| 11755 | struct sk_buff *msg; |
| 11756 | void *hdr; |
| 11757 | u32 nlportid; |
| 11758 | |
| 11759 | rdev = wiphy_to_dev(wdev->wiphy); |
| 11760 | if (!rdev->crit_proto_nlportid) |
| 11761 | return; |
| 11762 | |
| 11763 | nlportid = rdev->crit_proto_nlportid; |
| 11764 | rdev->crit_proto_nlportid = 0; |
| 11765 | |
| 11766 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 11767 | if (!msg) |
| 11768 | return; |
| 11769 | |
| 11770 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP); |
| 11771 | if (!hdr) |
| 11772 | goto nla_put_failure; |
| 11773 | |
| 11774 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11775 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 11776 | goto nla_put_failure; |
| 11777 | |
| 11778 | genlmsg_end(msg, hdr); |
| 11779 | |
| 11780 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
| 11781 | return; |
| 11782 | |
| 11783 | nla_put_failure: |
| 11784 | if (hdr) |
| 11785 | genlmsg_cancel(msg, hdr); |
| 11786 | nlmsg_free(msg); |
| 11787 | |
| 11788 | } |
| 11789 | EXPORT_SYMBOL(cfg80211_crit_proto_stopped); |
| 11790 | |
Johannes Berg | 348baf0 | 2014-01-24 14:06:29 +0100 | [diff] [blame] | 11791 | void nl80211_send_ap_stopped(struct wireless_dev *wdev) |
| 11792 | { |
| 11793 | struct wiphy *wiphy = wdev->wiphy; |
| 11794 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 11795 | struct sk_buff *msg; |
| 11796 | void *hdr; |
| 11797 | |
| 11798 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 11799 | if (!msg) |
| 11800 | return; |
| 11801 | |
| 11802 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP); |
| 11803 | if (!hdr) |
| 11804 | goto out; |
| 11805 | |
| 11806 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11807 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) || |
| 11808 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 11809 | goto out; |
| 11810 | |
| 11811 | genlmsg_end(msg, hdr); |
| 11812 | |
| 11813 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0, |
| 11814 | NL80211_MCGRP_MLME, GFP_KERNEL); |
| 11815 | return; |
| 11816 | out: |
| 11817 | nlmsg_free(msg); |
| 11818 | } |
| 11819 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11820 | /* initialisation/exit functions */ |
| 11821 | |
| 11822 | int nl80211_init(void) |
| 11823 | { |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 11824 | int err; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11825 | |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11826 | err = genl_register_family_with_ops_groups(&nl80211_fam, nl80211_ops, |
| 11827 | nl80211_mcgrps); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11828 | if (err) |
| 11829 | return err; |
| 11830 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11831 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
| 11832 | if (err) |
| 11833 | goto err_out; |
| 11834 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11835 | return 0; |
| 11836 | err_out: |
| 11837 | genl_unregister_family(&nl80211_fam); |
| 11838 | return err; |
| 11839 | } |
| 11840 | |
| 11841 | void nl80211_exit(void) |
| 11842 | { |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11843 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11844 | genl_unregister_family(&nl80211_fam); |
| 11845 | } |