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 | 36aedc90 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 272 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 273 | [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 274 | [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 275 | |
Johannes Berg | 6c73941 | 2011-11-03 09:27:01 +0100 | [diff] [blame] | 276 | [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 277 | |
| 278 | [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 }, |
| 279 | [NL80211_ATTR_IE] = { .type = NLA_BINARY, |
| 280 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 281 | [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED }, |
| 282 | [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 283 | |
| 284 | [NL80211_ATTR_SSID] = { .type = NLA_BINARY, |
| 285 | .len = IEEE80211_MAX_SSID_LEN }, |
| 286 | [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 }, |
| 287 | [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 288 | [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG }, |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 289 | [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG }, |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 290 | [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 }, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 291 | [NL80211_ATTR_STA_FLAGS2] = { |
| 292 | .len = sizeof(struct nl80211_sta_flag_update), |
| 293 | }, |
Jouni Malinen | 3f77316c | 2009-05-11 21:57:57 +0300 | [diff] [blame] | 294 | [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG }, |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 295 | [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 }, |
| 296 | [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG }, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 297 | [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG }, |
| 298 | [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 }, |
| 299 | [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 300 | [NL80211_ATTR_PID] = { .type = NLA_U32 }, |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 301 | [NL80211_ATTR_4ADDR] = { .type = NLA_U8 }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 302 | [NL80211_ATTR_PMKID] = { .type = NLA_BINARY, |
| 303 | .len = WLAN_PMKID_LEN }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 304 | [NL80211_ATTR_DURATION] = { .type = NLA_U32 }, |
| 305 | [NL80211_ATTR_COOKIE] = { .type = NLA_U64 }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 306 | [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 307 | [NL80211_ATTR_FRAME] = { .type = NLA_BINARY, |
| 308 | .len = IEEE80211_MAX_DATA_LEN }, |
| 309 | [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 310 | [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 311 | [NL80211_ATTR_CQM] = { .type = NLA_NESTED, }, |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 312 | [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG }, |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 313 | [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 }, |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 314 | [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 }, |
| 315 | [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 }, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 316 | [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 }, |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 317 | [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 }, |
| 318 | [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 }, |
Felix Fietkau | 885a46d | 2010-11-11 15:07:22 +0100 | [diff] [blame] | 319 | [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 }, |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 320 | [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 321 | [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 322 | [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED }, |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 323 | [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 }, |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 324 | [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 }, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 325 | [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED }, |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 326 | [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED }, |
Jouni Malinen | 32e9de8 | 2011-08-10 23:53:31 +0300 | [diff] [blame] | 327 | [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 }, |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 328 | [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY, |
| 329 | .len = IEEE80211_MAX_DATA_LEN }, |
| 330 | [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY, |
| 331 | .len = IEEE80211_MAX_DATA_LEN }, |
Vivek Natarajan | f4b34b5 | 2011-08-29 14:23:03 +0530 | [diff] [blame] | 332 | [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG }, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 333 | [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED }, |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 334 | [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 335 | [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 }, |
| 336 | [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 }, |
| 337 | [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 }, |
| 338 | [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG }, |
| 339 | [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG }, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 340 | [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG }, |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 341 | [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY, |
| 342 | .len = IEEE80211_MAX_DATA_LEN }, |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 343 | [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 }, |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 344 | [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG }, |
| 345 | [NL80211_ATTR_HT_CAPABILITY_MASK] = { |
| 346 | .len = NL80211_HT_CAPABILITY_LEN |
| 347 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 348 | [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 }, |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 349 | [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 }, |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 350 | [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 }, |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 351 | [NL80211_ATTR_WDEV] = { .type = NLA_U64 }, |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 352 | [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 }, |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 353 | [NL80211_ATTR_SAE_DATA] = { .type = NLA_BINARY, }, |
Mahesh Palivela | f461be3e | 2012-10-11 08:04:52 +0000 | [diff] [blame] | 354 | [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN }, |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 355 | [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 }, |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 356 | [NL80211_ATTR_P2P_CTWINDOW] = { .type = NLA_U8 }, |
| 357 | [NL80211_ATTR_P2P_OPPPS] = { .type = NLA_U8 }, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 358 | [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 }, |
| 359 | [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED }, |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 360 | [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 }, |
| 361 | [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, }, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 362 | [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, }, |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 363 | [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG }, |
| 364 | [NL80211_ATTR_VHT_CAPABILITY_MASK] = { |
| 365 | .len = NL80211_VHT_CAPABILITY_LEN, |
| 366 | }, |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 367 | [NL80211_ATTR_MDID] = { .type = NLA_U16 }, |
| 368 | [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY, |
| 369 | .len = IEEE80211_MAX_DATA_LEN }, |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 370 | [NL80211_ATTR_PEER_AID] = { .type = NLA_U16 }, |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 371 | [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 }, |
| 372 | [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG }, |
| 373 | [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED }, |
| 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 }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 385 | }; |
| 386 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 387 | /* policy for the key attributes */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 388 | static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 389 | [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 390 | [NL80211_KEY_IDX] = { .type = NLA_U8 }, |
| 391 | [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, |
Jouni Malinen | 8196226 | 2011-11-02 23:36:31 +0200 | [diff] [blame] | 392 | [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 393 | [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, |
| 394 | [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 395 | [NL80211_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 396 | [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
| 397 | }; |
| 398 | |
| 399 | /* policy for the key default flags */ |
| 400 | static const struct nla_policy |
| 401 | nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = { |
| 402 | [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG }, |
| 403 | [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 404 | }; |
| 405 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 406 | /* policy for WoWLAN attributes */ |
| 407 | static const struct nla_policy |
| 408 | nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = { |
| 409 | [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG }, |
| 410 | [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG }, |
| 411 | [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG }, |
| 412 | [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED }, |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 413 | [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG }, |
| 414 | [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG }, |
| 415 | [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG }, |
| 416 | [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG }, |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 417 | [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED }, |
| 418 | }; |
| 419 | |
| 420 | static const struct nla_policy |
| 421 | nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = { |
| 422 | [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 }, |
| 423 | [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 }, |
| 424 | [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN }, |
| 425 | [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 }, |
| 426 | [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 }, |
| 427 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 }, |
| 428 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = { |
| 429 | .len = sizeof(struct nl80211_wowlan_tcp_data_seq) |
| 430 | }, |
| 431 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = { |
| 432 | .len = sizeof(struct nl80211_wowlan_tcp_data_token) |
| 433 | }, |
| 434 | [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 }, |
| 435 | [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 }, |
| 436 | [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 437 | }; |
| 438 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 439 | /* policy for coalesce rule attributes */ |
| 440 | static const struct nla_policy |
| 441 | nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = { |
| 442 | [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 }, |
| 443 | [NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 }, |
| 444 | [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED }, |
| 445 | }; |
| 446 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 447 | /* policy for GTK rekey offload attributes */ |
| 448 | static const struct nla_policy |
| 449 | nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = { |
| 450 | [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN }, |
| 451 | [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN }, |
| 452 | [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN }, |
| 453 | }; |
| 454 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 455 | static const struct nla_policy |
| 456 | nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = { |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 457 | [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 458 | .len = IEEE80211_MAX_SSID_LEN }, |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 459 | [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 }, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 460 | }; |
| 461 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 462 | static int nl80211_prepare_wdev_dump(struct sk_buff *skb, |
| 463 | struct netlink_callback *cb, |
| 464 | struct cfg80211_registered_device **rdev, |
| 465 | struct wireless_dev **wdev) |
Holger Schurig | a043897 | 2009-11-11 11:30:02 +0100 | [diff] [blame] | 466 | { |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 467 | int err; |
| 468 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 469 | rtnl_lock(); |
| 470 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 471 | if (!cb->args[0]) { |
| 472 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 473 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 474 | nl80211_policy); |
| 475 | if (err) |
| 476 | goto out_unlock; |
| 477 | |
| 478 | *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk), |
| 479 | nl80211_fam.attrbuf); |
| 480 | if (IS_ERR(*wdev)) { |
| 481 | err = PTR_ERR(*wdev); |
| 482 | goto out_unlock; |
| 483 | } |
| 484 | *rdev = wiphy_to_dev((*wdev)->wiphy); |
Johannes Berg | c319d50 | 2013-07-30 22:34:28 +0200 | [diff] [blame] | 485 | /* 0 is the first index - add 1 to parse only once */ |
| 486 | cb->args[0] = (*rdev)->wiphy_idx + 1; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 487 | cb->args[1] = (*wdev)->identifier; |
| 488 | } else { |
Johannes Berg | c319d50 | 2013-07-30 22:34:28 +0200 | [diff] [blame] | 489 | /* subtract the 1 again here */ |
| 490 | struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1); |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 491 | struct wireless_dev *tmp; |
| 492 | |
| 493 | if (!wiphy) { |
| 494 | err = -ENODEV; |
| 495 | goto out_unlock; |
| 496 | } |
| 497 | *rdev = wiphy_to_dev(wiphy); |
| 498 | *wdev = NULL; |
| 499 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 500 | list_for_each_entry(tmp, &(*rdev)->wdev_list, list) { |
| 501 | if (tmp->identifier == cb->args[1]) { |
| 502 | *wdev = tmp; |
| 503 | break; |
| 504 | } |
| 505 | } |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 506 | |
| 507 | if (!*wdev) { |
| 508 | err = -ENODEV; |
| 509 | goto out_unlock; |
| 510 | } |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 511 | } |
| 512 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 513 | return 0; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 514 | out_unlock: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 515 | rtnl_unlock(); |
| 516 | return err; |
| 517 | } |
| 518 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 519 | static void nl80211_finish_wdev_dump(struct cfg80211_registered_device *rdev) |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 520 | { |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 521 | rtnl_unlock(); |
| 522 | } |
| 523 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 524 | /* IE validation */ |
| 525 | static bool is_valid_ie_attr(const struct nlattr *attr) |
| 526 | { |
| 527 | const u8 *pos; |
| 528 | int len; |
| 529 | |
| 530 | if (!attr) |
| 531 | return true; |
| 532 | |
| 533 | pos = nla_data(attr); |
| 534 | len = nla_len(attr); |
| 535 | |
| 536 | while (len) { |
| 537 | u8 elemlen; |
| 538 | |
| 539 | if (len < 2) |
| 540 | return false; |
| 541 | len -= 2; |
| 542 | |
| 543 | elemlen = pos[1]; |
| 544 | if (elemlen > len) |
| 545 | return false; |
| 546 | |
| 547 | len -= elemlen; |
| 548 | pos += 2 + elemlen; |
| 549 | } |
| 550 | |
| 551 | return true; |
| 552 | } |
| 553 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 554 | /* message building helper */ |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 555 | 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] | 556 | int flags, u8 cmd) |
| 557 | { |
| 558 | /* since there is no private header just add the generic one */ |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 559 | return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 560 | } |
| 561 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 562 | static int nl80211_msg_put_channel(struct sk_buff *msg, |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 563 | struct ieee80211_channel *chan, |
| 564 | bool large) |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 565 | { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 566 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
| 567 | chan->center_freq)) |
| 568 | goto nla_put_failure; |
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 ((chan->flags & IEEE80211_CHAN_DISABLED) && |
| 571 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED)) |
| 572 | goto nla_put_failure; |
Luis R. Rodriguez | 8fe02e1 | 2013-10-21 19:22:25 +0200 | [diff] [blame] | 573 | if (chan->flags & IEEE80211_CHAN_NO_IR) { |
| 574 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR)) |
| 575 | goto nla_put_failure; |
| 576 | if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS)) |
| 577 | goto nla_put_failure; |
| 578 | } |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 579 | if (chan->flags & IEEE80211_CHAN_RADAR) { |
| 580 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR)) |
| 581 | goto nla_put_failure; |
| 582 | if (large) { |
| 583 | u32 time; |
| 584 | |
| 585 | time = elapsed_jiffies_msecs(chan->dfs_state_entered); |
| 586 | |
| 587 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE, |
| 588 | chan->dfs_state)) |
| 589 | goto nla_put_failure; |
| 590 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME, |
| 591 | time)) |
| 592 | goto nla_put_failure; |
| 593 | } |
| 594 | } |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 595 | |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 596 | if (large) { |
| 597 | if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) && |
| 598 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS)) |
| 599 | goto nla_put_failure; |
| 600 | if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) && |
| 601 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS)) |
| 602 | goto nla_put_failure; |
| 603 | if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) && |
| 604 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ)) |
| 605 | goto nla_put_failure; |
| 606 | if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) && |
| 607 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ)) |
| 608 | goto nla_put_failure; |
| 609 | } |
| 610 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 611 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
| 612 | DBM_TO_MBM(chan->max_power))) |
| 613 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 614 | |
| 615 | return 0; |
| 616 | |
| 617 | nla_put_failure: |
| 618 | return -ENOBUFS; |
| 619 | } |
| 620 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 621 | /* netlink command implementations */ |
| 622 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 623 | struct key_parse { |
| 624 | struct key_params p; |
| 625 | int idx; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 626 | int type; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 627 | bool def, defmgmt; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 628 | bool def_uni, def_multi; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 629 | }; |
| 630 | |
| 631 | static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k) |
| 632 | { |
| 633 | struct nlattr *tb[NL80211_KEY_MAX + 1]; |
| 634 | int err = nla_parse_nested(tb, NL80211_KEY_MAX, key, |
| 635 | nl80211_key_policy); |
| 636 | if (err) |
| 637 | return err; |
| 638 | |
| 639 | k->def = !!tb[NL80211_KEY_DEFAULT]; |
| 640 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; |
| 641 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 642 | if (k->def) { |
| 643 | k->def_uni = true; |
| 644 | k->def_multi = true; |
| 645 | } |
| 646 | if (k->defmgmt) |
| 647 | k->def_multi = true; |
| 648 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 649 | if (tb[NL80211_KEY_IDX]) |
| 650 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); |
| 651 | |
| 652 | if (tb[NL80211_KEY_DATA]) { |
| 653 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); |
| 654 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); |
| 655 | } |
| 656 | |
| 657 | if (tb[NL80211_KEY_SEQ]) { |
| 658 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); |
| 659 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); |
| 660 | } |
| 661 | |
| 662 | if (tb[NL80211_KEY_CIPHER]) |
| 663 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); |
| 664 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 665 | if (tb[NL80211_KEY_TYPE]) { |
| 666 | k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); |
| 667 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 668 | return -EINVAL; |
| 669 | } |
| 670 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 671 | if (tb[NL80211_KEY_DEFAULT_TYPES]) { |
| 672 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
Johannes Berg | 2da8f41 | 2012-01-20 13:52:37 +0100 | [diff] [blame] | 673 | err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 674 | tb[NL80211_KEY_DEFAULT_TYPES], |
| 675 | nl80211_key_default_policy); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 676 | if (err) |
| 677 | return err; |
| 678 | |
| 679 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 680 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 681 | } |
| 682 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 683 | return 0; |
| 684 | } |
| 685 | |
| 686 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) |
| 687 | { |
| 688 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { |
| 689 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 690 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 691 | } |
| 692 | |
| 693 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { |
| 694 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 695 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 696 | } |
| 697 | |
| 698 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 699 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 700 | |
| 701 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) |
| 702 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); |
| 703 | |
| 704 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; |
| 705 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; |
| 706 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 707 | if (k->def) { |
| 708 | k->def_uni = true; |
| 709 | k->def_multi = true; |
| 710 | } |
| 711 | if (k->defmgmt) |
| 712 | k->def_multi = true; |
| 713 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 714 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 715 | k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 716 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 717 | return -EINVAL; |
| 718 | } |
| 719 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 720 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { |
| 721 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
| 722 | int err = nla_parse_nested( |
| 723 | kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 724 | info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], |
| 725 | nl80211_key_default_policy); |
| 726 | if (err) |
| 727 | return err; |
| 728 | |
| 729 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 730 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 731 | } |
| 732 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 733 | return 0; |
| 734 | } |
| 735 | |
| 736 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) |
| 737 | { |
| 738 | int err; |
| 739 | |
| 740 | memset(k, 0, sizeof(*k)); |
| 741 | k->idx = -1; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 742 | k->type = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 743 | |
| 744 | if (info->attrs[NL80211_ATTR_KEY]) |
| 745 | err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k); |
| 746 | else |
| 747 | err = nl80211_parse_key_old(info, k); |
| 748 | |
| 749 | if (err) |
| 750 | return err; |
| 751 | |
| 752 | if (k->def && k->defmgmt) |
| 753 | return -EINVAL; |
| 754 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 755 | if (k->defmgmt) { |
| 756 | if (k->def_uni || !k->def_multi) |
| 757 | return -EINVAL; |
| 758 | } |
| 759 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 760 | if (k->idx != -1) { |
| 761 | if (k->defmgmt) { |
| 762 | if (k->idx < 4 || k->idx > 5) |
| 763 | return -EINVAL; |
| 764 | } else if (k->def) { |
| 765 | if (k->idx < 0 || k->idx > 3) |
| 766 | return -EINVAL; |
| 767 | } else { |
| 768 | if (k->idx < 0 || k->idx > 5) |
| 769 | return -EINVAL; |
| 770 | } |
| 771 | } |
| 772 | |
| 773 | return 0; |
| 774 | } |
| 775 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 776 | static struct cfg80211_cached_keys * |
| 777 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 778 | struct nlattr *keys, bool *no_ht) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 779 | { |
| 780 | struct key_parse parse; |
| 781 | struct nlattr *key; |
| 782 | struct cfg80211_cached_keys *result; |
| 783 | int rem, err, def = 0; |
| 784 | |
| 785 | result = kzalloc(sizeof(*result), GFP_KERNEL); |
| 786 | if (!result) |
| 787 | return ERR_PTR(-ENOMEM); |
| 788 | |
| 789 | result->def = -1; |
| 790 | result->defmgmt = -1; |
| 791 | |
| 792 | nla_for_each_nested(key, keys, rem) { |
| 793 | memset(&parse, 0, sizeof(parse)); |
| 794 | parse.idx = -1; |
| 795 | |
| 796 | err = nl80211_parse_key_new(key, &parse); |
| 797 | if (err) |
| 798 | goto error; |
| 799 | err = -EINVAL; |
| 800 | if (!parse.p.key) |
| 801 | goto error; |
| 802 | if (parse.idx < 0 || parse.idx > 4) |
| 803 | goto error; |
| 804 | if (parse.def) { |
| 805 | if (def) |
| 806 | goto error; |
| 807 | def = 1; |
| 808 | result->def = parse.idx; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 809 | if (!parse.def_uni || !parse.def_multi) |
| 810 | goto error; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 811 | } else if (parse.defmgmt) |
| 812 | goto error; |
| 813 | err = cfg80211_validate_key_settings(rdev, &parse.p, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 814 | parse.idx, false, NULL); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 815 | if (err) |
| 816 | goto error; |
| 817 | result->params[parse.idx].cipher = parse.p.cipher; |
| 818 | result->params[parse.idx].key_len = parse.p.key_len; |
| 819 | result->params[parse.idx].key = result->data[parse.idx]; |
| 820 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 821 | |
| 822 | if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 || |
| 823 | parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) { |
| 824 | if (no_ht) |
| 825 | *no_ht = true; |
| 826 | } |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 827 | } |
| 828 | |
| 829 | return result; |
| 830 | error: |
| 831 | kfree(result); |
| 832 | return ERR_PTR(err); |
| 833 | } |
| 834 | |
| 835 | static int nl80211_key_allowed(struct wireless_dev *wdev) |
| 836 | { |
| 837 | ASSERT_WDEV_LOCK(wdev); |
| 838 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 839 | switch (wdev->iftype) { |
| 840 | case NL80211_IFTYPE_AP: |
| 841 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 842 | case NL80211_IFTYPE_P2P_GO: |
Thomas Pedersen | ff973af | 2011-05-03 16:57:12 -0700 | [diff] [blame] | 843 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 844 | break; |
| 845 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 846 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 847 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 848 | if (!wdev->current_bss) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 849 | return -ENOLINK; |
| 850 | break; |
| 851 | default: |
| 852 | return -EINVAL; |
| 853 | } |
| 854 | |
| 855 | return 0; |
| 856 | } |
| 857 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 858 | static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) |
| 859 | { |
| 860 | struct nlattr *nl_modes = nla_nest_start(msg, attr); |
| 861 | int i; |
| 862 | |
| 863 | if (!nl_modes) |
| 864 | goto nla_put_failure; |
| 865 | |
| 866 | i = 0; |
| 867 | while (ifmodes) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 868 | if ((ifmodes & 1) && nla_put_flag(msg, i)) |
| 869 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 870 | ifmodes >>= 1; |
| 871 | i++; |
| 872 | } |
| 873 | |
| 874 | nla_nest_end(msg, nl_modes); |
| 875 | return 0; |
| 876 | |
| 877 | nla_put_failure: |
| 878 | return -ENOBUFS; |
| 879 | } |
| 880 | |
| 881 | static int nl80211_put_iface_combinations(struct wiphy *wiphy, |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 882 | struct sk_buff *msg, |
| 883 | bool large) |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 884 | { |
| 885 | struct nlattr *nl_combis; |
| 886 | int i, j; |
| 887 | |
| 888 | nl_combis = nla_nest_start(msg, |
| 889 | NL80211_ATTR_INTERFACE_COMBINATIONS); |
| 890 | if (!nl_combis) |
| 891 | goto nla_put_failure; |
| 892 | |
| 893 | for (i = 0; i < wiphy->n_iface_combinations; i++) { |
| 894 | const struct ieee80211_iface_combination *c; |
| 895 | struct nlattr *nl_combi, *nl_limits; |
| 896 | |
| 897 | c = &wiphy->iface_combinations[i]; |
| 898 | |
| 899 | nl_combi = nla_nest_start(msg, i + 1); |
| 900 | if (!nl_combi) |
| 901 | goto nla_put_failure; |
| 902 | |
| 903 | nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS); |
| 904 | if (!nl_limits) |
| 905 | goto nla_put_failure; |
| 906 | |
| 907 | for (j = 0; j < c->n_limits; j++) { |
| 908 | struct nlattr *nl_limit; |
| 909 | |
| 910 | nl_limit = nla_nest_start(msg, j + 1); |
| 911 | if (!nl_limit) |
| 912 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 913 | if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX, |
| 914 | c->limits[j].max)) |
| 915 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 916 | if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, |
| 917 | c->limits[j].types)) |
| 918 | goto nla_put_failure; |
| 919 | nla_nest_end(msg, nl_limit); |
| 920 | } |
| 921 | |
| 922 | nla_nest_end(msg, nl_limits); |
| 923 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 924 | if (c->beacon_int_infra_match && |
| 925 | nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH)) |
| 926 | goto nla_put_failure; |
| 927 | if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, |
| 928 | c->num_different_channels) || |
| 929 | nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM, |
| 930 | c->max_interfaces)) |
| 931 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 932 | if (large && |
| 933 | nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS, |
| 934 | c->radar_detect_widths)) |
| 935 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 936 | |
| 937 | nla_nest_end(msg, nl_combi); |
| 938 | } |
| 939 | |
| 940 | nla_nest_end(msg, nl_combis); |
| 941 | |
| 942 | return 0; |
| 943 | nla_put_failure: |
| 944 | return -ENOBUFS; |
| 945 | } |
| 946 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 947 | #ifdef CONFIG_PM |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 948 | static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev, |
| 949 | struct sk_buff *msg) |
| 950 | { |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 951 | const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp; |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 952 | struct nlattr *nl_tcp; |
| 953 | |
| 954 | if (!tcp) |
| 955 | return 0; |
| 956 | |
| 957 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); |
| 958 | if (!nl_tcp) |
| 959 | return -ENOBUFS; |
| 960 | |
| 961 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 962 | tcp->data_payload_max)) |
| 963 | return -ENOBUFS; |
| 964 | |
| 965 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 966 | tcp->data_payload_max)) |
| 967 | return -ENOBUFS; |
| 968 | |
| 969 | if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ)) |
| 970 | return -ENOBUFS; |
| 971 | |
| 972 | if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, |
| 973 | sizeof(*tcp->tok), tcp->tok)) |
| 974 | return -ENOBUFS; |
| 975 | |
| 976 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, |
| 977 | tcp->data_interval_max)) |
| 978 | return -ENOBUFS; |
| 979 | |
| 980 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, |
| 981 | tcp->wake_payload_max)) |
| 982 | return -ENOBUFS; |
| 983 | |
| 984 | nla_nest_end(msg, nl_tcp); |
| 985 | return 0; |
| 986 | } |
| 987 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 988 | static int nl80211_send_wowlan(struct sk_buff *msg, |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 989 | struct cfg80211_registered_device *dev, |
| 990 | bool large) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 991 | { |
| 992 | struct nlattr *nl_wowlan; |
| 993 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 994 | if (!dev->wiphy.wowlan) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 995 | return 0; |
| 996 | |
| 997 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); |
| 998 | if (!nl_wowlan) |
| 999 | return -ENOBUFS; |
| 1000 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 1001 | if (((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1002 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 1003 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1004 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 1005 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1006 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 1007 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1008 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) || |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 1009 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1010 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 1011 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1012 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 1013 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1014 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 1015 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1016 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 1017 | return -ENOBUFS; |
| 1018 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 1019 | if (dev->wiphy.wowlan->n_patterns) { |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 1020 | struct nl80211_pattern_support pat = { |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 1021 | .max_patterns = dev->wiphy.wowlan->n_patterns, |
| 1022 | .min_pattern_len = dev->wiphy.wowlan->pattern_min_len, |
| 1023 | .max_pattern_len = dev->wiphy.wowlan->pattern_max_len, |
| 1024 | .max_pkt_offset = dev->wiphy.wowlan->max_pkt_offset, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1025 | }; |
| 1026 | |
| 1027 | if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 1028 | sizeof(pat), &pat)) |
| 1029 | return -ENOBUFS; |
| 1030 | } |
| 1031 | |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1032 | if (large && nl80211_send_wowlan_tcp_caps(dev, msg)) |
| 1033 | return -ENOBUFS; |
| 1034 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1035 | nla_nest_end(msg, nl_wowlan); |
| 1036 | |
| 1037 | return 0; |
| 1038 | } |
| 1039 | #endif |
| 1040 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1041 | static int nl80211_send_coalesce(struct sk_buff *msg, |
| 1042 | struct cfg80211_registered_device *dev) |
| 1043 | { |
| 1044 | struct nl80211_coalesce_rule_support rule; |
| 1045 | |
| 1046 | if (!dev->wiphy.coalesce) |
| 1047 | return 0; |
| 1048 | |
| 1049 | rule.max_rules = dev->wiphy.coalesce->n_rules; |
| 1050 | rule.max_delay = dev->wiphy.coalesce->max_delay; |
| 1051 | rule.pat.max_patterns = dev->wiphy.coalesce->n_patterns; |
| 1052 | rule.pat.min_pattern_len = dev->wiphy.coalesce->pattern_min_len; |
| 1053 | rule.pat.max_pattern_len = dev->wiphy.coalesce->pattern_max_len; |
| 1054 | rule.pat.max_pkt_offset = dev->wiphy.coalesce->max_pkt_offset; |
| 1055 | |
| 1056 | if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule)) |
| 1057 | return -ENOBUFS; |
| 1058 | |
| 1059 | return 0; |
| 1060 | } |
| 1061 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1062 | static int nl80211_send_band_rateinfo(struct sk_buff *msg, |
| 1063 | struct ieee80211_supported_band *sband) |
| 1064 | { |
| 1065 | struct nlattr *nl_rates, *nl_rate; |
| 1066 | struct ieee80211_rate *rate; |
| 1067 | int i; |
| 1068 | |
| 1069 | /* add HT info */ |
| 1070 | if (sband->ht_cap.ht_supported && |
| 1071 | (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET, |
| 1072 | sizeof(sband->ht_cap.mcs), |
| 1073 | &sband->ht_cap.mcs) || |
| 1074 | nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA, |
| 1075 | sband->ht_cap.cap) || |
| 1076 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, |
| 1077 | sband->ht_cap.ampdu_factor) || |
| 1078 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, |
| 1079 | sband->ht_cap.ampdu_density))) |
| 1080 | return -ENOBUFS; |
| 1081 | |
| 1082 | /* add VHT info */ |
| 1083 | if (sband->vht_cap.vht_supported && |
| 1084 | (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET, |
| 1085 | sizeof(sband->vht_cap.vht_mcs), |
| 1086 | &sband->vht_cap.vht_mcs) || |
| 1087 | nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA, |
| 1088 | sband->vht_cap.cap))) |
| 1089 | return -ENOBUFS; |
| 1090 | |
| 1091 | /* add bitrates */ |
| 1092 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); |
| 1093 | if (!nl_rates) |
| 1094 | return -ENOBUFS; |
| 1095 | |
| 1096 | for (i = 0; i < sband->n_bitrates; i++) { |
| 1097 | nl_rate = nla_nest_start(msg, i); |
| 1098 | if (!nl_rate) |
| 1099 | return -ENOBUFS; |
| 1100 | |
| 1101 | rate = &sband->bitrates[i]; |
| 1102 | if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE, |
| 1103 | rate->bitrate)) |
| 1104 | return -ENOBUFS; |
| 1105 | if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) && |
| 1106 | nla_put_flag(msg, |
| 1107 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE)) |
| 1108 | return -ENOBUFS; |
| 1109 | |
| 1110 | nla_nest_end(msg, nl_rate); |
| 1111 | } |
| 1112 | |
| 1113 | nla_nest_end(msg, nl_rates); |
| 1114 | |
| 1115 | return 0; |
| 1116 | } |
| 1117 | |
| 1118 | static int |
| 1119 | nl80211_send_mgmt_stypes(struct sk_buff *msg, |
| 1120 | const struct ieee80211_txrx_stypes *mgmt_stypes) |
| 1121 | { |
| 1122 | u16 stypes; |
| 1123 | struct nlattr *nl_ftypes, *nl_ifs; |
| 1124 | enum nl80211_iftype ift; |
| 1125 | int i; |
| 1126 | |
| 1127 | if (!mgmt_stypes) |
| 1128 | return 0; |
| 1129 | |
| 1130 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES); |
| 1131 | if (!nl_ifs) |
| 1132 | return -ENOBUFS; |
| 1133 | |
| 1134 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 1135 | nl_ftypes = nla_nest_start(msg, ift); |
| 1136 | if (!nl_ftypes) |
| 1137 | return -ENOBUFS; |
| 1138 | i = 0; |
| 1139 | stypes = mgmt_stypes[ift].tx; |
| 1140 | while (stypes) { |
| 1141 | if ((stypes & 1) && |
| 1142 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1143 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1144 | return -ENOBUFS; |
| 1145 | stypes >>= 1; |
| 1146 | i++; |
| 1147 | } |
| 1148 | nla_nest_end(msg, nl_ftypes); |
| 1149 | } |
| 1150 | |
| 1151 | nla_nest_end(msg, nl_ifs); |
| 1152 | |
| 1153 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES); |
| 1154 | if (!nl_ifs) |
| 1155 | return -ENOBUFS; |
| 1156 | |
| 1157 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 1158 | nl_ftypes = nla_nest_start(msg, ift); |
| 1159 | if (!nl_ftypes) |
| 1160 | return -ENOBUFS; |
| 1161 | i = 0; |
| 1162 | stypes = mgmt_stypes[ift].rx; |
| 1163 | while (stypes) { |
| 1164 | if ((stypes & 1) && |
| 1165 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1166 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1167 | return -ENOBUFS; |
| 1168 | stypes >>= 1; |
| 1169 | i++; |
| 1170 | } |
| 1171 | nla_nest_end(msg, nl_ftypes); |
| 1172 | } |
| 1173 | nla_nest_end(msg, nl_ifs); |
| 1174 | |
| 1175 | return 0; |
| 1176 | } |
| 1177 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1178 | struct nl80211_dump_wiphy_state { |
| 1179 | s64 filter_wiphy; |
| 1180 | long start; |
| 1181 | long split_start, band_start, chan_start; |
| 1182 | bool split; |
| 1183 | }; |
| 1184 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1185 | static int nl80211_send_wiphy(struct cfg80211_registered_device *dev, |
| 1186 | struct sk_buff *msg, u32 portid, u32 seq, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1187 | int flags, struct nl80211_dump_wiphy_state *state) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1188 | { |
| 1189 | void *hdr; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1190 | struct nlattr *nl_bands, *nl_band; |
| 1191 | struct nlattr *nl_freqs, *nl_freq; |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1192 | struct nlattr *nl_cmds; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1193 | enum ieee80211_band band; |
| 1194 | struct ieee80211_channel *chan; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1195 | int i; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1196 | const struct ieee80211_txrx_stypes *mgmt_stypes = |
| 1197 | dev->wiphy.mgmt_stypes; |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1198 | u32 features; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1199 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 1200 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_WIPHY); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1201 | if (!hdr) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1202 | return -ENOBUFS; |
| 1203 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1204 | if (WARN_ON(!state)) |
| 1205 | return -EINVAL; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1206 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1207 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1208 | nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, |
| 1209 | wiphy_name(&dev->wiphy)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1210 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1211 | cfg80211_rdev_list_generation)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1212 | goto nla_put_failure; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1213 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1214 | switch (state->split_start) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1215 | case 0: |
| 1216 | if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, |
| 1217 | dev->wiphy.retry_short) || |
| 1218 | nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, |
| 1219 | dev->wiphy.retry_long) || |
| 1220 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, |
| 1221 | dev->wiphy.frag_threshold) || |
| 1222 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, |
| 1223 | dev->wiphy.rts_threshold) || |
| 1224 | nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, |
| 1225 | dev->wiphy.coverage_class) || |
| 1226 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, |
| 1227 | dev->wiphy.max_scan_ssids) || |
| 1228 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, |
| 1229 | dev->wiphy.max_sched_scan_ssids) || |
| 1230 | nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, |
| 1231 | dev->wiphy.max_scan_ie_len) || |
| 1232 | nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, |
| 1233 | dev->wiphy.max_sched_scan_ie_len) || |
| 1234 | nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS, |
| 1235 | dev->wiphy.max_match_sets)) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1236 | goto nla_put_failure; |
| 1237 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1238 | if ((dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) && |
| 1239 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN)) |
| 1240 | goto nla_put_failure; |
| 1241 | if ((dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) && |
| 1242 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH)) |
| 1243 | goto nla_put_failure; |
| 1244 | if ((dev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && |
| 1245 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD)) |
| 1246 | goto nla_put_failure; |
| 1247 | if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) && |
| 1248 | nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT)) |
| 1249 | goto nla_put_failure; |
| 1250 | if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) && |
| 1251 | nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT)) |
| 1252 | goto nla_put_failure; |
| 1253 | if ((dev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) && |
| 1254 | nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1255 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1256 | state->split_start++; |
| 1257 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1258 | break; |
| 1259 | case 1: |
| 1260 | if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES, |
| 1261 | sizeof(u32) * dev->wiphy.n_cipher_suites, |
| 1262 | dev->wiphy.cipher_suites)) |
Mahesh Palivela | bf0c111e | 2012-06-22 07:27:46 +0000 | [diff] [blame] | 1263 | goto nla_put_failure; |
| 1264 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1265 | if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, |
| 1266 | dev->wiphy.max_num_pmkids)) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1267 | goto nla_put_failure; |
| 1268 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1269 | if ((dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 1270 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE)) |
| 1271 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1272 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1273 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, |
| 1274 | dev->wiphy.available_antennas_tx) || |
| 1275 | nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, |
| 1276 | dev->wiphy.available_antennas_rx)) |
| 1277 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1278 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1279 | if ((dev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) && |
| 1280 | nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD, |
| 1281 | dev->wiphy.probe_resp_offload)) |
| 1282 | goto nla_put_failure; |
Jouni Malinen | e2f367f26 | 2008-11-21 19:01:30 +0200 | [diff] [blame] | 1283 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1284 | if ((dev->wiphy.available_antennas_tx || |
| 1285 | dev->wiphy.available_antennas_rx) && |
| 1286 | dev->ops->get_antenna) { |
| 1287 | u32 tx_ant = 0, rx_ant = 0; |
| 1288 | int res; |
| 1289 | res = rdev_get_antenna(dev, &tx_ant, &rx_ant); |
| 1290 | if (!res) { |
| 1291 | if (nla_put_u32(msg, |
| 1292 | NL80211_ATTR_WIPHY_ANTENNA_TX, |
| 1293 | tx_ant) || |
| 1294 | nla_put_u32(msg, |
| 1295 | NL80211_ATTR_WIPHY_ANTENNA_RX, |
| 1296 | rx_ant)) |
| 1297 | goto nla_put_failure; |
| 1298 | } |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1299 | } |
| 1300 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1301 | state->split_start++; |
| 1302 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1303 | break; |
| 1304 | case 2: |
| 1305 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, |
| 1306 | dev->wiphy.interface_modes)) |
| 1307 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1308 | state->split_start++; |
| 1309 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1310 | break; |
| 1311 | case 3: |
| 1312 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); |
| 1313 | if (!nl_bands) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1314 | goto nla_put_failure; |
| 1315 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1316 | for (band = state->band_start; |
| 1317 | band < IEEE80211_NUM_BANDS; band++) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1318 | struct ieee80211_supported_band *sband; |
| 1319 | |
| 1320 | sband = dev->wiphy.bands[band]; |
| 1321 | |
| 1322 | if (!sband) |
| 1323 | continue; |
| 1324 | |
| 1325 | nl_band = nla_nest_start(msg, band); |
| 1326 | if (!nl_band) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1327 | goto nla_put_failure; |
| 1328 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1329 | switch (state->chan_start) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1330 | case 0: |
| 1331 | if (nl80211_send_band_rateinfo(msg, sband)) |
| 1332 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1333 | state->chan_start++; |
| 1334 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1335 | break; |
| 1336 | default: |
| 1337 | /* add frequencies */ |
| 1338 | nl_freqs = nla_nest_start( |
| 1339 | msg, NL80211_BAND_ATTR_FREQS); |
| 1340 | if (!nl_freqs) |
| 1341 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1342 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1343 | for (i = state->chan_start - 1; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1344 | i < sband->n_channels; |
| 1345 | i++) { |
| 1346 | nl_freq = nla_nest_start(msg, i); |
| 1347 | if (!nl_freq) |
| 1348 | goto nla_put_failure; |
| 1349 | |
| 1350 | chan = &sband->channels[i]; |
| 1351 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1352 | if (nl80211_msg_put_channel( |
| 1353 | msg, chan, |
| 1354 | state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1355 | goto nla_put_failure; |
| 1356 | |
| 1357 | nla_nest_end(msg, nl_freq); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1358 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1359 | break; |
| 1360 | } |
| 1361 | if (i < sband->n_channels) |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1362 | state->chan_start = i + 2; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1363 | else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1364 | state->chan_start = 0; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1365 | nla_nest_end(msg, nl_freqs); |
| 1366 | } |
| 1367 | |
| 1368 | nla_nest_end(msg, nl_band); |
| 1369 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1370 | if (state->split) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1371 | /* start again here */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1372 | if (state->chan_start) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1373 | band--; |
| 1374 | break; |
| 1375 | } |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1376 | } |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1377 | nla_nest_end(msg, nl_bands); |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1378 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1379 | if (band < IEEE80211_NUM_BANDS) |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1380 | state->band_start = band + 1; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1381 | else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1382 | state->band_start = 0; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1383 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1384 | /* if bands & channels are done, continue outside */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1385 | if (state->band_start == 0 && state->chan_start == 0) |
| 1386 | state->split_start++; |
| 1387 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1388 | break; |
| 1389 | case 4: |
| 1390 | nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); |
| 1391 | if (!nl_cmds) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1392 | goto nla_put_failure; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1393 | |
| 1394 | i = 0; |
| 1395 | #define CMD(op, n) \ |
| 1396 | do { \ |
| 1397 | if (dev->ops->op) { \ |
| 1398 | i++; \ |
| 1399 | if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \ |
| 1400 | goto nla_put_failure; \ |
| 1401 | } \ |
| 1402 | } while (0) |
| 1403 | |
| 1404 | CMD(add_virtual_intf, NEW_INTERFACE); |
| 1405 | CMD(change_virtual_intf, SET_INTERFACE); |
| 1406 | CMD(add_key, NEW_KEY); |
| 1407 | CMD(start_ap, START_AP); |
| 1408 | CMD(add_station, NEW_STATION); |
| 1409 | CMD(add_mpath, NEW_MPATH); |
| 1410 | CMD(update_mesh_config, SET_MESH_CONFIG); |
| 1411 | CMD(change_bss, SET_BSS); |
| 1412 | CMD(auth, AUTHENTICATE); |
| 1413 | CMD(assoc, ASSOCIATE); |
| 1414 | CMD(deauth, DEAUTHENTICATE); |
| 1415 | CMD(disassoc, DISASSOCIATE); |
| 1416 | CMD(join_ibss, JOIN_IBSS); |
| 1417 | CMD(join_mesh, JOIN_MESH); |
| 1418 | CMD(set_pmksa, SET_PMKSA); |
| 1419 | CMD(del_pmksa, DEL_PMKSA); |
| 1420 | CMD(flush_pmksa, FLUSH_PMKSA); |
| 1421 | if (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) |
| 1422 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); |
| 1423 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); |
| 1424 | CMD(mgmt_tx, FRAME); |
| 1425 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); |
| 1426 | if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { |
| 1427 | i++; |
| 1428 | if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS)) |
| 1429 | goto nla_put_failure; |
| 1430 | } |
| 1431 | if (dev->ops->set_monitor_channel || dev->ops->start_ap || |
| 1432 | dev->ops->join_mesh) { |
| 1433 | i++; |
| 1434 | if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL)) |
| 1435 | goto nla_put_failure; |
| 1436 | } |
| 1437 | CMD(set_wds_peer, SET_WDS_PEER); |
| 1438 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) { |
| 1439 | CMD(tdls_mgmt, TDLS_MGMT); |
| 1440 | CMD(tdls_oper, TDLS_OPER); |
| 1441 | } |
| 1442 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) |
| 1443 | CMD(sched_scan_start, START_SCHED_SCAN); |
| 1444 | CMD(probe_client, PROBE_CLIENT); |
| 1445 | CMD(set_noack_map, SET_NOACK_MAP); |
| 1446 | if (dev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) { |
| 1447 | i++; |
| 1448 | if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS)) |
| 1449 | goto nla_put_failure; |
| 1450 | } |
| 1451 | CMD(start_p2p_device, START_P2P_DEVICE); |
| 1452 | CMD(set_mcast_rate, SET_MCAST_RATE); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1453 | if (state->split) { |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 1454 | CMD(crit_proto_start, CRIT_PROTOCOL_START); |
| 1455 | CMD(crit_proto_stop, CRIT_PROTOCOL_STOP); |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 1456 | if (dev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH) |
| 1457 | CMD(channel_switch, CHANNEL_SWITCH); |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 1458 | } |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 1459 | CMD(set_qos_map, SET_QOS_MAP); |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1460 | |
Kalle Valo | 4745fc0 | 2011-11-17 19:06:10 +0200 | [diff] [blame] | 1461 | #ifdef CONFIG_NL80211_TESTMODE |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1462 | CMD(testmode_cmd, TESTMODE); |
Kalle Valo | 4745fc0 | 2011-11-17 19:06:10 +0200 | [diff] [blame] | 1463 | #endif |
| 1464 | |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1465 | #undef CMD |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1466 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1467 | if (dev->ops->connect || dev->ops->auth) { |
| 1468 | i++; |
| 1469 | if (nla_put_u32(msg, i, NL80211_CMD_CONNECT)) |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1470 | goto nla_put_failure; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1471 | } |
| 1472 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1473 | if (dev->ops->disconnect || dev->ops->deauth) { |
| 1474 | i++; |
| 1475 | if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT)) |
| 1476 | goto nla_put_failure; |
| 1477 | } |
Johannes Berg | 74b70a4 | 2010-08-24 12:15:53 +0200 | [diff] [blame] | 1478 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1479 | nla_nest_end(msg, nl_cmds); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1480 | state->split_start++; |
| 1481 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1482 | break; |
| 1483 | case 5: |
| 1484 | if (dev->ops->remain_on_channel && |
| 1485 | (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) && |
| 1486 | nla_put_u32(msg, |
| 1487 | NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, |
| 1488 | dev->wiphy.max_remain_on_channel_duration)) |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1489 | goto nla_put_failure; |
| 1490 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1491 | if ((dev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) && |
| 1492 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) |
| 1493 | goto nla_put_failure; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1494 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1495 | if (nl80211_send_mgmt_stypes(msg, mgmt_stypes)) |
| 1496 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1497 | state->split_start++; |
| 1498 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1499 | break; |
| 1500 | case 6: |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 1501 | #ifdef CONFIG_PM |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1502 | if (nl80211_send_wowlan(msg, dev, state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1503 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1504 | state->split_start++; |
| 1505 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1506 | break; |
| 1507 | #else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1508 | state->split_start++; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1509 | #endif |
| 1510 | case 7: |
| 1511 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, |
| 1512 | dev->wiphy.software_iftypes)) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1513 | goto nla_put_failure; |
| 1514 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1515 | if (nl80211_put_iface_combinations(&dev->wiphy, msg, |
| 1516 | state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1517 | goto nla_put_failure; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1518 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1519 | state->split_start++; |
| 1520 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1521 | break; |
| 1522 | case 8: |
| 1523 | if ((dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) && |
| 1524 | nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME, |
| 1525 | dev->wiphy.ap_sme_capa)) |
| 1526 | goto nla_put_failure; |
| 1527 | |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1528 | features = dev->wiphy.features; |
| 1529 | /* |
| 1530 | * We can only add the per-channel limit information if the |
| 1531 | * dump is split, otherwise it makes it too big. Therefore |
| 1532 | * only advertise it in that case. |
| 1533 | */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1534 | if (state->split) |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1535 | features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS; |
| 1536 | if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1537 | goto nla_put_failure; |
| 1538 | |
| 1539 | if (dev->wiphy.ht_capa_mod_mask && |
| 1540 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, |
| 1541 | sizeof(*dev->wiphy.ht_capa_mod_mask), |
| 1542 | dev->wiphy.ht_capa_mod_mask)) |
| 1543 | goto nla_put_failure; |
| 1544 | |
| 1545 | if (dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME && |
| 1546 | dev->wiphy.max_acl_mac_addrs && |
| 1547 | nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX, |
| 1548 | dev->wiphy.max_acl_mac_addrs)) |
| 1549 | goto nla_put_failure; |
| 1550 | |
| 1551 | /* |
| 1552 | * Any information below this point is only available to |
| 1553 | * applications that can deal with it being split. This |
| 1554 | * helps ensure that newly added capabilities don't break |
| 1555 | * older tools by overrunning their buffers. |
| 1556 | * |
| 1557 | * We still increment split_start so that in the split |
| 1558 | * case we'll continue with more data in the next round, |
| 1559 | * but break unconditionally so unsplit data stops here. |
| 1560 | */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1561 | state->split_start++; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1562 | break; |
| 1563 | case 9: |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1564 | if (dev->wiphy.extended_capabilities && |
| 1565 | (nla_put(msg, NL80211_ATTR_EXT_CAPA, |
| 1566 | dev->wiphy.extended_capabilities_len, |
| 1567 | dev->wiphy.extended_capabilities) || |
| 1568 | nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, |
| 1569 | dev->wiphy.extended_capabilities_len, |
| 1570 | dev->wiphy.extended_capabilities_mask))) |
| 1571 | goto nla_put_failure; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1572 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 1573 | if (dev->wiphy.vht_capa_mod_mask && |
| 1574 | nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, |
| 1575 | sizeof(*dev->wiphy.vht_capa_mod_mask), |
| 1576 | dev->wiphy.vht_capa_mod_mask)) |
| 1577 | goto nla_put_failure; |
| 1578 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1579 | state->split_start++; |
| 1580 | break; |
| 1581 | case 10: |
| 1582 | if (nl80211_send_coalesce(msg, dev)) |
| 1583 | goto nla_put_failure; |
| 1584 | |
Felix Fietkau | 01e0daa | 2013-11-09 14:57:54 +0100 | [diff] [blame] | 1585 | if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) && |
| 1586 | (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) || |
| 1587 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ))) |
| 1588 | goto nla_put_failure; |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 1589 | state->split_start++; |
| 1590 | break; |
| 1591 | case 11: |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1592 | if (dev->wiphy.n_vendor_commands) { |
| 1593 | const struct nl80211_vendor_cmd_info *info; |
| 1594 | struct nlattr *nested; |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 1595 | |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1596 | nested = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); |
| 1597 | if (!nested) |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 1598 | goto nla_put_failure; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1599 | |
| 1600 | for (i = 0; i < dev->wiphy.n_vendor_commands; i++) { |
| 1601 | info = &dev->wiphy.vendor_commands[i].info; |
| 1602 | if (nla_put(msg, i + 1, sizeof(*info), info)) |
| 1603 | goto nla_put_failure; |
| 1604 | } |
| 1605 | nla_nest_end(msg, nested); |
| 1606 | } |
| 1607 | |
| 1608 | if (dev->wiphy.n_vendor_events) { |
| 1609 | const struct nl80211_vendor_cmd_info *info; |
| 1610 | struct nlattr *nested; |
| 1611 | |
| 1612 | nested = nla_nest_start(msg, |
| 1613 | NL80211_ATTR_VENDOR_EVENTS); |
| 1614 | if (!nested) |
| 1615 | goto nla_put_failure; |
| 1616 | |
| 1617 | for (i = 0; i < dev->wiphy.n_vendor_events; i++) { |
| 1618 | info = &dev->wiphy.vendor_events[i]; |
| 1619 | if (nla_put(msg, i + 1, sizeof(*info), info)) |
| 1620 | goto nla_put_failure; |
| 1621 | } |
| 1622 | nla_nest_end(msg, nested); |
| 1623 | } |
Felix Fietkau | 01e0daa | 2013-11-09 14:57:54 +0100 | [diff] [blame] | 1624 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1625 | /* done */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1626 | state->split_start = 0; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1627 | break; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1628 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1629 | return genlmsg_end(msg, hdr); |
| 1630 | |
| 1631 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 1632 | genlmsg_cancel(msg, hdr); |
| 1633 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1634 | } |
| 1635 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1636 | static int nl80211_dump_wiphy_parse(struct sk_buff *skb, |
| 1637 | struct netlink_callback *cb, |
| 1638 | struct nl80211_dump_wiphy_state *state) |
| 1639 | { |
| 1640 | struct nlattr **tb = nl80211_fam.attrbuf; |
| 1641 | int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 1642 | tb, nl80211_fam.maxattr, nl80211_policy); |
| 1643 | /* ignore parse errors for backward compatibility */ |
| 1644 | if (ret) |
| 1645 | return 0; |
| 1646 | |
| 1647 | state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP]; |
| 1648 | if (tb[NL80211_ATTR_WIPHY]) |
| 1649 | state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]); |
| 1650 | if (tb[NL80211_ATTR_WDEV]) |
| 1651 | state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32; |
| 1652 | if (tb[NL80211_ATTR_IFINDEX]) { |
| 1653 | struct net_device *netdev; |
| 1654 | struct cfg80211_registered_device *rdev; |
| 1655 | int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); |
| 1656 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 1657 | netdev = __dev_get_by_index(sock_net(skb->sk), ifidx); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1658 | if (!netdev) |
| 1659 | return -ENODEV; |
| 1660 | if (netdev->ieee80211_ptr) { |
| 1661 | rdev = wiphy_to_dev( |
| 1662 | netdev->ieee80211_ptr->wiphy); |
| 1663 | state->filter_wiphy = rdev->wiphy_idx; |
| 1664 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1665 | } |
| 1666 | |
| 1667 | return 0; |
| 1668 | } |
| 1669 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1670 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) |
| 1671 | { |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1672 | int idx = 0, ret; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1673 | struct nl80211_dump_wiphy_state *state = (void *)cb->args[0]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1674 | struct cfg80211_registered_device *dev; |
Johannes Berg | 3a5a423 | 2013-06-19 10:09:57 +0200 | [diff] [blame] | 1675 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1676 | rtnl_lock(); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1677 | if (!state) { |
| 1678 | state = kzalloc(sizeof(*state), GFP_KERNEL); |
John W. Linville | 57ed5cd | 2013-06-28 13:18:21 -0400 | [diff] [blame] | 1679 | if (!state) { |
| 1680 | rtnl_unlock(); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1681 | return -ENOMEM; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1682 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1683 | state->filter_wiphy = -1; |
| 1684 | ret = nl80211_dump_wiphy_parse(skb, cb, state); |
| 1685 | if (ret) { |
| 1686 | kfree(state); |
| 1687 | rtnl_unlock(); |
| 1688 | return ret; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1689 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1690 | cb->args[0] = (long)state; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1691 | } |
| 1692 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1693 | list_for_each_entry(dev, &cfg80211_rdev_list, list) { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1694 | if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk))) |
| 1695 | continue; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1696 | if (++idx <= state->start) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1697 | continue; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1698 | if (state->filter_wiphy != -1 && |
| 1699 | state->filter_wiphy != dev->wiphy_idx) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1700 | continue; |
| 1701 | /* attempt to fit multiple wiphy data chunks into the skb */ |
| 1702 | do { |
| 1703 | ret = nl80211_send_wiphy(dev, skb, |
| 1704 | NETLINK_CB(cb->skb).portid, |
| 1705 | cb->nlh->nlmsg_seq, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1706 | NLM_F_MULTI, state); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1707 | if (ret < 0) { |
| 1708 | /* |
| 1709 | * If sending the wiphy data didn't fit (ENOBUFS |
| 1710 | * or EMSGSIZE returned), this SKB is still |
| 1711 | * empty (so it's not too big because another |
| 1712 | * wiphy dataset is already in the skb) and |
| 1713 | * we've not tried to adjust the dump allocation |
| 1714 | * yet ... then adjust the alloc size to be |
| 1715 | * bigger, and return 1 but with the empty skb. |
| 1716 | * This results in an empty message being RX'ed |
| 1717 | * in userspace, but that is ignored. |
| 1718 | * |
| 1719 | * We can then retry with the larger buffer. |
| 1720 | */ |
| 1721 | if ((ret == -ENOBUFS || ret == -EMSGSIZE) && |
| 1722 | !skb->len && |
| 1723 | cb->min_dump_alloc < 4096) { |
| 1724 | cb->min_dump_alloc = 4096; |
David S. Miller | d98cae64e | 2013-06-19 16:49:39 -0700 | [diff] [blame] | 1725 | rtnl_unlock(); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1726 | return 1; |
| 1727 | } |
| 1728 | idx--; |
| 1729 | break; |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1730 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1731 | } while (state->split_start > 0); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1732 | break; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1733 | } |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1734 | rtnl_unlock(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1735 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1736 | state->start = idx; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1737 | |
| 1738 | return skb->len; |
| 1739 | } |
| 1740 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1741 | static int nl80211_dump_wiphy_done(struct netlink_callback *cb) |
| 1742 | { |
| 1743 | kfree((void *)cb->args[0]); |
| 1744 | return 0; |
| 1745 | } |
| 1746 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1747 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1748 | { |
| 1749 | struct sk_buff *msg; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1750 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1751 | struct nl80211_dump_wiphy_state state = {}; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1752 | |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1753 | msg = nlmsg_new(4096, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1754 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1755 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1756 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1757 | 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] | 1758 | &state) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1759 | nlmsg_free(msg); |
| 1760 | return -ENOBUFS; |
| 1761 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1762 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 1763 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1764 | } |
| 1765 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1766 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
| 1767 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, |
| 1768 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, |
| 1769 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, |
| 1770 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, |
| 1771 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, |
| 1772 | }; |
| 1773 | |
| 1774 | static int parse_txq_params(struct nlattr *tb[], |
| 1775 | struct ieee80211_txq_params *txq_params) |
| 1776 | { |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1777 | if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] || |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1778 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
| 1779 | !tb[NL80211_TXQ_ATTR_AIFS]) |
| 1780 | return -EINVAL; |
| 1781 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1782 | txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1783 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
| 1784 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); |
| 1785 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); |
| 1786 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); |
| 1787 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1788 | if (txq_params->ac >= NL80211_NUM_ACS) |
| 1789 | return -EINVAL; |
| 1790 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1791 | return 0; |
| 1792 | } |
| 1793 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1794 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
| 1795 | { |
| 1796 | /* |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1797 | * You can only set the channel explicitly for WDS interfaces, |
| 1798 | * all others have their channel managed via their respective |
| 1799 | * "establish a connection" command (connect, join, ...) |
| 1800 | * |
| 1801 | * For AP/GO and mesh mode, the channel can be set with the |
| 1802 | * channel userspace API, but is only stored and passed to the |
| 1803 | * low-level driver when the AP starts or the mesh is joined. |
| 1804 | * This is for backward compatibility, userspace can also give |
| 1805 | * the channel in the start-ap or join-mesh commands instead. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1806 | * |
| 1807 | * Monitors are special as they are normally slaved to |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1808 | * whatever else is going on, so they have their own special |
| 1809 | * operation to set the monitor channel if possible. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1810 | */ |
| 1811 | return !wdev || |
| 1812 | wdev->iftype == NL80211_IFTYPE_AP || |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1813 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 1814 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
| 1815 | wdev->iftype == NL80211_IFTYPE_P2P_GO; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1816 | } |
| 1817 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1818 | static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev, |
| 1819 | struct genl_info *info, |
| 1820 | struct cfg80211_chan_def *chandef) |
| 1821 | { |
Mahesh Palivela | dbeca2e | 2012-11-29 14:11:07 +0530 | [diff] [blame] | 1822 | u32 control_freq; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1823 | |
| 1824 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 1825 | return -EINVAL; |
| 1826 | |
| 1827 | control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 1828 | |
| 1829 | chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1830 | chandef->width = NL80211_CHAN_WIDTH_20_NOHT; |
| 1831 | chandef->center_freq1 = control_freq; |
| 1832 | chandef->center_freq2 = 0; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1833 | |
| 1834 | /* Primary channel not allowed */ |
| 1835 | if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) |
| 1836 | return -EINVAL; |
| 1837 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1838 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 1839 | enum nl80211_channel_type chantype; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1840 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1841 | chantype = nla_get_u32( |
| 1842 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 1843 | |
| 1844 | switch (chantype) { |
| 1845 | case NL80211_CHAN_NO_HT: |
| 1846 | case NL80211_CHAN_HT20: |
| 1847 | case NL80211_CHAN_HT40PLUS: |
| 1848 | case NL80211_CHAN_HT40MINUS: |
| 1849 | cfg80211_chandef_create(chandef, chandef->chan, |
| 1850 | chantype); |
| 1851 | break; |
| 1852 | default: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1853 | return -EINVAL; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1854 | } |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1855 | } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) { |
| 1856 | chandef->width = |
| 1857 | nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]); |
| 1858 | if (info->attrs[NL80211_ATTR_CENTER_FREQ1]) |
| 1859 | chandef->center_freq1 = |
| 1860 | nla_get_u32( |
| 1861 | info->attrs[NL80211_ATTR_CENTER_FREQ1]); |
| 1862 | if (info->attrs[NL80211_ATTR_CENTER_FREQ2]) |
| 1863 | chandef->center_freq2 = |
| 1864 | nla_get_u32( |
| 1865 | info->attrs[NL80211_ATTR_CENTER_FREQ2]); |
| 1866 | } |
| 1867 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 1868 | if (!cfg80211_chandef_valid(chandef)) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1869 | return -EINVAL; |
| 1870 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 1871 | if (!cfg80211_chandef_usable(&rdev->wiphy, chandef, |
| 1872 | IEEE80211_CHAN_DISABLED)) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1873 | return -EINVAL; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1874 | |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 1875 | if ((chandef->width == NL80211_CHAN_WIDTH_5 || |
| 1876 | chandef->width == NL80211_CHAN_WIDTH_10) && |
| 1877 | !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ)) |
| 1878 | return -EINVAL; |
| 1879 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1880 | return 0; |
| 1881 | } |
| 1882 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1883 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
| 1884 | struct wireless_dev *wdev, |
| 1885 | struct genl_info *info) |
| 1886 | { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1887 | struct cfg80211_chan_def chandef; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1888 | int result; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1889 | enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR; |
| 1890 | |
| 1891 | if (wdev) |
| 1892 | iftype = wdev->iftype; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1893 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1894 | if (!nl80211_can_set_dev_channel(wdev)) |
| 1895 | return -EOPNOTSUPP; |
| 1896 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1897 | result = nl80211_parse_chandef(rdev, info, &chandef); |
| 1898 | if (result) |
| 1899 | return result; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1900 | |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1901 | switch (iftype) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1902 | case NL80211_IFTYPE_AP: |
| 1903 | case NL80211_IFTYPE_P2P_GO: |
| 1904 | if (wdev->beacon_interval) { |
| 1905 | result = -EBUSY; |
| 1906 | break; |
| 1907 | } |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1908 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef)) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1909 | result = -EINVAL; |
| 1910 | break; |
| 1911 | } |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1912 | wdev->preset_chandef = chandef; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1913 | result = 0; |
| 1914 | break; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1915 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1916 | result = cfg80211_set_mesh_channel(rdev, wdev, &chandef); |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1917 | break; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1918 | case NL80211_IFTYPE_MONITOR: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1919 | result = cfg80211_set_monitor_channel(rdev, &chandef); |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1920 | break; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1921 | default: |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1922 | result = -EINVAL; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1923 | } |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1924 | |
| 1925 | return result; |
| 1926 | } |
| 1927 | |
| 1928 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) |
| 1929 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1930 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1931 | struct net_device *netdev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1932 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1933 | return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1934 | } |
| 1935 | |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1936 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
| 1937 | { |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1938 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1939 | struct net_device *dev = info->user_ptr[1]; |
| 1940 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 388ac77 | 2010-10-07 13:11:09 +0200 | [diff] [blame] | 1941 | const u8 *bssid; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1942 | |
| 1943 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 1944 | return -EINVAL; |
| 1945 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1946 | if (netif_running(dev)) |
| 1947 | return -EBUSY; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1948 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1949 | if (!rdev->ops->set_wds_peer) |
| 1950 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1951 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1952 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
| 1953 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1954 | |
| 1955 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 1956 | return rdev_set_wds_peer(rdev, dev, bssid); |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1957 | } |
| 1958 | |
| 1959 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1960 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1961 | { |
| 1962 | struct cfg80211_registered_device *rdev; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1963 | struct net_device *netdev = NULL; |
| 1964 | struct wireless_dev *wdev; |
Bill Jordan | a1e567c | 2010-09-10 11:22:32 -0400 | [diff] [blame] | 1965 | int result = 0, rem_txq_params = 0; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1966 | struct nlattr *nl_txq_params; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1967 | u32 changed; |
| 1968 | u8 retry_short = 0, retry_long = 0; |
| 1969 | u32 frag_threshold = 0, rts_threshold = 0; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1970 | u8 coverage_class = 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1971 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1972 | ASSERT_RTNL(); |
| 1973 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1974 | /* |
| 1975 | * Try to find the wiphy and netdev. Normally this |
| 1976 | * function shouldn't need the netdev, but this is |
| 1977 | * done for backward compatibility -- previously |
| 1978 | * setting the channel was done per wiphy, but now |
| 1979 | * it is per netdev. Previous userland like hostapd |
| 1980 | * also passed a netdev to set_wiphy, so that it is |
| 1981 | * possible to let that go to the right netdev! |
| 1982 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1983 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1984 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
| 1985 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); |
| 1986 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 1987 | netdev = __dev_get_by_index(genl_info_net(info), ifindex); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1988 | if (netdev && netdev->ieee80211_ptr) |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1989 | rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1990 | else |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1991 | netdev = NULL; |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1992 | } |
| 1993 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1994 | if (!netdev) { |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 1995 | rdev = __cfg80211_rdev_from_attrs(genl_info_net(info), |
| 1996 | info->attrs); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1997 | if (IS_ERR(rdev)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1998 | return PTR_ERR(rdev); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1999 | wdev = NULL; |
| 2000 | netdev = NULL; |
| 2001 | result = 0; |
Johannes Berg | 71fe96b | 2012-10-24 10:04:58 +0200 | [diff] [blame] | 2002 | } else |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2003 | wdev = netdev->ieee80211_ptr; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2004 | |
| 2005 | /* |
| 2006 | * end workaround code, by now the rdev is available |
| 2007 | * and locked, and wdev may or may not be NULL. |
| 2008 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2009 | |
| 2010 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2011 | result = cfg80211_dev_rename( |
| 2012 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2013 | |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2014 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2015 | return result; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2016 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2017 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { |
| 2018 | struct ieee80211_txq_params txq_params; |
| 2019 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; |
| 2020 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2021 | if (!rdev->ops->set_txq_params) |
| 2022 | return -EOPNOTSUPP; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2023 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2024 | if (!netdev) |
| 2025 | return -EINVAL; |
Eliad Peller | f70f01c | 2011-09-25 20:06:53 +0300 | [diff] [blame] | 2026 | |
Johannes Berg | 133a3ff | 2011-11-03 14:50:13 +0100 | [diff] [blame] | 2027 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2028 | netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2029 | return -EINVAL; |
Johannes Berg | 133a3ff | 2011-11-03 14:50:13 +0100 | [diff] [blame] | 2030 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2031 | if (!netif_running(netdev)) |
| 2032 | return -ENETDOWN; |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 2033 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2034 | nla_for_each_nested(nl_txq_params, |
| 2035 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], |
| 2036 | rem_txq_params) { |
| 2037 | nla_parse(tb, NL80211_TXQ_ATTR_MAX, |
| 2038 | nla_data(nl_txq_params), |
| 2039 | nla_len(nl_txq_params), |
| 2040 | txq_params_policy); |
| 2041 | result = parse_txq_params(tb, &txq_params); |
| 2042 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2043 | return result; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2044 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2045 | result = rdev_set_txq_params(rdev, netdev, |
| 2046 | &txq_params); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2047 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2048 | return result; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2049 | } |
| 2050 | } |
| 2051 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2052 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 71fe96b | 2012-10-24 10:04:58 +0200 | [diff] [blame] | 2053 | result = __nl80211_set_channel(rdev, |
| 2054 | nl80211_can_set_dev_channel(wdev) ? wdev : NULL, |
| 2055 | info); |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2056 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2057 | return result; |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2058 | } |
| 2059 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2060 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2061 | struct wireless_dev *txp_wdev = wdev; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2062 | enum nl80211_tx_power_setting type; |
| 2063 | int idx, mbm = 0; |
| 2064 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2065 | if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER)) |
| 2066 | txp_wdev = NULL; |
| 2067 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2068 | if (!rdev->ops->set_tx_power) |
| 2069 | return -EOPNOTSUPP; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2070 | |
| 2071 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; |
| 2072 | type = nla_get_u32(info->attrs[idx]); |
| 2073 | |
| 2074 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2075 | (type != NL80211_TX_POWER_AUTOMATIC)) |
| 2076 | return -EINVAL; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2077 | |
| 2078 | if (type != NL80211_TX_POWER_AUTOMATIC) { |
| 2079 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; |
| 2080 | mbm = nla_get_u32(info->attrs[idx]); |
| 2081 | } |
| 2082 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2083 | result = rdev_set_tx_power(rdev, txp_wdev, type, mbm); |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2084 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2085 | return result; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2086 | } |
| 2087 | |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2088 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
| 2089 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { |
| 2090 | u32 tx_ant, rx_ant; |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2091 | if ((!rdev->wiphy.available_antennas_tx && |
| 2092 | !rdev->wiphy.available_antennas_rx) || |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2093 | !rdev->ops->set_antenna) |
| 2094 | return -EOPNOTSUPP; |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2095 | |
| 2096 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); |
| 2097 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); |
| 2098 | |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2099 | /* reject antenna configurations which don't match the |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2100 | * available antenna masks, except for the "all" mask */ |
| 2101 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2102 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) |
| 2103 | return -EINVAL; |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2104 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2105 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
| 2106 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2107 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2108 | result = rdev_set_antenna(rdev, tx_ant, rx_ant); |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2109 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2110 | return result; |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2111 | } |
| 2112 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2113 | changed = 0; |
| 2114 | |
| 2115 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { |
| 2116 | retry_short = nla_get_u8( |
| 2117 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2118 | if (retry_short == 0) |
| 2119 | return -EINVAL; |
| 2120 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2121 | changed |= WIPHY_PARAM_RETRY_SHORT; |
| 2122 | } |
| 2123 | |
| 2124 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { |
| 2125 | retry_long = nla_get_u8( |
| 2126 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2127 | if (retry_long == 0) |
| 2128 | return -EINVAL; |
| 2129 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2130 | changed |= WIPHY_PARAM_RETRY_LONG; |
| 2131 | } |
| 2132 | |
| 2133 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { |
| 2134 | frag_threshold = nla_get_u32( |
| 2135 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2136 | if (frag_threshold < 256) |
| 2137 | return -EINVAL; |
| 2138 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2139 | if (frag_threshold != (u32) -1) { |
| 2140 | /* |
| 2141 | * Fragments (apart from the last one) are required to |
| 2142 | * have even length. Make the fragmentation code |
| 2143 | * simpler by stripping LSB should someone try to use |
| 2144 | * odd threshold value. |
| 2145 | */ |
| 2146 | frag_threshold &= ~0x1; |
| 2147 | } |
| 2148 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; |
| 2149 | } |
| 2150 | |
| 2151 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { |
| 2152 | rts_threshold = nla_get_u32( |
| 2153 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); |
| 2154 | changed |= WIPHY_PARAM_RTS_THRESHOLD; |
| 2155 | } |
| 2156 | |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2157 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
| 2158 | coverage_class = nla_get_u8( |
| 2159 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); |
| 2160 | changed |= WIPHY_PARAM_COVERAGE_CLASS; |
| 2161 | } |
| 2162 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2163 | if (changed) { |
| 2164 | u8 old_retry_short, old_retry_long; |
| 2165 | u32 old_frag_threshold, old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2166 | u8 old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2167 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2168 | if (!rdev->ops->set_wiphy_params) |
| 2169 | return -EOPNOTSUPP; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2170 | |
| 2171 | old_retry_short = rdev->wiphy.retry_short; |
| 2172 | old_retry_long = rdev->wiphy.retry_long; |
| 2173 | old_frag_threshold = rdev->wiphy.frag_threshold; |
| 2174 | old_rts_threshold = rdev->wiphy.rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2175 | old_coverage_class = rdev->wiphy.coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2176 | |
| 2177 | if (changed & WIPHY_PARAM_RETRY_SHORT) |
| 2178 | rdev->wiphy.retry_short = retry_short; |
| 2179 | if (changed & WIPHY_PARAM_RETRY_LONG) |
| 2180 | rdev->wiphy.retry_long = retry_long; |
| 2181 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) |
| 2182 | rdev->wiphy.frag_threshold = frag_threshold; |
| 2183 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) |
| 2184 | rdev->wiphy.rts_threshold = rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2185 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
| 2186 | rdev->wiphy.coverage_class = coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2187 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2188 | result = rdev_set_wiphy_params(rdev, changed); |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2189 | if (result) { |
| 2190 | rdev->wiphy.retry_short = old_retry_short; |
| 2191 | rdev->wiphy.retry_long = old_retry_long; |
| 2192 | rdev->wiphy.frag_threshold = old_frag_threshold; |
| 2193 | rdev->wiphy.rts_threshold = old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2194 | rdev->wiphy.coverage_class = old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2195 | } |
| 2196 | } |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2197 | return 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2198 | } |
| 2199 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 2200 | static inline u64 wdev_id(struct wireless_dev *wdev) |
| 2201 | { |
| 2202 | return (u64)wdev->identifier | |
| 2203 | ((u64)wiphy_to_dev(wdev->wiphy)->wiphy_idx << 32); |
| 2204 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2205 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2206 | static int nl80211_send_chandef(struct sk_buff *msg, |
Janusz Dziedzic | d2859df | 2013-11-06 13:55:51 +0100 | [diff] [blame] | 2207 | const struct cfg80211_chan_def *chandef) |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2208 | { |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 2209 | WARN_ON(!cfg80211_chandef_valid(chandef)); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2210 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2211 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
| 2212 | chandef->chan->center_freq)) |
| 2213 | return -ENOBUFS; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2214 | switch (chandef->width) { |
| 2215 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 2216 | case NL80211_CHAN_WIDTH_20: |
| 2217 | case NL80211_CHAN_WIDTH_40: |
| 2218 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 2219 | cfg80211_get_chandef_type(chandef))) |
| 2220 | return -ENOBUFS; |
| 2221 | break; |
| 2222 | default: |
| 2223 | break; |
| 2224 | } |
| 2225 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width)) |
| 2226 | return -ENOBUFS; |
| 2227 | if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1)) |
| 2228 | return -ENOBUFS; |
| 2229 | if (chandef->center_freq2 && |
| 2230 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2)) |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2231 | return -ENOBUFS; |
| 2232 | return 0; |
| 2233 | } |
| 2234 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2235 | 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] | 2236 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2237 | struct wireless_dev *wdev) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2238 | { |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2239 | struct net_device *dev = wdev->netdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2240 | void *hdr; |
| 2241 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2242 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_INTERFACE); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2243 | if (!hdr) |
| 2244 | return -1; |
| 2245 | |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2246 | if (dev && |
| 2247 | (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2248 | nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name))) |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2249 | goto nla_put_failure; |
| 2250 | |
| 2251 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 2252 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 2253 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2254 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2255 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
| 2256 | rdev->devlist_generation ^ |
| 2257 | (cfg80211_rdev_list_generation << 2))) |
| 2258 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2259 | |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 2260 | if (rdev->ops->get_channel) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2261 | int ret; |
| 2262 | struct cfg80211_chan_def chandef; |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 2263 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2264 | ret = rdev_get_channel(rdev, wdev, &chandef); |
| 2265 | if (ret == 0) { |
| 2266 | if (nl80211_send_chandef(msg, &chandef)) |
| 2267 | goto nla_put_failure; |
| 2268 | } |
Pontus Fuchs | d91df0e | 2012-04-03 16:39:58 +0200 | [diff] [blame] | 2269 | } |
| 2270 | |
Antonio Quartulli | b84e7a0 | 2012-11-07 12:52:20 +0100 | [diff] [blame] | 2271 | if (wdev->ssid_len) { |
| 2272 | if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid)) |
| 2273 | goto nla_put_failure; |
| 2274 | } |
| 2275 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2276 | return genlmsg_end(msg, hdr); |
| 2277 | |
| 2278 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 2279 | genlmsg_cancel(msg, hdr); |
| 2280 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2281 | } |
| 2282 | |
| 2283 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) |
| 2284 | { |
| 2285 | int wp_idx = 0; |
| 2286 | int if_idx = 0; |
| 2287 | int wp_start = cb->args[0]; |
| 2288 | int if_start = cb->args[1]; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2289 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2290 | struct wireless_dev *wdev; |
| 2291 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2292 | rtnl_lock(); |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2293 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 2294 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2295 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2296 | if (wp_idx < wp_start) { |
| 2297 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2298 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2299 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2300 | if_idx = 0; |
| 2301 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 2302 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2303 | if (if_idx < if_start) { |
| 2304 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2305 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2306 | } |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2307 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2308 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2309 | rdev, wdev) < 0) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2310 | goto out; |
| 2311 | } |
| 2312 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2313 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2314 | |
| 2315 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2316 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2317 | out: |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2318 | rtnl_unlock(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2319 | |
| 2320 | cb->args[0] = wp_idx; |
| 2321 | cb->args[1] = if_idx; |
| 2322 | |
| 2323 | return skb->len; |
| 2324 | } |
| 2325 | |
| 2326 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) |
| 2327 | { |
| 2328 | struct sk_buff *msg; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2329 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2330 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2331 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2332 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2333 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2334 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2335 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2336 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2337 | dev, wdev) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2338 | nlmsg_free(msg); |
| 2339 | return -ENOBUFS; |
| 2340 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2341 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 2342 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2343 | } |
| 2344 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2345 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
| 2346 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, |
| 2347 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, |
| 2348 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, |
| 2349 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, |
| 2350 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2351 | [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG }, |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2352 | }; |
| 2353 | |
| 2354 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) |
| 2355 | { |
| 2356 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; |
| 2357 | int flag; |
| 2358 | |
| 2359 | *mntrflags = 0; |
| 2360 | |
| 2361 | if (!nla) |
| 2362 | return -EINVAL; |
| 2363 | |
| 2364 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, |
| 2365 | nla, mntr_flags_policy)) |
| 2366 | return -EINVAL; |
| 2367 | |
| 2368 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) |
| 2369 | if (flags[flag]) |
| 2370 | *mntrflags |= (1<<flag); |
| 2371 | |
| 2372 | return 0; |
| 2373 | } |
| 2374 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2375 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2376 | struct net_device *netdev, u8 use_4addr, |
| 2377 | enum nl80211_iftype iftype) |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2378 | { |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2379 | if (!use_4addr) { |
Jiri Pirko | f350a0a8 | 2010-06-15 06:50:45 +0000 | [diff] [blame] | 2380 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2381 | return -EBUSY; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2382 | return 0; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2383 | } |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2384 | |
| 2385 | switch (iftype) { |
| 2386 | case NL80211_IFTYPE_AP_VLAN: |
| 2387 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) |
| 2388 | return 0; |
| 2389 | break; |
| 2390 | case NL80211_IFTYPE_STATION: |
| 2391 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) |
| 2392 | return 0; |
| 2393 | break; |
| 2394 | default: |
| 2395 | break; |
| 2396 | } |
| 2397 | |
| 2398 | return -EOPNOTSUPP; |
| 2399 | } |
| 2400 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2401 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
| 2402 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2403 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2404 | struct vif_params params; |
Johannes Berg | e36d56b | 2009-06-09 21:04:43 +0200 | [diff] [blame] | 2405 | int err; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2406 | enum nl80211_iftype otype, ntype; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2407 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2408 | u32 _flags, *flags = NULL; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2409 | bool change = false; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2410 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2411 | memset(¶ms, 0, sizeof(params)); |
| 2412 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2413 | otype = ntype = dev->ieee80211_ptr->iftype; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2414 | |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 2415 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2416 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2417 | if (otype != ntype) |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2418 | change = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2419 | if (ntype > NL80211_IFTYPE_MAX) |
| 2420 | return -EINVAL; |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 2421 | } |
| 2422 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2423 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2424 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2425 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2426 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
| 2427 | return -EINVAL; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2428 | if (netif_running(dev)) |
| 2429 | return -EBUSY; |
| 2430 | |
| 2431 | wdev_lock(wdev); |
| 2432 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 2433 | IEEE80211_MAX_MESH_ID_LEN); |
| 2434 | wdev->mesh_id_up_len = |
| 2435 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 2436 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 2437 | wdev->mesh_id_up_len); |
| 2438 | wdev_unlock(wdev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2439 | } |
| 2440 | |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2441 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
| 2442 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
| 2443 | change = true; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2444 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2445 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2446 | return err; |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2447 | } else { |
| 2448 | params.use_4addr = -1; |
| 2449 | } |
| 2450 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2451 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2452 | if (ntype != NL80211_IFTYPE_MONITOR) |
| 2453 | return -EINVAL; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2454 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
| 2455 | &_flags); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2456 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2457 | return err; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2458 | |
| 2459 | flags = &_flags; |
| 2460 | change = true; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2461 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2462 | |
Luciano Coelho | 1800329 | 2013-08-29 13:26:57 +0300 | [diff] [blame] | 2463 | if (flags && (*flags & MONITOR_FLAG_ACTIVE) && |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2464 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
| 2465 | return -EOPNOTSUPP; |
| 2466 | |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2467 | if (change) |
Johannes Berg | 3d54d25 | 2009-08-21 14:51:05 +0200 | [diff] [blame] | 2468 | err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2469 | else |
| 2470 | err = 0; |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 2471 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2472 | if (!err && params.use_4addr != -1) |
| 2473 | dev->ieee80211_ptr->use_4addr = params.use_4addr; |
| 2474 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2475 | return err; |
| 2476 | } |
| 2477 | |
| 2478 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) |
| 2479 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2480 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2481 | struct vif_params params; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2482 | struct wireless_dev *wdev; |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2483 | struct sk_buff *msg; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2484 | int err; |
| 2485 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2486 | u32 flags; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2487 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2488 | memset(¶ms, 0, sizeof(params)); |
| 2489 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2490 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
| 2491 | return -EINVAL; |
| 2492 | |
| 2493 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
| 2494 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
| 2495 | if (type > NL80211_IFTYPE_MAX) |
| 2496 | return -EINVAL; |
| 2497 | } |
| 2498 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2499 | if (!rdev->ops->add_virtual_intf || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2500 | !(rdev->wiphy.interface_modes & (1 << type))) |
| 2501 | return -EOPNOTSUPP; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2502 | |
Arend van Spriel | 1c18f14 | 2013-01-08 10:17:27 +0100 | [diff] [blame] | 2503 | if (type == NL80211_IFTYPE_P2P_DEVICE && info->attrs[NL80211_ATTR_MAC]) { |
| 2504 | nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC], |
| 2505 | ETH_ALEN); |
| 2506 | if (!is_valid_ether_addr(params.macaddr)) |
| 2507 | return -EADDRNOTAVAIL; |
| 2508 | } |
| 2509 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2510 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2511 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2512 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2513 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2514 | return err; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2515 | } |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2516 | |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2517 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 2518 | if (!msg) |
| 2519 | return -ENOMEM; |
| 2520 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2521 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
| 2522 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, |
| 2523 | &flags); |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2524 | |
Luciano Coelho | 1800329 | 2013-08-29 13:26:57 +0300 | [diff] [blame] | 2525 | if (!err && (flags & MONITOR_FLAG_ACTIVE) && |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2526 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
| 2527 | return -EOPNOTSUPP; |
| 2528 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2529 | wdev = rdev_add_virtual_intf(rdev, |
| 2530 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), |
| 2531 | type, err ? NULL : &flags, ¶ms); |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2532 | if (IS_ERR(wdev)) { |
| 2533 | nlmsg_free(msg); |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2534 | return PTR_ERR(wdev); |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2535 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2536 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2537 | switch (type) { |
| 2538 | case NL80211_IFTYPE_MESH_POINT: |
| 2539 | if (!info->attrs[NL80211_ATTR_MESH_ID]) |
| 2540 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2541 | wdev_lock(wdev); |
| 2542 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 2543 | IEEE80211_MAX_MESH_ID_LEN); |
| 2544 | wdev->mesh_id_up_len = |
| 2545 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 2546 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 2547 | wdev->mesh_id_up_len); |
| 2548 | wdev_unlock(wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2549 | break; |
| 2550 | case NL80211_IFTYPE_P2P_DEVICE: |
| 2551 | /* |
| 2552 | * P2P Device doesn't have a netdev, so doesn't go |
| 2553 | * through the netdev notifier and must be added here |
| 2554 | */ |
| 2555 | mutex_init(&wdev->mtx); |
| 2556 | INIT_LIST_HEAD(&wdev->event_list); |
| 2557 | spin_lock_init(&wdev->event_lock); |
| 2558 | INIT_LIST_HEAD(&wdev->mgmt_registrations); |
| 2559 | spin_lock_init(&wdev->mgmt_registrations_lock); |
| 2560 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2561 | wdev->identifier = ++rdev->wdev_id; |
| 2562 | list_add_rcu(&wdev->list, &rdev->wdev_list); |
| 2563 | rdev->devlist_generation++; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2564 | break; |
| 2565 | default: |
| 2566 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2567 | } |
| 2568 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2569 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2570 | rdev, wdev) < 0) { |
| 2571 | nlmsg_free(msg); |
| 2572 | return -ENOBUFS; |
| 2573 | } |
| 2574 | |
| 2575 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2576 | } |
| 2577 | |
| 2578 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) |
| 2579 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2580 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2581 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2582 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2583 | if (!rdev->ops->del_virtual_intf) |
| 2584 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2585 | |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2586 | /* |
| 2587 | * If we remove a wireless device without a netdev then clear |
| 2588 | * user_ptr[1] so that nl80211_post_doit won't dereference it |
| 2589 | * to check if it needs to do dev_put(). Otherwise it crashes |
| 2590 | * since the wdev has been freed, unlike with a netdev where |
| 2591 | * we need the dev_put() for the netdev to really be freed. |
| 2592 | */ |
| 2593 | if (!wdev->netdev) |
| 2594 | info->user_ptr[1] = NULL; |
| 2595 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2596 | return rdev_del_virtual_intf(rdev, wdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2597 | } |
| 2598 | |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 2599 | static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info) |
| 2600 | { |
| 2601 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2602 | struct net_device *dev = info->user_ptr[1]; |
| 2603 | u16 noack_map; |
| 2604 | |
| 2605 | if (!info->attrs[NL80211_ATTR_NOACK_MAP]) |
| 2606 | return -EINVAL; |
| 2607 | |
| 2608 | if (!rdev->ops->set_noack_map) |
| 2609 | return -EOPNOTSUPP; |
| 2610 | |
| 2611 | noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]); |
| 2612 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2613 | return rdev_set_noack_map(rdev, dev, noack_map); |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 2614 | } |
| 2615 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2616 | struct get_key_cookie { |
| 2617 | struct sk_buff *msg; |
| 2618 | int error; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2619 | int idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2620 | }; |
| 2621 | |
| 2622 | static void get_key_callback(void *c, struct key_params *params) |
| 2623 | { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2624 | struct nlattr *key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2625 | struct get_key_cookie *cookie = c; |
| 2626 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2627 | if ((params->key && |
| 2628 | nla_put(cookie->msg, NL80211_ATTR_KEY_DATA, |
| 2629 | params->key_len, params->key)) || |
| 2630 | (params->seq && |
| 2631 | nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ, |
| 2632 | params->seq_len, params->seq)) || |
| 2633 | (params->cipher && |
| 2634 | nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER, |
| 2635 | params->cipher))) |
| 2636 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2637 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2638 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
| 2639 | if (!key) |
| 2640 | goto nla_put_failure; |
| 2641 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2642 | if ((params->key && |
| 2643 | nla_put(cookie->msg, NL80211_KEY_DATA, |
| 2644 | params->key_len, params->key)) || |
| 2645 | (params->seq && |
| 2646 | nla_put(cookie->msg, NL80211_KEY_SEQ, |
| 2647 | params->seq_len, params->seq)) || |
| 2648 | (params->cipher && |
| 2649 | nla_put_u32(cookie->msg, NL80211_KEY_CIPHER, |
| 2650 | params->cipher))) |
| 2651 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2652 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2653 | if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx)) |
| 2654 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2655 | |
| 2656 | nla_nest_end(cookie->msg, key); |
| 2657 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2658 | return; |
| 2659 | nla_put_failure: |
| 2660 | cookie->error = 1; |
| 2661 | } |
| 2662 | |
| 2663 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) |
| 2664 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2665 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2666 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2667 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2668 | u8 key_idx = 0; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2669 | const u8 *mac_addr = NULL; |
| 2670 | bool pairwise; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2671 | struct get_key_cookie cookie = { |
| 2672 | .error = 0, |
| 2673 | }; |
| 2674 | void *hdr; |
| 2675 | struct sk_buff *msg; |
| 2676 | |
| 2677 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 2678 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 2679 | |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 2680 | if (key_idx > 5) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2681 | return -EINVAL; |
| 2682 | |
| 2683 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2684 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2685 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2686 | pairwise = !!mac_addr; |
| 2687 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 2688 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 2689 | if (kt >= NUM_NL80211_KEYTYPES) |
| 2690 | return -EINVAL; |
| 2691 | if (kt != NL80211_KEYTYPE_GROUP && |
| 2692 | kt != NL80211_KEYTYPE_PAIRWISE) |
| 2693 | return -EINVAL; |
| 2694 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; |
| 2695 | } |
| 2696 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2697 | if (!rdev->ops->get_key) |
| 2698 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2699 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2700 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2701 | if (!msg) |
| 2702 | return -ENOMEM; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2703 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2704 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2705 | NL80211_CMD_NEW_KEY); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 2706 | if (!hdr) |
Johannes Berg | 9fe271a | 2013-10-25 11:15:12 +0200 | [diff] [blame] | 2707 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2708 | |
| 2709 | cookie.msg = msg; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2710 | cookie.idx = key_idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2711 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2712 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 2713 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) |
| 2714 | goto nla_put_failure; |
| 2715 | if (mac_addr && |
| 2716 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 2717 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2718 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2719 | if (pairwise && mac_addr && |
| 2720 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 2721 | return -ENOENT; |
| 2722 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2723 | err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie, |
| 2724 | get_key_callback); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2725 | |
| 2726 | if (err) |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 2727 | goto free_msg; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2728 | |
| 2729 | if (cookie.error) |
| 2730 | goto nla_put_failure; |
| 2731 | |
| 2732 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2733 | return genlmsg_reply(msg, info); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2734 | |
| 2735 | nla_put_failure: |
| 2736 | err = -ENOBUFS; |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 2737 | free_msg: |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2738 | nlmsg_free(msg); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2739 | return err; |
| 2740 | } |
| 2741 | |
| 2742 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) |
| 2743 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2744 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2745 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2746 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2747 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2748 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2749 | err = nl80211_parse_key(info, &key); |
| 2750 | if (err) |
| 2751 | return err; |
| 2752 | |
| 2753 | if (key.idx < 0) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2754 | return -EINVAL; |
| 2755 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2756 | /* only support setting default key */ |
| 2757 | if (!key.def && !key.defmgmt) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2758 | return -EINVAL; |
| 2759 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2760 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2761 | |
| 2762 | if (key.def) { |
| 2763 | if (!rdev->ops->set_default_key) { |
| 2764 | err = -EOPNOTSUPP; |
| 2765 | goto out; |
| 2766 | } |
| 2767 | |
| 2768 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2769 | if (err) |
| 2770 | goto out; |
| 2771 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2772 | err = rdev_set_default_key(rdev, dev, key.idx, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2773 | key.def_uni, key.def_multi); |
| 2774 | |
| 2775 | if (err) |
| 2776 | goto out; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2777 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 2778 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2779 | dev->ieee80211_ptr->wext.default_key = key.idx; |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2780 | #endif |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2781 | } else { |
| 2782 | if (key.def_uni || !key.def_multi) { |
| 2783 | err = -EINVAL; |
| 2784 | goto out; |
| 2785 | } |
| 2786 | |
| 2787 | if (!rdev->ops->set_default_mgmt_key) { |
| 2788 | err = -EOPNOTSUPP; |
| 2789 | goto out; |
| 2790 | } |
| 2791 | |
| 2792 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2793 | if (err) |
| 2794 | goto out; |
| 2795 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2796 | err = rdev_set_default_mgmt_key(rdev, dev, key.idx); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2797 | if (err) |
| 2798 | goto out; |
| 2799 | |
| 2800 | #ifdef CONFIG_CFG80211_WEXT |
| 2801 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; |
| 2802 | #endif |
| 2803 | } |
| 2804 | |
| 2805 | out: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2806 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2807 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2808 | return err; |
| 2809 | } |
| 2810 | |
| 2811 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) |
| 2812 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2813 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2814 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2815 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2816 | struct key_parse key; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2817 | const u8 *mac_addr = NULL; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2818 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2819 | err = nl80211_parse_key(info, &key); |
| 2820 | if (err) |
| 2821 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2822 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2823 | if (!key.p.key) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2824 | return -EINVAL; |
| 2825 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2826 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2827 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2828 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2829 | if (key.type == -1) { |
| 2830 | if (mac_addr) |
| 2831 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 2832 | else |
| 2833 | key.type = NL80211_KEYTYPE_GROUP; |
| 2834 | } |
| 2835 | |
| 2836 | /* for now */ |
| 2837 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 2838 | key.type != NL80211_KEYTYPE_GROUP) |
| 2839 | return -EINVAL; |
| 2840 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2841 | if (!rdev->ops->add_key) |
| 2842 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2843 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2844 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
| 2845 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2846 | mac_addr)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2847 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2848 | |
| 2849 | wdev_lock(dev->ieee80211_ptr); |
| 2850 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2851 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2852 | err = rdev_add_key(rdev, dev, key.idx, |
| 2853 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2854 | mac_addr, &key.p); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2855 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2856 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2857 | return err; |
| 2858 | } |
| 2859 | |
| 2860 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) |
| 2861 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2862 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2863 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2864 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2865 | u8 *mac_addr = NULL; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2866 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2867 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2868 | err = nl80211_parse_key(info, &key); |
| 2869 | if (err) |
| 2870 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2871 | |
| 2872 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2873 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2874 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2875 | if (key.type == -1) { |
| 2876 | if (mac_addr) |
| 2877 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 2878 | else |
| 2879 | key.type = NL80211_KEYTYPE_GROUP; |
| 2880 | } |
| 2881 | |
| 2882 | /* for now */ |
| 2883 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 2884 | key.type != NL80211_KEYTYPE_GROUP) |
| 2885 | return -EINVAL; |
| 2886 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2887 | if (!rdev->ops->del_key) |
| 2888 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2889 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2890 | wdev_lock(dev->ieee80211_ptr); |
| 2891 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2892 | |
| 2893 | if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr && |
| 2894 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 2895 | err = -ENOENT; |
| 2896 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2897 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2898 | err = rdev_del_key(rdev, dev, key.idx, |
| 2899 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2900 | mac_addr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2901 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 2902 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2903 | if (!err) { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2904 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2905 | dev->ieee80211_ptr->wext.default_key = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2906 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2907 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
| 2908 | } |
| 2909 | #endif |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2910 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2911 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2912 | return err; |
| 2913 | } |
| 2914 | |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 2915 | /* This function returns an error or the number of nested attributes */ |
| 2916 | static int validate_acl_mac_addrs(struct nlattr *nl_attr) |
| 2917 | { |
| 2918 | struct nlattr *attr; |
| 2919 | int n_entries = 0, tmp; |
| 2920 | |
| 2921 | nla_for_each_nested(attr, nl_attr, tmp) { |
| 2922 | if (nla_len(attr) != ETH_ALEN) |
| 2923 | return -EINVAL; |
| 2924 | |
| 2925 | n_entries++; |
| 2926 | } |
| 2927 | |
| 2928 | return n_entries; |
| 2929 | } |
| 2930 | |
| 2931 | /* |
| 2932 | * This function parses ACL information and allocates memory for ACL data. |
| 2933 | * On successful return, the calling function is responsible to free the |
| 2934 | * ACL buffer returned by this function. |
| 2935 | */ |
| 2936 | static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy, |
| 2937 | struct genl_info *info) |
| 2938 | { |
| 2939 | enum nl80211_acl_policy acl_policy; |
| 2940 | struct nlattr *attr; |
| 2941 | struct cfg80211_acl_data *acl; |
| 2942 | int i = 0, n_entries, tmp; |
| 2943 | |
| 2944 | if (!wiphy->max_acl_mac_addrs) |
| 2945 | return ERR_PTR(-EOPNOTSUPP); |
| 2946 | |
| 2947 | if (!info->attrs[NL80211_ATTR_ACL_POLICY]) |
| 2948 | return ERR_PTR(-EINVAL); |
| 2949 | |
| 2950 | acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]); |
| 2951 | if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED && |
| 2952 | acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED) |
| 2953 | return ERR_PTR(-EINVAL); |
| 2954 | |
| 2955 | if (!info->attrs[NL80211_ATTR_MAC_ADDRS]) |
| 2956 | return ERR_PTR(-EINVAL); |
| 2957 | |
| 2958 | n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]); |
| 2959 | if (n_entries < 0) |
| 2960 | return ERR_PTR(n_entries); |
| 2961 | |
| 2962 | if (n_entries > wiphy->max_acl_mac_addrs) |
| 2963 | return ERR_PTR(-ENOTSUPP); |
| 2964 | |
| 2965 | acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries), |
| 2966 | GFP_KERNEL); |
| 2967 | if (!acl) |
| 2968 | return ERR_PTR(-ENOMEM); |
| 2969 | |
| 2970 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) { |
| 2971 | memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN); |
| 2972 | i++; |
| 2973 | } |
| 2974 | |
| 2975 | acl->n_acl_entries = n_entries; |
| 2976 | acl->acl_policy = acl_policy; |
| 2977 | |
| 2978 | return acl; |
| 2979 | } |
| 2980 | |
| 2981 | static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info) |
| 2982 | { |
| 2983 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2984 | struct net_device *dev = info->user_ptr[1]; |
| 2985 | struct cfg80211_acl_data *acl; |
| 2986 | int err; |
| 2987 | |
| 2988 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 2989 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2990 | return -EOPNOTSUPP; |
| 2991 | |
| 2992 | if (!dev->ieee80211_ptr->beacon_interval) |
| 2993 | return -EINVAL; |
| 2994 | |
| 2995 | acl = parse_acl_data(&rdev->wiphy, info); |
| 2996 | if (IS_ERR(acl)) |
| 2997 | return PTR_ERR(acl); |
| 2998 | |
| 2999 | err = rdev_set_mac_acl(rdev, dev, acl); |
| 3000 | |
| 3001 | kfree(acl); |
| 3002 | |
| 3003 | return err; |
| 3004 | } |
| 3005 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3006 | static int nl80211_parse_beacon(struct nlattr *attrs[], |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3007 | struct cfg80211_beacon_data *bcn) |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3008 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3009 | bool haveinfo = false; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3010 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3011 | if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) || |
| 3012 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) || |
| 3013 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) || |
| 3014 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP])) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 3015 | return -EINVAL; |
| 3016 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3017 | memset(bcn, 0, sizeof(*bcn)); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3018 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3019 | if (attrs[NL80211_ATTR_BEACON_HEAD]) { |
| 3020 | bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]); |
| 3021 | bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3022 | if (!bcn->head_len) |
| 3023 | return -EINVAL; |
| 3024 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3025 | } |
| 3026 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3027 | if (attrs[NL80211_ATTR_BEACON_TAIL]) { |
| 3028 | bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]); |
| 3029 | bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3030 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3031 | } |
| 3032 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3033 | if (!haveinfo) |
| 3034 | return -EINVAL; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3035 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3036 | if (attrs[NL80211_ATTR_IE]) { |
| 3037 | bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]); |
| 3038 | bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 3039 | } |
| 3040 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3041 | if (attrs[NL80211_ATTR_IE_PROBE_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3042 | bcn->proberesp_ies = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3043 | nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3044 | bcn->proberesp_ies_len = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3045 | nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 3046 | } |
| 3047 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3048 | if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3049 | bcn->assocresp_ies = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3050 | nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3051 | bcn->assocresp_ies_len = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3052 | nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 3053 | } |
| 3054 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3055 | if (attrs[NL80211_ATTR_PROBE_RESP]) { |
| 3056 | bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]); |
| 3057 | bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]); |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 3058 | } |
| 3059 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3060 | return 0; |
| 3061 | } |
| 3062 | |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3063 | static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev, |
| 3064 | struct cfg80211_ap_settings *params) |
| 3065 | { |
| 3066 | struct wireless_dev *wdev; |
| 3067 | bool ret = false; |
| 3068 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 3069 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3070 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 3071 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 3072 | continue; |
| 3073 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3074 | if (!wdev->preset_chandef.chan) |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3075 | continue; |
| 3076 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3077 | params->chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3078 | ret = true; |
| 3079 | break; |
| 3080 | } |
| 3081 | |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3082 | return ret; |
| 3083 | } |
| 3084 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 3085 | static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev, |
| 3086 | enum nl80211_auth_type auth_type, |
| 3087 | enum nl80211_commands cmd) |
| 3088 | { |
| 3089 | if (auth_type > NL80211_AUTHTYPE_MAX) |
| 3090 | return false; |
| 3091 | |
| 3092 | switch (cmd) { |
| 3093 | case NL80211_CMD_AUTHENTICATE: |
| 3094 | if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && |
| 3095 | auth_type == NL80211_AUTHTYPE_SAE) |
| 3096 | return false; |
| 3097 | return true; |
| 3098 | case NL80211_CMD_CONNECT: |
| 3099 | case NL80211_CMD_START_AP: |
| 3100 | /* SAE not supported yet */ |
| 3101 | if (auth_type == NL80211_AUTHTYPE_SAE) |
| 3102 | return false; |
| 3103 | return true; |
| 3104 | default: |
| 3105 | return false; |
| 3106 | } |
| 3107 | } |
| 3108 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3109 | static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) |
| 3110 | { |
| 3111 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3112 | struct net_device *dev = info->user_ptr[1]; |
| 3113 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3114 | struct cfg80211_ap_settings params; |
| 3115 | int err; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 3116 | u8 radar_detect_width = 0; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3117 | |
| 3118 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3119 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3120 | return -EOPNOTSUPP; |
| 3121 | |
| 3122 | if (!rdev->ops->start_ap) |
| 3123 | return -EOPNOTSUPP; |
| 3124 | |
| 3125 | if (wdev->beacon_interval) |
| 3126 | return -EALREADY; |
| 3127 | |
| 3128 | memset(¶ms, 0, sizeof(params)); |
| 3129 | |
| 3130 | /* these are required for START_AP */ |
| 3131 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || |
| 3132 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || |
| 3133 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) |
| 3134 | return -EINVAL; |
| 3135 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3136 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3137 | if (err) |
| 3138 | return err; |
| 3139 | |
| 3140 | params.beacon_interval = |
| 3141 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 3142 | params.dtim_period = |
| 3143 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 3144 | |
| 3145 | err = cfg80211_validate_beacon_int(rdev, params.beacon_interval); |
| 3146 | if (err) |
| 3147 | return err; |
| 3148 | |
| 3149 | /* |
| 3150 | * In theory, some of these attributes should be required here |
| 3151 | * but since they were not used when the command was originally |
| 3152 | * added, keep them optional for old user space programs to let |
| 3153 | * them continue to work with drivers that do not need the |
| 3154 | * additional information -- drivers must check! |
| 3155 | */ |
| 3156 | if (info->attrs[NL80211_ATTR_SSID]) { |
| 3157 | params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 3158 | params.ssid_len = |
| 3159 | nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 3160 | if (params.ssid_len == 0 || |
| 3161 | params.ssid_len > IEEE80211_MAX_SSID_LEN) |
| 3162 | return -EINVAL; |
| 3163 | } |
| 3164 | |
| 3165 | if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) { |
| 3166 | params.hidden_ssid = nla_get_u32( |
| 3167 | info->attrs[NL80211_ATTR_HIDDEN_SSID]); |
| 3168 | if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE && |
| 3169 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN && |
| 3170 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS) |
| 3171 | return -EINVAL; |
| 3172 | } |
| 3173 | |
| 3174 | params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
| 3175 | |
| 3176 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 3177 | params.auth_type = nla_get_u32( |
| 3178 | info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 3179 | if (!nl80211_valid_auth_type(rdev, params.auth_type, |
| 3180 | NL80211_CMD_START_AP)) |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3181 | return -EINVAL; |
| 3182 | } else |
| 3183 | params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 3184 | |
| 3185 | err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, |
| 3186 | NL80211_MAX_NR_CIPHER_SUITES); |
| 3187 | if (err) |
| 3188 | return err; |
| 3189 | |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 3190 | if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) { |
| 3191 | if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER)) |
| 3192 | return -EOPNOTSUPP; |
| 3193 | params.inactivity_timeout = nla_get_u16( |
| 3194 | info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]); |
| 3195 | } |
| 3196 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 3197 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 3198 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3199 | return -EINVAL; |
| 3200 | params.p2p_ctwindow = |
| 3201 | nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
| 3202 | if (params.p2p_ctwindow > 127) |
| 3203 | return -EINVAL; |
| 3204 | if (params.p2p_ctwindow != 0 && |
| 3205 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 3206 | return -EINVAL; |
| 3207 | } |
| 3208 | |
| 3209 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 3210 | u8 tmp; |
| 3211 | |
| 3212 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3213 | return -EINVAL; |
| 3214 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
| 3215 | if (tmp > 1) |
| 3216 | return -EINVAL; |
| 3217 | params.p2p_opp_ps = tmp; |
| 3218 | if (params.p2p_opp_ps != 0 && |
| 3219 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 3220 | return -EINVAL; |
| 3221 | } |
| 3222 | |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3223 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3224 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
| 3225 | if (err) |
| 3226 | return err; |
| 3227 | } else if (wdev->preset_chandef.chan) { |
| 3228 | params.chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3229 | } else if (!nl80211_get_ap_channel(rdev, ¶ms)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3230 | return -EINVAL; |
| 3231 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3232 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, ¶ms.chandef)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3233 | return -EINVAL; |
| 3234 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 3235 | err = cfg80211_chandef_dfs_required(wdev->wiphy, ¶ms.chandef); |
| 3236 | if (err < 0) |
| 3237 | return err; |
| 3238 | if (err) { |
| 3239 | radar_detect_width = BIT(params.chandef.width); |
| 3240 | params.radar_required = true; |
| 3241 | } |
| 3242 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 3243 | err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype, |
| 3244 | params.chandef.chan, |
| 3245 | CHAN_MODE_SHARED, |
| 3246 | radar_detect_width); |
Michal Kazior | e4e3245 | 2012-06-29 12:47:08 +0200 | [diff] [blame] | 3247 | if (err) |
| 3248 | return err; |
| 3249 | |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 3250 | if (info->attrs[NL80211_ATTR_ACL_POLICY]) { |
| 3251 | params.acl = parse_acl_data(&rdev->wiphy, info); |
| 3252 | if (IS_ERR(params.acl)) |
| 3253 | return PTR_ERR(params.acl); |
| 3254 | } |
| 3255 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 3256 | wdev_lock(wdev); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3257 | err = rdev_start_ap(rdev, dev, ¶ms); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3258 | if (!err) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3259 | wdev->preset_chandef = params.chandef; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3260 | wdev->beacon_interval = params.beacon_interval; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3261 | wdev->channel = params.chandef.chan; |
Antonio Quartulli | 06e191e | 2012-11-07 12:52:19 +0100 | [diff] [blame] | 3262 | wdev->ssid_len = params.ssid_len; |
| 3263 | memcpy(wdev->ssid, params.ssid, wdev->ssid_len); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3264 | } |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 3265 | wdev_unlock(wdev); |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 3266 | |
| 3267 | kfree(params.acl); |
| 3268 | |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 3269 | return err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3270 | } |
| 3271 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3272 | static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info) |
| 3273 | { |
| 3274 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3275 | struct net_device *dev = info->user_ptr[1]; |
| 3276 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3277 | struct cfg80211_beacon_data params; |
| 3278 | int err; |
| 3279 | |
| 3280 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3281 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3282 | return -EOPNOTSUPP; |
| 3283 | |
| 3284 | if (!rdev->ops->change_beacon) |
| 3285 | return -EOPNOTSUPP; |
| 3286 | |
| 3287 | if (!wdev->beacon_interval) |
| 3288 | return -EINVAL; |
| 3289 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3290 | err = nl80211_parse_beacon(info->attrs, ¶ms); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3291 | if (err) |
| 3292 | return err; |
| 3293 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 3294 | wdev_lock(wdev); |
| 3295 | err = rdev_change_beacon(rdev, dev, ¶ms); |
| 3296 | wdev_unlock(wdev); |
| 3297 | |
| 3298 | return err; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3299 | } |
| 3300 | |
| 3301 | 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] | 3302 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3303 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3304 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3305 | |
Michal Kazior | 6077178 | 2012-06-29 12:46:56 +0200 | [diff] [blame] | 3306 | return cfg80211_stop_ap(rdev, dev); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3307 | } |
| 3308 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3309 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
| 3310 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, |
| 3311 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, |
| 3312 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, |
Jouni Malinen | 0e46724 | 2009-05-11 21:57:55 +0300 | [diff] [blame] | 3313 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 3314 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
Johannes Berg | d83023d | 2011-12-14 09:29:15 +0100 | [diff] [blame] | 3315 | [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3316 | }; |
| 3317 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3318 | static int parse_station_flags(struct genl_info *info, |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3319 | enum nl80211_iftype iftype, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3320 | struct station_parameters *params) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3321 | { |
| 3322 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3323 | struct nlattr *nla; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3324 | int flag; |
| 3325 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3326 | /* |
| 3327 | * Try parsing the new attribute first so userspace |
| 3328 | * can specify both for older kernels. |
| 3329 | */ |
| 3330 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; |
| 3331 | if (nla) { |
| 3332 | struct nl80211_sta_flag_update *sta_flags; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3333 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3334 | sta_flags = nla_data(nla); |
| 3335 | params->sta_flags_mask = sta_flags->mask; |
| 3336 | params->sta_flags_set = sta_flags->set; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3337 | params->sta_flags_set &= params->sta_flags_mask; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3338 | if ((params->sta_flags_mask | |
| 3339 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) |
| 3340 | return -EINVAL; |
| 3341 | return 0; |
| 3342 | } |
| 3343 | |
| 3344 | /* if present, parse the old attribute */ |
| 3345 | |
| 3346 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3347 | if (!nla) |
| 3348 | return 0; |
| 3349 | |
| 3350 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, |
| 3351 | nla, sta_flags_policy)) |
| 3352 | return -EINVAL; |
| 3353 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3354 | /* |
| 3355 | * Only allow certain flags for interface types so that |
| 3356 | * other attributes are silently ignored. Remember that |
| 3357 | * this is backward compatibility code with old userspace |
| 3358 | * and shouldn't be hit in other cases anyway. |
| 3359 | */ |
| 3360 | switch (iftype) { |
| 3361 | case NL80211_IFTYPE_AP: |
| 3362 | case NL80211_IFTYPE_AP_VLAN: |
| 3363 | case NL80211_IFTYPE_P2P_GO: |
| 3364 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3365 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 3366 | BIT(NL80211_STA_FLAG_WME) | |
| 3367 | BIT(NL80211_STA_FLAG_MFP); |
| 3368 | break; |
| 3369 | case NL80211_IFTYPE_P2P_CLIENT: |
| 3370 | case NL80211_IFTYPE_STATION: |
| 3371 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3372 | BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3373 | break; |
| 3374 | case NL80211_IFTYPE_MESH_POINT: |
| 3375 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3376 | BIT(NL80211_STA_FLAG_MFP) | |
| 3377 | BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 3378 | default: |
| 3379 | return -EINVAL; |
| 3380 | } |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3381 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 3382 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) { |
| 3383 | if (flags[flag]) { |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3384 | params->sta_flags_set |= (1<<flag); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3385 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 3386 | /* no longer support new API additions in old API */ |
| 3387 | if (flag > NL80211_STA_FLAG_MAX_OLD_API) |
| 3388 | return -EINVAL; |
| 3389 | } |
| 3390 | } |
| 3391 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3392 | return 0; |
| 3393 | } |
| 3394 | |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3395 | static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, |
| 3396 | int attr) |
| 3397 | { |
| 3398 | struct nlattr *rate; |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 3399 | u32 bitrate; |
| 3400 | u16 bitrate_compat; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3401 | |
| 3402 | rate = nla_nest_start(msg, attr); |
| 3403 | if (!rate) |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 3404 | return false; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3405 | |
| 3406 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ |
| 3407 | bitrate = cfg80211_calculate_bitrate(info); |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 3408 | /* report 16-bit bitrate only if we can */ |
| 3409 | bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 3410 | if (bitrate > 0 && |
| 3411 | nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate)) |
| 3412 | return false; |
| 3413 | if (bitrate_compat > 0 && |
| 3414 | nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat)) |
| 3415 | return false; |
| 3416 | |
| 3417 | if (info->flags & RATE_INFO_FLAGS_MCS) { |
| 3418 | if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) |
| 3419 | return false; |
| 3420 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && |
| 3421 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) |
| 3422 | return false; |
| 3423 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 3424 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 3425 | return false; |
| 3426 | } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) { |
| 3427 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs)) |
| 3428 | return false; |
| 3429 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss)) |
| 3430 | return false; |
| 3431 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && |
| 3432 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) |
| 3433 | return false; |
| 3434 | if (info->flags & RATE_INFO_FLAGS_80_MHZ_WIDTH && |
| 3435 | nla_put_flag(msg, NL80211_RATE_INFO_80_MHZ_WIDTH)) |
| 3436 | return false; |
| 3437 | if (info->flags & RATE_INFO_FLAGS_80P80_MHZ_WIDTH && |
| 3438 | nla_put_flag(msg, NL80211_RATE_INFO_80P80_MHZ_WIDTH)) |
| 3439 | return false; |
| 3440 | if (info->flags & RATE_INFO_FLAGS_160_MHZ_WIDTH && |
| 3441 | nla_put_flag(msg, NL80211_RATE_INFO_160_MHZ_WIDTH)) |
| 3442 | return false; |
| 3443 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 3444 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 3445 | return false; |
| 3446 | } |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3447 | |
| 3448 | nla_nest_end(msg, rate); |
| 3449 | return true; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3450 | } |
| 3451 | |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 3452 | static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal, |
| 3453 | int id) |
| 3454 | { |
| 3455 | void *attr; |
| 3456 | int i = 0; |
| 3457 | |
| 3458 | if (!mask) |
| 3459 | return true; |
| 3460 | |
| 3461 | attr = nla_nest_start(msg, id); |
| 3462 | if (!attr) |
| 3463 | return false; |
| 3464 | |
| 3465 | for (i = 0; i < IEEE80211_MAX_CHAINS; i++) { |
| 3466 | if (!(mask & BIT(i))) |
| 3467 | continue; |
| 3468 | |
| 3469 | if (nla_put_u8(msg, i, signal[i])) |
| 3470 | return false; |
| 3471 | } |
| 3472 | |
| 3473 | nla_nest_end(msg, attr); |
| 3474 | |
| 3475 | return true; |
| 3476 | } |
| 3477 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3478 | 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] | 3479 | int flags, |
| 3480 | struct cfg80211_registered_device *rdev, |
| 3481 | struct net_device *dev, |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 3482 | const u8 *mac_addr, struct station_info *sinfo) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3483 | { |
| 3484 | void *hdr; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3485 | struct nlattr *sinfoattr, *bss_param; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3486 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3487 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3488 | if (!hdr) |
| 3489 | return -1; |
| 3490 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3491 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 3492 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 3493 | nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation)) |
| 3494 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 3495 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3496 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
| 3497 | if (!sinfoattr) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3498 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3499 | if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) && |
| 3500 | nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME, |
| 3501 | sinfo->connected_time)) |
| 3502 | goto nla_put_failure; |
| 3503 | if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) && |
| 3504 | nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME, |
| 3505 | sinfo->inactive_time)) |
| 3506 | goto nla_put_failure; |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3507 | if ((sinfo->filled & (STATION_INFO_RX_BYTES | |
| 3508 | STATION_INFO_RX_BYTES64)) && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3509 | nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES, |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3510 | (u32)sinfo->rx_bytes)) |
| 3511 | goto nla_put_failure; |
| 3512 | if ((sinfo->filled & (STATION_INFO_TX_BYTES | |
Felix Fietkau | 4325d72 | 2013-05-23 15:05:59 +0200 | [diff] [blame] | 3513 | STATION_INFO_TX_BYTES64)) && |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3514 | nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES, |
| 3515 | (u32)sinfo->tx_bytes)) |
| 3516 | goto nla_put_failure; |
| 3517 | if ((sinfo->filled & STATION_INFO_RX_BYTES64) && |
| 3518 | nla_put_u64(msg, NL80211_STA_INFO_RX_BYTES64, |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3519 | sinfo->rx_bytes)) |
| 3520 | goto nla_put_failure; |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3521 | if ((sinfo->filled & STATION_INFO_TX_BYTES64) && |
| 3522 | nla_put_u64(msg, NL80211_STA_INFO_TX_BYTES64, |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3523 | sinfo->tx_bytes)) |
| 3524 | goto nla_put_failure; |
| 3525 | if ((sinfo->filled & STATION_INFO_LLID) && |
| 3526 | nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid)) |
| 3527 | goto nla_put_failure; |
| 3528 | if ((sinfo->filled & STATION_INFO_PLID) && |
| 3529 | nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid)) |
| 3530 | goto nla_put_failure; |
| 3531 | if ((sinfo->filled & STATION_INFO_PLINK_STATE) && |
| 3532 | nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE, |
| 3533 | sinfo->plink_state)) |
| 3534 | goto nla_put_failure; |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3535 | switch (rdev->wiphy.signal_type) { |
| 3536 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3537 | if ((sinfo->filled & STATION_INFO_SIGNAL) && |
| 3538 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL, |
| 3539 | sinfo->signal)) |
| 3540 | goto nla_put_failure; |
| 3541 | if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) && |
| 3542 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG, |
| 3543 | sinfo->signal_avg)) |
| 3544 | goto nla_put_failure; |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3545 | break; |
| 3546 | default: |
| 3547 | break; |
| 3548 | } |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 3549 | if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL) { |
| 3550 | if (!nl80211_put_signal(msg, sinfo->chains, |
| 3551 | sinfo->chain_signal, |
| 3552 | NL80211_STA_INFO_CHAIN_SIGNAL)) |
| 3553 | goto nla_put_failure; |
| 3554 | } |
| 3555 | if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL_AVG) { |
| 3556 | if (!nl80211_put_signal(msg, sinfo->chains, |
| 3557 | sinfo->chain_signal_avg, |
| 3558 | NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) |
| 3559 | goto nla_put_failure; |
| 3560 | } |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3561 | if (sinfo->filled & STATION_INFO_TX_BITRATE) { |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3562 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
| 3563 | NL80211_STA_INFO_TX_BITRATE)) |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3564 | goto nla_put_failure; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3565 | } |
| 3566 | if (sinfo->filled & STATION_INFO_RX_BITRATE) { |
| 3567 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, |
| 3568 | NL80211_STA_INFO_RX_BITRATE)) |
| 3569 | goto nla_put_failure; |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3570 | } |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3571 | if ((sinfo->filled & STATION_INFO_RX_PACKETS) && |
| 3572 | nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS, |
| 3573 | sinfo->rx_packets)) |
| 3574 | goto nla_put_failure; |
| 3575 | if ((sinfo->filled & STATION_INFO_TX_PACKETS) && |
| 3576 | nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS, |
| 3577 | sinfo->tx_packets)) |
| 3578 | goto nla_put_failure; |
| 3579 | if ((sinfo->filled & STATION_INFO_TX_RETRIES) && |
| 3580 | nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES, |
| 3581 | sinfo->tx_retries)) |
| 3582 | goto nla_put_failure; |
| 3583 | if ((sinfo->filled & STATION_INFO_TX_FAILED) && |
| 3584 | nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED, |
| 3585 | sinfo->tx_failed)) |
| 3586 | goto nla_put_failure; |
| 3587 | if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) && |
| 3588 | nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS, |
| 3589 | sinfo->beacon_loss_count)) |
| 3590 | goto nla_put_failure; |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 3591 | if ((sinfo->filled & STATION_INFO_LOCAL_PM) && |
| 3592 | nla_put_u32(msg, NL80211_STA_INFO_LOCAL_PM, |
| 3593 | sinfo->local_pm)) |
| 3594 | goto nla_put_failure; |
| 3595 | if ((sinfo->filled & STATION_INFO_PEER_PM) && |
| 3596 | nla_put_u32(msg, NL80211_STA_INFO_PEER_PM, |
| 3597 | sinfo->peer_pm)) |
| 3598 | goto nla_put_failure; |
| 3599 | if ((sinfo->filled & STATION_INFO_NONPEER_PM) && |
| 3600 | nla_put_u32(msg, NL80211_STA_INFO_NONPEER_PM, |
| 3601 | sinfo->nonpeer_pm)) |
| 3602 | goto nla_put_failure; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3603 | if (sinfo->filled & STATION_INFO_BSS_PARAM) { |
| 3604 | bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); |
| 3605 | if (!bss_param) |
| 3606 | goto nla_put_failure; |
| 3607 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3608 | if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) && |
| 3609 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) || |
| 3610 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) && |
| 3611 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) || |
| 3612 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) && |
| 3613 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) || |
| 3614 | nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, |
| 3615 | sinfo->bss_param.dtim_period) || |
| 3616 | nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, |
| 3617 | sinfo->bss_param.beacon_interval)) |
| 3618 | goto nla_put_failure; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3619 | |
| 3620 | nla_nest_end(msg, bss_param); |
| 3621 | } |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3622 | if ((sinfo->filled & STATION_INFO_STA_FLAGS) && |
| 3623 | nla_put(msg, NL80211_STA_INFO_STA_FLAGS, |
| 3624 | sizeof(struct nl80211_sta_flag_update), |
| 3625 | &sinfo->sta_flags)) |
| 3626 | goto nla_put_failure; |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 3627 | if ((sinfo->filled & STATION_INFO_T_OFFSET) && |
| 3628 | nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET, |
| 3629 | sinfo->t_offset)) |
| 3630 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3631 | nla_nest_end(msg, sinfoattr); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3632 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3633 | if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) && |
| 3634 | nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, |
| 3635 | sinfo->assoc_req_ies)) |
| 3636 | goto nla_put_failure; |
Jouni Malinen | 50d3dfb | 2011-08-08 12:11:52 +0300 | [diff] [blame] | 3637 | |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3638 | return genlmsg_end(msg, hdr); |
| 3639 | |
| 3640 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 3641 | genlmsg_cancel(msg, hdr); |
| 3642 | return -EMSGSIZE; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3643 | } |
| 3644 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3645 | static int nl80211_dump_station(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3646 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3647 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3648 | struct station_info sinfo; |
| 3649 | struct cfg80211_registered_device *dev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3650 | struct wireless_dev *wdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3651 | u8 mac_addr[ETH_ALEN]; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3652 | int sta_idx = cb->args[2]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3653 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3654 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3655 | err = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3656 | if (err) |
| 3657 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3658 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3659 | if (!wdev->netdev) { |
| 3660 | err = -EINVAL; |
| 3661 | goto out_err; |
| 3662 | } |
| 3663 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3664 | if (!dev->ops->dump_station) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3665 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3666 | goto out_err; |
| 3667 | } |
| 3668 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3669 | while (1) { |
Jouni Malinen | f612ced | 2011-08-11 11:46:22 +0300 | [diff] [blame] | 3670 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3671 | err = rdev_dump_station(dev, wdev->netdev, sta_idx, |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3672 | mac_addr, &sinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3673 | if (err == -ENOENT) |
| 3674 | break; |
| 3675 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3676 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3677 | |
| 3678 | if (nl80211_send_station(skb, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3679 | NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3680 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3681 | dev, wdev->netdev, mac_addr, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3682 | &sinfo) < 0) |
| 3683 | goto out; |
| 3684 | |
| 3685 | sta_idx++; |
| 3686 | } |
| 3687 | |
| 3688 | |
| 3689 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3690 | cb->args[2] = sta_idx; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3691 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3692 | out_err: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3693 | nl80211_finish_wdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3694 | |
| 3695 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3696 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3697 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3698 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
| 3699 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3700 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3701 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3702 | struct station_info sinfo; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3703 | struct sk_buff *msg; |
| 3704 | u8 *mac_addr = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3705 | int err; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3706 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3707 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3708 | |
| 3709 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3710 | return -EINVAL; |
| 3711 | |
| 3712 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3713 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3714 | if (!rdev->ops->get_station) |
| 3715 | return -EOPNOTSUPP; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3716 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3717 | err = rdev_get_station(rdev, dev, mac_addr, &sinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3718 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3719 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3720 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3721 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3722 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3723 | return -ENOMEM; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3724 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3725 | 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] | 3726 | rdev, dev, mac_addr, &sinfo) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3727 | nlmsg_free(msg); |
| 3728 | return -ENOBUFS; |
| 3729 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3730 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3731 | return genlmsg_reply(msg, info); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3732 | } |
| 3733 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3734 | int cfg80211_check_station_change(struct wiphy *wiphy, |
| 3735 | struct station_parameters *params, |
| 3736 | enum cfg80211_station_type statype) |
| 3737 | { |
| 3738 | if (params->listen_interval != -1) |
| 3739 | return -EINVAL; |
| 3740 | if (params->aid) |
| 3741 | return -EINVAL; |
| 3742 | |
| 3743 | /* When you run into this, adjust the code below for the new flag */ |
| 3744 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); |
| 3745 | |
| 3746 | switch (statype) { |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 3747 | case CFG80211_STA_MESH_PEER_KERNEL: |
| 3748 | case CFG80211_STA_MESH_PEER_USER: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3749 | /* |
| 3750 | * No ignoring the TDLS flag here -- the userspace mesh |
| 3751 | * code doesn't have the bug of including TDLS in the |
| 3752 | * mask everywhere. |
| 3753 | */ |
| 3754 | if (params->sta_flags_mask & |
| 3755 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3756 | BIT(NL80211_STA_FLAG_MFP) | |
| 3757 | BIT(NL80211_STA_FLAG_AUTHORIZED))) |
| 3758 | return -EINVAL; |
| 3759 | break; |
| 3760 | case CFG80211_STA_TDLS_PEER_SETUP: |
| 3761 | case CFG80211_STA_TDLS_PEER_ACTIVE: |
| 3762 | if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 3763 | return -EINVAL; |
| 3764 | /* ignore since it can't change */ |
| 3765 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3766 | break; |
| 3767 | default: |
| 3768 | /* disallow mesh-specific things */ |
| 3769 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) |
| 3770 | return -EINVAL; |
| 3771 | if (params->local_pm) |
| 3772 | return -EINVAL; |
| 3773 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
| 3774 | return -EINVAL; |
| 3775 | } |
| 3776 | |
| 3777 | if (statype != CFG80211_STA_TDLS_PEER_SETUP && |
| 3778 | statype != CFG80211_STA_TDLS_PEER_ACTIVE) { |
| 3779 | /* TDLS can't be set, ... */ |
| 3780 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
| 3781 | return -EINVAL; |
| 3782 | /* |
| 3783 | * ... but don't bother the driver with it. This works around |
| 3784 | * a hostapd/wpa_supplicant issue -- it always includes the |
| 3785 | * TLDS_PEER flag in the mask even for AP mode. |
| 3786 | */ |
| 3787 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3788 | } |
| 3789 | |
| 3790 | if (statype != CFG80211_STA_TDLS_PEER_SETUP) { |
| 3791 | /* reject other things that can't change */ |
| 3792 | if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) |
| 3793 | return -EINVAL; |
| 3794 | if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY) |
| 3795 | return -EINVAL; |
| 3796 | if (params->supported_rates) |
| 3797 | return -EINVAL; |
| 3798 | if (params->ext_capab || params->ht_capa || params->vht_capa) |
| 3799 | return -EINVAL; |
| 3800 | } |
| 3801 | |
| 3802 | if (statype != CFG80211_STA_AP_CLIENT) { |
| 3803 | if (params->vlan) |
| 3804 | return -EINVAL; |
| 3805 | } |
| 3806 | |
| 3807 | switch (statype) { |
| 3808 | case CFG80211_STA_AP_MLME_CLIENT: |
| 3809 | /* Use this only for authorizing/unauthorizing a station */ |
| 3810 | if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))) |
| 3811 | return -EOPNOTSUPP; |
| 3812 | break; |
| 3813 | case CFG80211_STA_AP_CLIENT: |
| 3814 | /* accept only the listed bits */ |
| 3815 | if (params->sta_flags_mask & |
| 3816 | ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3817 | BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3818 | BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 3819 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 3820 | BIT(NL80211_STA_FLAG_WME) | |
| 3821 | BIT(NL80211_STA_FLAG_MFP))) |
| 3822 | return -EINVAL; |
| 3823 | |
| 3824 | /* but authenticated/associated only if driver handles it */ |
| 3825 | if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
| 3826 | params->sta_flags_mask & |
| 3827 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3828 | BIT(NL80211_STA_FLAG_ASSOCIATED))) |
| 3829 | return -EINVAL; |
| 3830 | break; |
| 3831 | case CFG80211_STA_IBSS: |
| 3832 | case CFG80211_STA_AP_STA: |
| 3833 | /* reject any changes other than AUTHORIZED */ |
| 3834 | if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) |
| 3835 | return -EINVAL; |
| 3836 | break; |
| 3837 | case CFG80211_STA_TDLS_PEER_SETUP: |
| 3838 | /* reject any changes other than AUTHORIZED or WME */ |
| 3839 | if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3840 | BIT(NL80211_STA_FLAG_WME))) |
| 3841 | return -EINVAL; |
| 3842 | /* force (at least) rates when authorizing */ |
| 3843 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) && |
| 3844 | !params->supported_rates) |
| 3845 | return -EINVAL; |
| 3846 | break; |
| 3847 | case CFG80211_STA_TDLS_PEER_ACTIVE: |
| 3848 | /* reject any changes */ |
| 3849 | return -EINVAL; |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 3850 | case CFG80211_STA_MESH_PEER_KERNEL: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3851 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
| 3852 | return -EINVAL; |
| 3853 | break; |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 3854 | case CFG80211_STA_MESH_PEER_USER: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3855 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) |
| 3856 | return -EINVAL; |
| 3857 | break; |
| 3858 | } |
| 3859 | |
| 3860 | return 0; |
| 3861 | } |
| 3862 | EXPORT_SYMBOL(cfg80211_check_station_change); |
| 3863 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3864 | /* |
Felix Fietkau | c258d2d | 2009-11-11 17:23:31 +0100 | [diff] [blame] | 3865 | * 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] | 3866 | */ |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3867 | static struct net_device *get_vlan(struct genl_info *info, |
| 3868 | struct cfg80211_registered_device *rdev) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3869 | { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3870 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3871 | struct net_device *v; |
| 3872 | int ret; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3873 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3874 | if (!vlanattr) |
| 3875 | return NULL; |
| 3876 | |
| 3877 | v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); |
| 3878 | if (!v) |
| 3879 | return ERR_PTR(-ENODEV); |
| 3880 | |
| 3881 | if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { |
| 3882 | ret = -EINVAL; |
| 3883 | goto error; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3884 | } |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3885 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3886 | if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
| 3887 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3888 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { |
| 3889 | ret = -EINVAL; |
| 3890 | goto error; |
| 3891 | } |
| 3892 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3893 | if (!netif_running(v)) { |
| 3894 | ret = -ENETDOWN; |
| 3895 | goto error; |
| 3896 | } |
| 3897 | |
| 3898 | return v; |
| 3899 | error: |
| 3900 | dev_put(v); |
| 3901 | return ERR_PTR(ret); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3902 | } |
| 3903 | |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3904 | static struct nla_policy |
| 3905 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] __read_mostly = { |
| 3906 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, |
| 3907 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, |
| 3908 | }; |
| 3909 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 3910 | static int nl80211_parse_sta_wme(struct genl_info *info, |
| 3911 | struct station_parameters *params) |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3912 | { |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3913 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; |
| 3914 | struct nlattr *nla; |
| 3915 | int err; |
| 3916 | |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3917 | /* parse WME attributes if present */ |
| 3918 | if (!info->attrs[NL80211_ATTR_STA_WME]) |
| 3919 | return 0; |
| 3920 | |
| 3921 | nla = info->attrs[NL80211_ATTR_STA_WME]; |
| 3922 | err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla, |
| 3923 | nl80211_sta_wme_policy); |
| 3924 | if (err) |
| 3925 | return err; |
| 3926 | |
| 3927 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) |
| 3928 | params->uapsd_queues = nla_get_u8( |
| 3929 | tb[NL80211_STA_WME_UAPSD_QUEUES]); |
| 3930 | if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) |
| 3931 | return -EINVAL; |
| 3932 | |
| 3933 | if (tb[NL80211_STA_WME_MAX_SP]) |
| 3934 | params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); |
| 3935 | |
| 3936 | if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) |
| 3937 | return -EINVAL; |
| 3938 | |
| 3939 | params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; |
| 3940 | |
| 3941 | return 0; |
| 3942 | } |
| 3943 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 3944 | static int nl80211_parse_sta_channel_info(struct genl_info *info, |
| 3945 | struct station_parameters *params) |
| 3946 | { |
| 3947 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) { |
| 3948 | params->supported_channels = |
| 3949 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); |
| 3950 | params->supported_channels_len = |
| 3951 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); |
| 3952 | /* |
| 3953 | * Need to include at least one (first channel, number of |
| 3954 | * channels) tuple for each subband, and must have proper |
| 3955 | * tuples for the rest of the data as well. |
| 3956 | */ |
| 3957 | if (params->supported_channels_len < 2) |
| 3958 | return -EINVAL; |
| 3959 | if (params->supported_channels_len % 2) |
| 3960 | return -EINVAL; |
| 3961 | } |
| 3962 | |
| 3963 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) { |
| 3964 | params->supported_oper_classes = |
| 3965 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); |
| 3966 | params->supported_oper_classes_len = |
| 3967 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); |
| 3968 | /* |
| 3969 | * The value of the Length field of the Supported Operating |
| 3970 | * Classes element is between 2 and 253. |
| 3971 | */ |
| 3972 | if (params->supported_oper_classes_len < 2 || |
| 3973 | params->supported_oper_classes_len > 253) |
| 3974 | return -EINVAL; |
| 3975 | } |
| 3976 | return 0; |
| 3977 | } |
| 3978 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 3979 | static int nl80211_set_station_tdls(struct genl_info *info, |
| 3980 | struct station_parameters *params) |
| 3981 | { |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 3982 | int err; |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 3983 | /* Dummy STA entry gets updated once the peer capabilities are known */ |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 3984 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
| 3985 | params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 3986 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 3987 | params->ht_capa = |
| 3988 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
| 3989 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 3990 | params->vht_capa = |
| 3991 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 3992 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 3993 | err = nl80211_parse_sta_channel_info(info, params); |
| 3994 | if (err) |
| 3995 | return err; |
| 3996 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 3997 | return nl80211_parse_sta_wme(info, params); |
| 3998 | } |
| 3999 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4000 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
| 4001 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4002 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4003 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4004 | struct station_parameters params; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4005 | u8 *mac_addr; |
| 4006 | int err; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4007 | |
| 4008 | memset(¶ms, 0, sizeof(params)); |
| 4009 | |
| 4010 | params.listen_interval = -1; |
| 4011 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4012 | if (!rdev->ops->change_station) |
| 4013 | return -EOPNOTSUPP; |
| 4014 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4015 | if (info->attrs[NL80211_ATTR_STA_AID]) |
| 4016 | return -EINVAL; |
| 4017 | |
| 4018 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4019 | return -EINVAL; |
| 4020 | |
| 4021 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4022 | |
| 4023 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { |
| 4024 | params.supported_rates = |
| 4025 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4026 | params.supported_rates_len = |
| 4027 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4028 | } |
| 4029 | |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 4030 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
| 4031 | params.capability = |
| 4032 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); |
| 4033 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; |
| 4034 | } |
| 4035 | |
| 4036 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { |
| 4037 | params.ext_capab = |
| 4038 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4039 | params.ext_capab_len = |
| 4040 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4041 | } |
| 4042 | |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 4043 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
Johannes Berg | ba23d20 | 2012-12-27 17:32:09 +0100 | [diff] [blame] | 4044 | return -EINVAL; |
Jouni Malinen | 36aedc90 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 4045 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 4046 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4047 | return -EINVAL; |
| 4048 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4049 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4050 | params.plink_action = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4051 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 4052 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) |
| 4053 | return -EINVAL; |
| 4054 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4055 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4056 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) { |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 4057 | params.plink_state = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4058 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
| 4059 | if (params.plink_state >= NUM_NL80211_PLINK_STATES) |
| 4060 | return -EINVAL; |
| 4061 | params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE; |
| 4062 | } |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 4063 | |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4064 | if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) { |
| 4065 | enum nl80211_mesh_power_mode pm = nla_get_u32( |
| 4066 | info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]); |
| 4067 | |
| 4068 | if (pm <= NL80211_MESH_POWER_UNKNOWN || |
| 4069 | pm > NL80211_MESH_POWER_MAX) |
| 4070 | return -EINVAL; |
| 4071 | |
| 4072 | params.local_pm = pm; |
| 4073 | } |
| 4074 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4075 | /* Include parameters for TDLS peer (will check later) */ |
| 4076 | err = nl80211_set_station_tdls(info, ¶ms); |
| 4077 | if (err) |
| 4078 | return err; |
| 4079 | |
| 4080 | params.vlan = get_vlan(info, rdev); |
| 4081 | if (IS_ERR(params.vlan)) |
| 4082 | return PTR_ERR(params.vlan); |
| 4083 | |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4084 | switch (dev->ieee80211_ptr->iftype) { |
| 4085 | case NL80211_IFTYPE_AP: |
| 4086 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4087 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4088 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4089 | case NL80211_IFTYPE_STATION: |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 4090 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4091 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4092 | break; |
| 4093 | default: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4094 | err = -EOPNOTSUPP; |
| 4095 | goto out_put_vlan; |
Johannes Berg | 034d655 | 2009-05-27 10:35:29 +0200 | [diff] [blame] | 4096 | } |
| 4097 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4098 | /* driver will call cfg80211_check_station_change() */ |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4099 | err = rdev_change_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4100 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4101 | out_put_vlan: |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4102 | if (params.vlan) |
| 4103 | dev_put(params.vlan); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4104 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4105 | return err; |
| 4106 | } |
| 4107 | |
| 4108 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) |
| 4109 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4110 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4111 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4112 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4113 | struct station_parameters params; |
| 4114 | u8 *mac_addr = NULL; |
| 4115 | |
| 4116 | memset(¶ms, 0, sizeof(params)); |
| 4117 | |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4118 | if (!rdev->ops->add_station) |
| 4119 | return -EOPNOTSUPP; |
| 4120 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4121 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4122 | return -EINVAL; |
| 4123 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4124 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 4125 | return -EINVAL; |
| 4126 | |
| 4127 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) |
| 4128 | return -EINVAL; |
| 4129 | |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 4130 | if (!info->attrs[NL80211_ATTR_STA_AID] && |
| 4131 | !info->attrs[NL80211_ATTR_PEER_AID]) |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 4132 | return -EINVAL; |
| 4133 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4134 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4135 | params.supported_rates = |
| 4136 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4137 | params.supported_rates_len = |
| 4138 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4139 | params.listen_interval = |
| 4140 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 4141 | |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4142 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 4143 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4144 | else |
| 4145 | 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] | 4146 | if (!params.aid || params.aid > IEEE80211_MAX_AID) |
| 4147 | return -EINVAL; |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 4148 | |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 4149 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
| 4150 | params.capability = |
| 4151 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); |
| 4152 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; |
| 4153 | } |
| 4154 | |
| 4155 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { |
| 4156 | params.ext_capab = |
| 4157 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4158 | params.ext_capab_len = |
| 4159 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4160 | } |
| 4161 | |
Jouni Malinen | 36aedc90 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 4162 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 4163 | params.ht_capa = |
| 4164 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4165 | |
Mahesh Palivela | f461be3e | 2012-10-11 08:04:52 +0000 | [diff] [blame] | 4166 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 4167 | params.vht_capa = |
| 4168 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 4169 | |
Marek Kwaczynski | 60f4a7b | 2013-12-03 10:04:59 +0100 | [diff] [blame] | 4170 | if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) { |
| 4171 | params.opmode_notif_used = true; |
| 4172 | params.opmode_notif = |
| 4173 | nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]); |
| 4174 | } |
| 4175 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4176 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 4177 | params.plink_action = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4178 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 4179 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) |
| 4180 | return -EINVAL; |
| 4181 | } |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 4182 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 4183 | err = nl80211_parse_sta_channel_info(info, ¶ms); |
| 4184 | if (err) |
| 4185 | return err; |
| 4186 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4187 | err = nl80211_parse_sta_wme(info, ¶ms); |
| 4188 | if (err) |
| 4189 | return err; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4190 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 4191 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4192 | return -EINVAL; |
| 4193 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4194 | /* When you run into this, adjust the code below for the new flag */ |
| 4195 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); |
| 4196 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4197 | switch (dev->ieee80211_ptr->iftype) { |
| 4198 | case NL80211_IFTYPE_AP: |
| 4199 | case NL80211_IFTYPE_AP_VLAN: |
| 4200 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4201 | /* ignore WME attributes if iface/sta is not capable */ |
| 4202 | if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) || |
| 4203 | !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) |
| 4204 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4205 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4206 | /* TDLS peers cannot be added */ |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4207 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
| 4208 | info->attrs[NL80211_ATTR_PEER_AID]) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 4209 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4210 | /* but don't bother the driver with it */ |
| 4211 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4212 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4213 | /* allow authenticated/associated only if driver handles it */ |
| 4214 | if (!(rdev->wiphy.features & |
| 4215 | NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
| 4216 | params.sta_flags_mask & |
| 4217 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 4218 | BIT(NL80211_STA_FLAG_ASSOCIATED))) |
| 4219 | return -EINVAL; |
| 4220 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4221 | /* must be last in here for error handling */ |
| 4222 | params.vlan = get_vlan(info, rdev); |
| 4223 | if (IS_ERR(params.vlan)) |
| 4224 | return PTR_ERR(params.vlan); |
| 4225 | break; |
| 4226 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4227 | /* ignore uAPSD data */ |
| 4228 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
| 4229 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4230 | /* associated is disallowed */ |
| 4231 | if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) |
| 4232 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4233 | /* TDLS peers cannot be added */ |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4234 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
| 4235 | info->attrs[NL80211_ATTR_PEER_AID]) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 4236 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4237 | break; |
| 4238 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 93d08f0 | 2013-03-04 09:29:46 +0100 | [diff] [blame] | 4239 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4240 | /* ignore uAPSD data */ |
| 4241 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
| 4242 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4243 | /* these are disallowed */ |
| 4244 | if (params.sta_flags_mask & |
| 4245 | (BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 4246 | BIT(NL80211_STA_FLAG_AUTHENTICATED))) |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4247 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4248 | /* Only TDLS peers can be added */ |
| 4249 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 4250 | return -EINVAL; |
| 4251 | /* Can only add if TDLS ... */ |
| 4252 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) |
| 4253 | return -EOPNOTSUPP; |
| 4254 | /* ... with external setup is supported */ |
| 4255 | if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) |
| 4256 | return -EOPNOTSUPP; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4257 | /* |
| 4258 | * Older wpa_supplicant versions always mark the TDLS peer |
| 4259 | * as authorized, but it shouldn't yet be. |
| 4260 | */ |
| 4261 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED); |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4262 | break; |
| 4263 | default: |
| 4264 | return -EOPNOTSUPP; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4265 | } |
| 4266 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4267 | /* be aware of params.vlan when changing code here */ |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4268 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4269 | err = rdev_add_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4270 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4271 | if (params.vlan) |
| 4272 | dev_put(params.vlan); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4273 | return err; |
| 4274 | } |
| 4275 | |
| 4276 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) |
| 4277 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4278 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4279 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4280 | u8 *mac_addr = NULL; |
| 4281 | |
| 4282 | if (info->attrs[NL80211_ATTR_MAC]) |
| 4283 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4284 | |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 4285 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Marco Porsch | d5d9de0 | 2010-03-30 10:00:16 +0200 | [diff] [blame] | 4286 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4287 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4288 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4289 | return -EINVAL; |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 4290 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4291 | if (!rdev->ops->del_station) |
| 4292 | return -EOPNOTSUPP; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4293 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4294 | return rdev_del_station(rdev, dev, mac_addr); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4295 | } |
| 4296 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4297 | 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] | 4298 | int flags, struct net_device *dev, |
| 4299 | u8 *dst, u8 *next_hop, |
| 4300 | struct mpath_info *pinfo) |
| 4301 | { |
| 4302 | void *hdr; |
| 4303 | struct nlattr *pinfoattr; |
| 4304 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4305 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4306 | if (!hdr) |
| 4307 | return -1; |
| 4308 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4309 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 4310 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || |
| 4311 | nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) || |
| 4312 | nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation)) |
| 4313 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 4314 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4315 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
| 4316 | if (!pinfoattr) |
| 4317 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4318 | if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) && |
| 4319 | nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN, |
| 4320 | pinfo->frame_qlen)) |
| 4321 | goto nla_put_failure; |
| 4322 | if (((pinfo->filled & MPATH_INFO_SN) && |
| 4323 | nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) || |
| 4324 | ((pinfo->filled & MPATH_INFO_METRIC) && |
| 4325 | nla_put_u32(msg, NL80211_MPATH_INFO_METRIC, |
| 4326 | pinfo->metric)) || |
| 4327 | ((pinfo->filled & MPATH_INFO_EXPTIME) && |
| 4328 | nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME, |
| 4329 | pinfo->exptime)) || |
| 4330 | ((pinfo->filled & MPATH_INFO_FLAGS) && |
| 4331 | nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS, |
| 4332 | pinfo->flags)) || |
| 4333 | ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) && |
| 4334 | nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, |
| 4335 | pinfo->discovery_timeout)) || |
| 4336 | ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) && |
| 4337 | nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, |
| 4338 | pinfo->discovery_retries))) |
| 4339 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4340 | |
| 4341 | nla_nest_end(msg, pinfoattr); |
| 4342 | |
| 4343 | return genlmsg_end(msg, hdr); |
| 4344 | |
| 4345 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 4346 | genlmsg_cancel(msg, hdr); |
| 4347 | return -EMSGSIZE; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4348 | } |
| 4349 | |
| 4350 | static int nl80211_dump_mpath(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4351 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4352 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4353 | struct mpath_info pinfo; |
| 4354 | struct cfg80211_registered_device *dev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4355 | struct wireless_dev *wdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4356 | u8 dst[ETH_ALEN]; |
| 4357 | u8 next_hop[ETH_ALEN]; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4358 | int path_idx = cb->args[2]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4359 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4360 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4361 | err = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4362 | if (err) |
| 4363 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4364 | |
| 4365 | if (!dev->ops->dump_mpath) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4366 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4367 | goto out_err; |
| 4368 | } |
| 4369 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4370 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4371 | err = -EOPNOTSUPP; |
Roel Kluin | 0448b5f | 2009-08-22 21:15:49 +0200 | [diff] [blame] | 4372 | goto out_err; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4373 | } |
| 4374 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4375 | while (1) { |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4376 | err = rdev_dump_mpath(dev, wdev->netdev, path_idx, dst, |
| 4377 | next_hop, &pinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4378 | if (err == -ENOENT) |
| 4379 | break; |
| 4380 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4381 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4382 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4383 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4384 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4385 | wdev->netdev, dst, next_hop, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4386 | &pinfo) < 0) |
| 4387 | goto out; |
| 4388 | |
| 4389 | path_idx++; |
| 4390 | } |
| 4391 | |
| 4392 | |
| 4393 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4394 | cb->args[2] = path_idx; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4395 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4396 | out_err: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4397 | nl80211_finish_wdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4398 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4399 | } |
| 4400 | |
| 4401 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4402 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4403 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4404 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4405 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4406 | struct mpath_info pinfo; |
| 4407 | struct sk_buff *msg; |
| 4408 | u8 *dst = NULL; |
| 4409 | u8 next_hop[ETH_ALEN]; |
| 4410 | |
| 4411 | memset(&pinfo, 0, sizeof(pinfo)); |
| 4412 | |
| 4413 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4414 | return -EINVAL; |
| 4415 | |
| 4416 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4417 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4418 | if (!rdev->ops->get_mpath) |
| 4419 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4420 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4421 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4422 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4423 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4424 | err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4425 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4426 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4427 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4428 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4429 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4430 | return -ENOMEM; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4431 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4432 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4433 | dev, dst, next_hop, &pinfo) < 0) { |
| 4434 | nlmsg_free(msg); |
| 4435 | return -ENOBUFS; |
| 4436 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4437 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4438 | return genlmsg_reply(msg, info); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4439 | } |
| 4440 | |
| 4441 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4442 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4443 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4444 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4445 | u8 *dst = NULL; |
| 4446 | u8 *next_hop = NULL; |
| 4447 | |
| 4448 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4449 | return -EINVAL; |
| 4450 | |
| 4451 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 4452 | return -EINVAL; |
| 4453 | |
| 4454 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4455 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 4456 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4457 | if (!rdev->ops->change_mpath) |
| 4458 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4459 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4460 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4461 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4462 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4463 | return rdev_change_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4464 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4465 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4466 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4467 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4468 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4469 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4470 | u8 *dst = NULL; |
| 4471 | u8 *next_hop = NULL; |
| 4472 | |
| 4473 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4474 | return -EINVAL; |
| 4475 | |
| 4476 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 4477 | return -EINVAL; |
| 4478 | |
| 4479 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4480 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 4481 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4482 | if (!rdev->ops->add_mpath) |
| 4483 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4484 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4485 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4486 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4487 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4488 | return rdev_add_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4489 | } |
| 4490 | |
| 4491 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4492 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4493 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4494 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4495 | u8 *dst = NULL; |
| 4496 | |
| 4497 | if (info->attrs[NL80211_ATTR_MAC]) |
| 4498 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4499 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4500 | if (!rdev->ops->del_mpath) |
| 4501 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4502 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4503 | return rdev_del_mpath(rdev, dev, dst); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4504 | } |
| 4505 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4506 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
| 4507 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4508 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4509 | struct net_device *dev = info->user_ptr[1]; |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 4510 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4511 | struct bss_parameters params; |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 4512 | int err; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4513 | |
| 4514 | memset(¶ms, 0, sizeof(params)); |
| 4515 | /* default to not changing parameters */ |
| 4516 | params.use_cts_prot = -1; |
| 4517 | params.use_short_preamble = -1; |
| 4518 | params.use_short_slot_time = -1; |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 4519 | params.ap_isolate = -1; |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 4520 | params.ht_opmode = -1; |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 4521 | params.p2p_ctwindow = -1; |
| 4522 | params.p2p_opp_ps = -1; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4523 | |
| 4524 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) |
| 4525 | params.use_cts_prot = |
| 4526 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); |
| 4527 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) |
| 4528 | params.use_short_preamble = |
| 4529 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); |
| 4530 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) |
| 4531 | params.use_short_slot_time = |
| 4532 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 4533 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 4534 | params.basic_rates = |
| 4535 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 4536 | params.basic_rates_len = |
| 4537 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 4538 | } |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 4539 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
| 4540 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 4541 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
| 4542 | params.ht_opmode = |
| 4543 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4544 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 4545 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 4546 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4547 | return -EINVAL; |
| 4548 | params.p2p_ctwindow = |
| 4549 | nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
| 4550 | if (params.p2p_ctwindow < 0) |
| 4551 | return -EINVAL; |
| 4552 | if (params.p2p_ctwindow != 0 && |
| 4553 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 4554 | return -EINVAL; |
| 4555 | } |
| 4556 | |
| 4557 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 4558 | u8 tmp; |
| 4559 | |
| 4560 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4561 | return -EINVAL; |
| 4562 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
| 4563 | if (tmp > 1) |
| 4564 | return -EINVAL; |
| 4565 | params.p2p_opp_ps = tmp; |
| 4566 | if (params.p2p_opp_ps && |
| 4567 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 4568 | return -EINVAL; |
| 4569 | } |
| 4570 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4571 | if (!rdev->ops->change_bss) |
| 4572 | return -EOPNOTSUPP; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4573 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4574 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4575 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4576 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4577 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 4578 | wdev_lock(wdev); |
| 4579 | err = rdev_change_bss(rdev, dev, ¶ms); |
| 4580 | wdev_unlock(wdev); |
| 4581 | |
| 4582 | return err; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4583 | } |
| 4584 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 4585 | 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] | 4586 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
| 4587 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, |
| 4588 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, |
| 4589 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, |
| 4590 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, |
| 4591 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, |
| 4592 | }; |
| 4593 | |
| 4594 | static int parse_reg_rule(struct nlattr *tb[], |
| 4595 | struct ieee80211_reg_rule *reg_rule) |
| 4596 | { |
| 4597 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; |
| 4598 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; |
| 4599 | |
| 4600 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) |
| 4601 | return -EINVAL; |
| 4602 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) |
| 4603 | return -EINVAL; |
| 4604 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) |
| 4605 | return -EINVAL; |
| 4606 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) |
| 4607 | return -EINVAL; |
| 4608 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) |
| 4609 | return -EINVAL; |
| 4610 | |
| 4611 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); |
| 4612 | |
| 4613 | freq_range->start_freq_khz = |
| 4614 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); |
| 4615 | freq_range->end_freq_khz = |
| 4616 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); |
| 4617 | freq_range->max_bandwidth_khz = |
| 4618 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); |
| 4619 | |
| 4620 | power_rule->max_eirp = |
| 4621 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); |
| 4622 | |
| 4623 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) |
| 4624 | power_rule->max_antenna_gain = |
| 4625 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); |
| 4626 | |
| 4627 | return 0; |
| 4628 | } |
| 4629 | |
| 4630 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 4631 | { |
| 4632 | int r; |
| 4633 | char *data = NULL; |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4634 | enum nl80211_user_reg_hint_type user_reg_hint_type; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4635 | |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 4636 | /* |
| 4637 | * You should only get this when cfg80211 hasn't yet initialized |
| 4638 | * completely when built-in to the kernel right between the time |
| 4639 | * window between nl80211_init() and regulatory_init(), if that is |
| 4640 | * even possible. |
| 4641 | */ |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4642 | if (unlikely(!rcu_access_pointer(cfg80211_regdomain))) |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 4643 | return -EINPROGRESS; |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 4644 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 4645 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 4646 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4647 | |
| 4648 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 4649 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4650 | if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]) |
| 4651 | user_reg_hint_type = |
| 4652 | nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]); |
| 4653 | else |
| 4654 | user_reg_hint_type = NL80211_USER_REG_HINT_USER; |
| 4655 | |
| 4656 | switch (user_reg_hint_type) { |
| 4657 | case NL80211_USER_REG_HINT_USER: |
| 4658 | case NL80211_USER_REG_HINT_CELL_BASE: |
| 4659 | break; |
| 4660 | default: |
| 4661 | return -EINVAL; |
| 4662 | } |
| 4663 | |
| 4664 | r = regulatory_hint_user(data, user_reg_hint_type); |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 4665 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4666 | return r; |
| 4667 | } |
| 4668 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4669 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4670 | struct genl_info *info) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4671 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4672 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4673 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4674 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 4675 | struct mesh_config cur_params; |
| 4676 | int err = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4677 | void *hdr; |
| 4678 | struct nlattr *pinfoattr; |
| 4679 | struct sk_buff *msg; |
| 4680 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4681 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4682 | return -EOPNOTSUPP; |
| 4683 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4684 | if (!rdev->ops->get_mesh_config) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4685 | return -EOPNOTSUPP; |
Jouni Malinen | f3f9258 | 2009-03-20 17:57:36 +0200 | [diff] [blame] | 4686 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4687 | wdev_lock(wdev); |
| 4688 | /* If not connected, get default parameters */ |
| 4689 | if (!wdev->mesh_id_len) |
| 4690 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); |
| 4691 | else |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4692 | err = rdev_get_mesh_config(rdev, dev, &cur_params); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4693 | wdev_unlock(wdev); |
| 4694 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4695 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4696 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4697 | |
| 4698 | /* Draw up a netlink message to send back */ |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4699 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4700 | if (!msg) |
| 4701 | return -ENOMEM; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4702 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4703 | NL80211_CMD_GET_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4704 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4705 | goto out; |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4706 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4707 | if (!pinfoattr) |
| 4708 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4709 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 4710 | nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 4711 | cur_params.dot11MeshRetryTimeout) || |
| 4712 | nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 4713 | cur_params.dot11MeshConfirmTimeout) || |
| 4714 | nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 4715 | cur_params.dot11MeshHoldingTimeout) || |
| 4716 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 4717 | cur_params.dot11MeshMaxPeerLinks) || |
| 4718 | nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES, |
| 4719 | cur_params.dot11MeshMaxRetries) || |
| 4720 | nla_put_u8(msg, NL80211_MESHCONF_TTL, |
| 4721 | cur_params.dot11MeshTTL) || |
| 4722 | nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL, |
| 4723 | cur_params.element_ttl) || |
| 4724 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 4725 | cur_params.auto_open_plinks) || |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 4726 | nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 4727 | cur_params.dot11MeshNbrOffsetMaxNeighbor) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4728 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 4729 | cur_params.dot11MeshHWMPmaxPREQretries) || |
| 4730 | nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 4731 | cur_params.path_refresh_time) || |
| 4732 | nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 4733 | cur_params.min_discovery_timeout) || |
| 4734 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 4735 | cur_params.dot11MeshHWMPactivePathTimeout) || |
| 4736 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 4737 | cur_params.dot11MeshHWMPpreqMinInterval) || |
| 4738 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
| 4739 | cur_params.dot11MeshHWMPperrMinInterval) || |
| 4740 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 4741 | cur_params.dot11MeshHWMPnetDiameterTraversalTime) || |
| 4742 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 4743 | cur_params.dot11MeshHWMPRootMode) || |
| 4744 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
| 4745 | cur_params.dot11MeshHWMPRannInterval) || |
| 4746 | nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
| 4747 | cur_params.dot11MeshGateAnnouncementProtocol) || |
| 4748 | nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, |
| 4749 | cur_params.dot11MeshForwarding) || |
| 4750 | nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, |
Ashok Nagarajan | 70c33ea | 2012-04-30 14:20:32 -0700 | [diff] [blame] | 4751 | cur_params.rssi_threshold) || |
| 4752 | nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4753 | cur_params.ht_opmode) || |
| 4754 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 4755 | cur_params.dot11MeshHWMPactivePathToRootTimeout) || |
| 4756 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4757 | cur_params.dot11MeshHWMProotInterval) || |
| 4758 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4759 | cur_params.dot11MeshHWMPconfirmationInterval) || |
| 4760 | nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE, |
| 4761 | cur_params.power_mode) || |
| 4762 | nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW, |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 4763 | cur_params.dot11MeshAwakeWindowDuration) || |
| 4764 | nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT, |
| 4765 | cur_params.plink_timeout)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4766 | goto nla_put_failure; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4767 | nla_nest_end(msg, pinfoattr); |
| 4768 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4769 | return genlmsg_reply(msg, info); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4770 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4771 | nla_put_failure: |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4772 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4773 | out: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 4774 | nlmsg_free(msg); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4775 | return -ENOBUFS; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4776 | } |
| 4777 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 4778 | 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] | 4779 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
| 4780 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, |
| 4781 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, |
| 4782 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, |
| 4783 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, |
| 4784 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 4785 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4786 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 4787 | [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4788 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
| 4789 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, |
| 4790 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, |
| 4791 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, |
| 4792 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 4793 | [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4794 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
Javier Cardona | 699403d | 2011-08-09 16:45:09 -0700 | [diff] [blame] | 4795 | [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 }, |
Javier Cardona | 0507e15 | 2011-08-09 16:45:10 -0700 | [diff] [blame] | 4796 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 }, |
Javier Cardona | 16dd726 | 2011-08-09 16:45:11 -0700 | [diff] [blame] | 4797 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | 94f9065 | 2012-01-21 01:02:16 +0800 | [diff] [blame] | 4798 | [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4799 | [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 }, |
| 4800 | [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4801 | [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 }, |
| 4802 | [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4803 | [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 }, |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4804 | [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 }, |
| 4805 | [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 }, |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 4806 | [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4807 | }; |
| 4808 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4809 | static const struct nla_policy |
| 4810 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 4811 | [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4812 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
| 4813 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 4814 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
Colleen Twitty | 6e16d90 | 2013-05-08 11:45:59 -0700 | [diff] [blame] | 4815 | [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 }, |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 4816 | [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG }, |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4817 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4818 | .len = IEEE80211_MAX_DATA_LEN }, |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 4819 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4820 | }; |
| 4821 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4822 | static int nl80211_parse_mesh_config(struct genl_info *info, |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4823 | struct mesh_config *cfg, |
| 4824 | u32 *mask_out) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4825 | { |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4826 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4827 | u32 mask = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4828 | |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4829 | #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \ |
| 4830 | do { \ |
| 4831 | if (tb[attr]) { \ |
| 4832 | if (fn(tb[attr]) < min || fn(tb[attr]) > max) \ |
| 4833 | return -EINVAL; \ |
| 4834 | cfg->param = fn(tb[attr]); \ |
| 4835 | mask |= (1 << (attr - 1)); \ |
| 4836 | } \ |
| 4837 | } while (0) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4838 | |
| 4839 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4840 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4841 | return -EINVAL; |
| 4842 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4843 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4844 | nl80211_meshconf_params_policy)) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4845 | return -EINVAL; |
| 4846 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4847 | /* This makes sure that there aren't more than 32 mesh config |
| 4848 | * parameters (otherwise our bitfield scheme would not work.) */ |
| 4849 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); |
| 4850 | |
| 4851 | /* Fill in the params struct */ |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4852 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4853 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 4854 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4855 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4856 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 4857 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4858 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4859 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 4860 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4861 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4862 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 4863 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4864 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4865 | mask, NL80211_MESHCONF_MAX_RETRIES, |
| 4866 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4867 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4868 | mask, NL80211_MESHCONF_TTL, nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4869 | 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] | 4870 | mask, NL80211_MESHCONF_ELEMENT_TTL, |
| 4871 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4872 | 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] | 4873 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 4874 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4875 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, |
| 4876 | 1, 255, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4877 | NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 4878 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4879 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4880 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 4881 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4882 | 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] | 4883 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 4884 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4885 | 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] | 4886 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 4887 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4888 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
| 4889 | 1, 65535, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4890 | NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 4891 | nla_get_u32); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4892 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4893 | 1, 65535, mask, |
| 4894 | NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4895 | nla_get_u16); |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 4896 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4897 | 1, 65535, mask, |
| 4898 | NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4899 | nla_get_u16); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4900 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4901 | dot11MeshHWMPnetDiameterTraversalTime, |
| 4902 | 1, 65535, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4903 | NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 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, dot11MeshHWMPRootMode, 0, 4, |
| 4906 | mask, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 4907 | nla_get_u8); |
| 4908 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535, |
| 4909 | mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4910 | nla_get_u16); |
Rui Paulo | 63c5723 | 2009-11-09 23:46:57 +0000 | [diff] [blame] | 4911 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4912 | dot11MeshGateAnnouncementProtocol, 0, 1, |
| 4913 | mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4914 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4915 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4916 | mask, NL80211_MESHCONF_FORWARDING, |
| 4917 | nla_get_u8); |
Chun-Yeow Yeoh | 83374fe | 2013-07-11 18:24:03 +0800 | [diff] [blame] | 4918 | 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] | 4919 | mask, NL80211_MESHCONF_RSSI_THRESHOLD, |
Chun-Yeow Yeoh | 83374fe | 2013-07-11 18:24:03 +0800 | [diff] [blame] | 4920 | nla_get_s32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4921 | 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] | 4922 | mask, NL80211_MESHCONF_HT_OPMODE, |
| 4923 | nla_get_u16); |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4924 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4925 | 1, 65535, mask, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4926 | NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 4927 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4928 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4929 | mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
| 4930 | nla_get_u16); |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4931 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4932 | dot11MeshHWMPconfirmationInterval, |
| 4933 | 1, 65535, mask, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4934 | NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
| 4935 | nla_get_u16); |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4936 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode, |
| 4937 | NL80211_MESH_POWER_ACTIVE, |
| 4938 | NL80211_MESH_POWER_MAX, |
| 4939 | mask, NL80211_MESHCONF_POWER_MODE, |
| 4940 | nla_get_u32); |
| 4941 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration, |
| 4942 | 0, 65535, mask, |
| 4943 | NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16); |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 4944 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 1, 0xffffffff, |
| 4945 | mask, NL80211_MESHCONF_PLINK_TIMEOUT, |
| 4946 | nla_get_u32); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4947 | if (mask_out) |
| 4948 | *mask_out = mask; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4949 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4950 | return 0; |
| 4951 | |
| 4952 | #undef FILL_IN_MESH_PARAM_IF_SET |
| 4953 | } |
| 4954 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4955 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
| 4956 | struct mesh_setup *setup) |
| 4957 | { |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 4958 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4959 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
| 4960 | |
| 4961 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) |
| 4962 | return -EINVAL; |
| 4963 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, |
| 4964 | info->attrs[NL80211_ATTR_MESH_SETUP], |
| 4965 | nl80211_mesh_setup_params_policy)) |
| 4966 | return -EINVAL; |
| 4967 | |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 4968 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC]) |
| 4969 | setup->sync_method = |
| 4970 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ? |
| 4971 | IEEE80211_SYNC_METHOD_VENDOR : |
| 4972 | IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET; |
| 4973 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4974 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
| 4975 | setup->path_sel_proto = |
| 4976 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? |
| 4977 | IEEE80211_PATH_PROTOCOL_VENDOR : |
| 4978 | IEEE80211_PATH_PROTOCOL_HWMP; |
| 4979 | |
| 4980 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) |
| 4981 | setup->path_metric = |
| 4982 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? |
| 4983 | IEEE80211_PATH_METRIC_VENDOR : |
| 4984 | IEEE80211_PATH_METRIC_AIRTIME; |
| 4985 | |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4986 | |
| 4987 | if (tb[NL80211_MESH_SETUP_IE]) { |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4988 | struct nlattr *ieattr = |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4989 | tb[NL80211_MESH_SETUP_IE]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4990 | if (!is_valid_ie_attr(ieattr)) |
| 4991 | return -EINVAL; |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4992 | setup->ie = nla_data(ieattr); |
| 4993 | setup->ie_len = nla_len(ieattr); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4994 | } |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 4995 | if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] && |
| 4996 | !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM)) |
| 4997 | return -EINVAL; |
| 4998 | setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]); |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 4999 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
| 5000 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 5001 | if (setup->is_secure) |
| 5002 | setup->user_mpm = true; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5003 | |
Colleen Twitty | 6e16d90 | 2013-05-08 11:45:59 -0700 | [diff] [blame] | 5004 | if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) { |
| 5005 | if (!setup->user_mpm) |
| 5006 | return -EINVAL; |
| 5007 | setup->auth_id = |
| 5008 | nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]); |
| 5009 | } |
| 5010 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5011 | return 0; |
| 5012 | } |
| 5013 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5014 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5015 | struct genl_info *info) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5016 | { |
| 5017 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5018 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5019 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5020 | struct mesh_config cfg; |
| 5021 | u32 mask; |
| 5022 | int err; |
| 5023 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5024 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 5025 | return -EOPNOTSUPP; |
| 5026 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5027 | if (!rdev->ops->update_mesh_config) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5028 | return -EOPNOTSUPP; |
| 5029 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5030 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5031 | if (err) |
| 5032 | return err; |
| 5033 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5034 | wdev_lock(wdev); |
| 5035 | if (!wdev->mesh_id_len) |
| 5036 | err = -ENOLINK; |
| 5037 | |
| 5038 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5039 | err = rdev_update_mesh_config(rdev, dev, mask, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5040 | |
| 5041 | wdev_unlock(wdev); |
| 5042 | |
| 5043 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5044 | } |
| 5045 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5046 | static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info) |
| 5047 | { |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5048 | const struct ieee80211_regdomain *regdom; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5049 | struct sk_buff *msg; |
| 5050 | void *hdr = NULL; |
| 5051 | struct nlattr *nl_reg_rules; |
| 5052 | unsigned int i; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5053 | |
| 5054 | if (!cfg80211_regdomain) |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5055 | return -EINVAL; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5056 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 5057 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5058 | if (!msg) |
| 5059 | return -ENOBUFS; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5060 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5061 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5062 | NL80211_CMD_GET_REG); |
| 5063 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 5064 | goto put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5065 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 5066 | if (reg_last_request_cell_base() && |
| 5067 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, |
| 5068 | NL80211_USER_REG_HINT_CELL_BASE)) |
| 5069 | goto nla_put_failure; |
| 5070 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5071 | rcu_read_lock(); |
| 5072 | regdom = rcu_dereference(cfg80211_regdomain); |
| 5073 | |
| 5074 | if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) || |
| 5075 | (regdom->dfs_region && |
| 5076 | nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region))) |
| 5077 | goto nla_put_failure_rcu; |
| 5078 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5079 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
| 5080 | if (!nl_reg_rules) |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5081 | goto nla_put_failure_rcu; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5082 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5083 | for (i = 0; i < regdom->n_reg_rules; i++) { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5084 | struct nlattr *nl_reg_rule; |
| 5085 | const struct ieee80211_reg_rule *reg_rule; |
| 5086 | const struct ieee80211_freq_range *freq_range; |
| 5087 | const struct ieee80211_power_rule *power_rule; |
| 5088 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5089 | reg_rule = ®dom->reg_rules[i]; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5090 | freq_range = ®_rule->freq_range; |
| 5091 | power_rule = ®_rule->power_rule; |
| 5092 | |
| 5093 | nl_reg_rule = nla_nest_start(msg, i); |
| 5094 | if (!nl_reg_rule) |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5095 | goto nla_put_failure_rcu; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5096 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5097 | if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
| 5098 | reg_rule->flags) || |
| 5099 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START, |
| 5100 | freq_range->start_freq_khz) || |
| 5101 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END, |
| 5102 | freq_range->end_freq_khz) || |
| 5103 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, |
| 5104 | freq_range->max_bandwidth_khz) || |
| 5105 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
| 5106 | power_rule->max_antenna_gain) || |
| 5107 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, |
| 5108 | power_rule->max_eirp)) |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5109 | goto nla_put_failure_rcu; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5110 | |
| 5111 | nla_nest_end(msg, nl_reg_rule); |
| 5112 | } |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5113 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5114 | |
| 5115 | nla_nest_end(msg, nl_reg_rules); |
| 5116 | |
| 5117 | genlmsg_end(msg, hdr); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5118 | return genlmsg_reply(msg, info); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5119 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5120 | nla_put_failure_rcu: |
| 5121 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5122 | nla_put_failure: |
| 5123 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 5124 | put_failure: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 5125 | nlmsg_free(msg); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5126 | return -EMSGSIZE; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5127 | } |
| 5128 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5129 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 5130 | { |
| 5131 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; |
| 5132 | struct nlattr *nl_reg_rule; |
| 5133 | char *alpha2 = NULL; |
| 5134 | int rem_reg_rules = 0, r = 0; |
| 5135 | u32 num_rules = 0, rule_idx = 0, size_of_regd; |
Luis R. Rodriguez | 4c7d398 | 2013-11-13 18:54:02 +0100 | [diff] [blame] | 5136 | enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5137 | struct ieee80211_regdomain *rd = NULL; |
| 5138 | |
| 5139 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 5140 | return -EINVAL; |
| 5141 | |
| 5142 | if (!info->attrs[NL80211_ATTR_REG_RULES]) |
| 5143 | return -EINVAL; |
| 5144 | |
| 5145 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 5146 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 5147 | if (info->attrs[NL80211_ATTR_DFS_REGION]) |
| 5148 | dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); |
| 5149 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5150 | 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] | 5151 | rem_reg_rules) { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5152 | num_rules++; |
| 5153 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) |
Luis R. Rodriguez | 4776c6e | 2009-05-13 17:04:39 -0400 | [diff] [blame] | 5154 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5155 | } |
| 5156 | |
Luis R. Rodriguez | e438768 | 2013-11-05 09:18:01 -0800 | [diff] [blame] | 5157 | if (!reg_is_valid_request(alpha2)) |
| 5158 | return -EINVAL; |
| 5159 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5160 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 5161 | num_rules * sizeof(struct ieee80211_reg_rule); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5162 | |
| 5163 | rd = kzalloc(size_of_regd, GFP_KERNEL); |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 5164 | if (!rd) |
| 5165 | return -ENOMEM; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5166 | |
| 5167 | rd->n_reg_rules = num_rules; |
| 5168 | rd->alpha2[0] = alpha2[0]; |
| 5169 | rd->alpha2[1] = alpha2[1]; |
| 5170 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 5171 | /* |
| 5172 | * Disable DFS master mode if the DFS region was |
| 5173 | * not supported or known on this kernel. |
| 5174 | */ |
| 5175 | if (reg_supported_dfs_region(dfs_region)) |
| 5176 | rd->dfs_region = dfs_region; |
| 5177 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5178 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 5179 | rem_reg_rules) { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5180 | nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 5181 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), |
| 5182 | reg_rule_policy); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5183 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
| 5184 | if (r) |
| 5185 | goto bad_reg; |
| 5186 | |
| 5187 | rule_idx++; |
| 5188 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 5189 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
| 5190 | r = -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5191 | goto bad_reg; |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 5192 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5193 | } |
| 5194 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5195 | r = set_regdom(rd); |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 5196 | /* set_regdom took ownership */ |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 5197 | rd = NULL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5198 | |
Johannes Berg | d2372b3 | 2008-10-24 20:32:20 +0200 | [diff] [blame] | 5199 | bad_reg: |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5200 | kfree(rd); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 5201 | return r; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5202 | } |
| 5203 | |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5204 | static int validate_scan_freqs(struct nlattr *freqs) |
| 5205 | { |
| 5206 | struct nlattr *attr1, *attr2; |
| 5207 | int n_channels = 0, tmp1, tmp2; |
| 5208 | |
| 5209 | nla_for_each_nested(attr1, freqs, tmp1) { |
| 5210 | n_channels++; |
| 5211 | /* |
| 5212 | * Some hardware has a limited channel list for |
| 5213 | * scanning, and it is pretty much nonsensical |
| 5214 | * to scan for a channel twice, so disallow that |
| 5215 | * and don't require drivers to check that the |
| 5216 | * channel list they get isn't longer than what |
| 5217 | * they can scan, as long as they can scan all |
| 5218 | * the channels they registered at once. |
| 5219 | */ |
| 5220 | nla_for_each_nested(attr2, freqs, tmp2) |
| 5221 | if (attr1 != attr2 && |
| 5222 | nla_get_u32(attr1) == nla_get_u32(attr2)) |
| 5223 | return 0; |
| 5224 | } |
| 5225 | |
| 5226 | return n_channels; |
| 5227 | } |
| 5228 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5229 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
| 5230 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5231 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 5232 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5233 | struct cfg80211_scan_request *request; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5234 | struct nlattr *attr; |
| 5235 | struct wiphy *wiphy; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5236 | int err, tmp, n_ssids = 0, n_channels, i; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5237 | size_t ie_len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5238 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5239 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5240 | return -EINVAL; |
| 5241 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5242 | wiphy = &rdev->wiphy; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5243 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5244 | if (!rdev->ops->scan) |
| 5245 | return -EOPNOTSUPP; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5246 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5247 | if (rdev->scan_req) { |
| 5248 | err = -EBUSY; |
| 5249 | goto unlock; |
| 5250 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5251 | |
| 5252 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5253 | n_channels = validate_scan_freqs( |
| 5254 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5255 | if (!n_channels) { |
| 5256 | err = -EINVAL; |
| 5257 | goto unlock; |
| 5258 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5259 | } else { |
Ilan Peer | bdfbec2 | 2014-01-09 11:37:23 +0200 | [diff] [blame] | 5260 | n_channels = ieee80211_get_num_supported_channels(wiphy); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5261 | } |
| 5262 | |
| 5263 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 5264 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) |
| 5265 | n_ssids++; |
| 5266 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5267 | if (n_ssids > wiphy->max_scan_ssids) { |
| 5268 | err = -EINVAL; |
| 5269 | goto unlock; |
| 5270 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5271 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5272 | if (info->attrs[NL80211_ATTR_IE]) |
| 5273 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5274 | else |
| 5275 | ie_len = 0; |
| 5276 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5277 | if (ie_len > wiphy->max_scan_ie_len) { |
| 5278 | err = -EINVAL; |
| 5279 | goto unlock; |
| 5280 | } |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 5281 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5282 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 5283 | + sizeof(*request->ssids) * n_ssids |
| 5284 | + sizeof(*request->channels) * n_channels |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5285 | + ie_len, GFP_KERNEL); |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5286 | if (!request) { |
| 5287 | err = -ENOMEM; |
| 5288 | goto unlock; |
| 5289 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5290 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5291 | if (n_ssids) |
Johannes Berg | 5ba6353 | 2009-08-07 17:54:07 +0200 | [diff] [blame] | 5292 | request->ssids = (void *)&request->channels[n_channels]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5293 | request->n_ssids = n_ssids; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5294 | if (ie_len) { |
| 5295 | if (request->ssids) |
| 5296 | request->ie = (void *)(request->ssids + n_ssids); |
| 5297 | else |
| 5298 | request->ie = (void *)(request->channels + n_channels); |
| 5299 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5300 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5301 | i = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5302 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 5303 | /* user specified, bail out if channel not found */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5304 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5305 | struct ieee80211_channel *chan; |
| 5306 | |
| 5307 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 5308 | |
| 5309 | if (!chan) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5310 | err = -EINVAL; |
| 5311 | goto out_free; |
| 5312 | } |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5313 | |
| 5314 | /* ignore disabled channels */ |
| 5315 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5316 | continue; |
| 5317 | |
| 5318 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5319 | i++; |
| 5320 | } |
| 5321 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5322 | enum ieee80211_band band; |
| 5323 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5324 | /* all channels */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5325 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 5326 | int j; |
| 5327 | if (!wiphy->bands[band]) |
| 5328 | continue; |
| 5329 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5330 | struct ieee80211_channel *chan; |
| 5331 | |
| 5332 | chan = &wiphy->bands[band]->channels[j]; |
| 5333 | |
| 5334 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5335 | continue; |
| 5336 | |
| 5337 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5338 | i++; |
| 5339 | } |
| 5340 | } |
| 5341 | } |
| 5342 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5343 | if (!i) { |
| 5344 | err = -EINVAL; |
| 5345 | goto out_free; |
| 5346 | } |
| 5347 | |
| 5348 | request->n_channels = i; |
| 5349 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5350 | i = 0; |
| 5351 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 5352 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5353 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5354 | err = -EINVAL; |
| 5355 | goto out_free; |
| 5356 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5357 | request->ssids[i].ssid_len = nla_len(attr); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5358 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5359 | i++; |
| 5360 | } |
| 5361 | } |
| 5362 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5363 | if (info->attrs[NL80211_ATTR_IE]) { |
| 5364 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Johannes Berg | de95a54 | 2009-04-01 11:58:36 +0200 | [diff] [blame] | 5365 | memcpy((void *)request->ie, |
| 5366 | nla_data(info->attrs[NL80211_ATTR_IE]), |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5367 | request->ie_len); |
| 5368 | } |
| 5369 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5370 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) |
Johannes Berg | a401d2b | 2011-07-20 00:52:16 +0200 | [diff] [blame] | 5371 | if (wiphy->bands[i]) |
| 5372 | request->rates[i] = |
| 5373 | (1 << wiphy->bands[i]->n_bitrates) - 1; |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5374 | |
| 5375 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { |
| 5376 | nla_for_each_nested(attr, |
| 5377 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], |
| 5378 | tmp) { |
| 5379 | enum ieee80211_band band = nla_type(attr); |
| 5380 | |
Dan Carpenter | 8440462 | 2011-07-29 11:52:18 +0300 | [diff] [blame] | 5381 | if (band < 0 || band >= IEEE80211_NUM_BANDS) { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5382 | err = -EINVAL; |
| 5383 | goto out_free; |
| 5384 | } |
Felix Fietkau | 1b09cd8 | 2013-11-20 19:40:41 +0100 | [diff] [blame] | 5385 | |
| 5386 | if (!wiphy->bands[band]) |
| 5387 | continue; |
| 5388 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5389 | err = ieee80211_get_ratemask(wiphy->bands[band], |
| 5390 | nla_data(attr), |
| 5391 | nla_len(attr), |
| 5392 | &request->rates[band]); |
| 5393 | if (err) |
| 5394 | goto out_free; |
| 5395 | } |
| 5396 | } |
| 5397 | |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5398 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5399 | request->flags = nla_get_u32( |
| 5400 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); |
Johannes Berg | 00c3a6e | 2013-10-26 17:14:38 +0200 | [diff] [blame] | 5401 | if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 5402 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) { |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5403 | err = -EOPNOTSUPP; |
| 5404 | goto out_free; |
| 5405 | } |
| 5406 | } |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5407 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 5408 | request->no_cck = |
| 5409 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 5410 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 5411 | request->wdev = wdev; |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5412 | request->wiphy = &rdev->wiphy; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 5413 | request->scan_start = jiffies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5414 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5415 | rdev->scan_req = request; |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5416 | err = rdev_scan(rdev, request); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5417 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5418 | if (!err) { |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 5419 | nl80211_send_scan_start(rdev, wdev); |
| 5420 | if (wdev->netdev) |
| 5421 | dev_hold(wdev->netdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5422 | } else { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5423 | out_free: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5424 | rdev->scan_req = NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5425 | kfree(request); |
| 5426 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 5427 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5428 | unlock: |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5429 | return err; |
| 5430 | } |
| 5431 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5432 | static int nl80211_start_sched_scan(struct sk_buff *skb, |
| 5433 | struct genl_info *info) |
| 5434 | { |
| 5435 | struct cfg80211_sched_scan_request *request; |
| 5436 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5437 | struct net_device *dev = info->user_ptr[1]; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5438 | struct nlattr *attr; |
| 5439 | struct wiphy *wiphy; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5440 | 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] | 5441 | u32 interval; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5442 | enum ieee80211_band band; |
| 5443 | size_t ie_len; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5444 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5445 | |
| 5446 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 5447 | !rdev->ops->sched_scan_start) |
| 5448 | return -EOPNOTSUPP; |
| 5449 | |
| 5450 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5451 | return -EINVAL; |
| 5452 | |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 5453 | if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
| 5454 | return -EINVAL; |
| 5455 | |
| 5456 | interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); |
| 5457 | if (interval == 0) |
| 5458 | return -EINVAL; |
| 5459 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5460 | wiphy = &rdev->wiphy; |
| 5461 | |
| 5462 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 5463 | n_channels = validate_scan_freqs( |
| 5464 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
| 5465 | if (!n_channels) |
| 5466 | return -EINVAL; |
| 5467 | } else { |
Ilan Peer | bdfbec2 | 2014-01-09 11:37:23 +0200 | [diff] [blame] | 5468 | n_channels = ieee80211_get_num_supported_channels(wiphy); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5469 | } |
| 5470 | |
| 5471 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 5472 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 5473 | tmp) |
| 5474 | n_ssids++; |
| 5475 | |
Luciano Coelho | 93b6aa6 | 2011-07-13 14:57:28 +0300 | [diff] [blame] | 5476 | if (n_ssids > wiphy->max_sched_scan_ssids) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5477 | return -EINVAL; |
| 5478 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5479 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) |
| 5480 | nla_for_each_nested(attr, |
| 5481 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
| 5482 | tmp) |
| 5483 | n_match_sets++; |
| 5484 | |
| 5485 | if (n_match_sets > wiphy->max_match_sets) |
| 5486 | return -EINVAL; |
| 5487 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5488 | if (info->attrs[NL80211_ATTR_IE]) |
| 5489 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5490 | else |
| 5491 | ie_len = 0; |
| 5492 | |
Luciano Coelho | 5a865ba | 2011-07-13 14:57:29 +0300 | [diff] [blame] | 5493 | if (ie_len > wiphy->max_sched_scan_ie_len) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5494 | return -EINVAL; |
| 5495 | |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 5496 | if (rdev->sched_scan_req) { |
| 5497 | err = -EINPROGRESS; |
| 5498 | goto out; |
| 5499 | } |
| 5500 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5501 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 5502 | + sizeof(*request->ssids) * n_ssids |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5503 | + sizeof(*request->match_sets) * n_match_sets |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 5504 | + sizeof(*request->channels) * n_channels |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5505 | + ie_len, GFP_KERNEL); |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 5506 | if (!request) { |
| 5507 | err = -ENOMEM; |
| 5508 | goto out; |
| 5509 | } |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5510 | |
| 5511 | if (n_ssids) |
| 5512 | request->ssids = (void *)&request->channels[n_channels]; |
| 5513 | request->n_ssids = n_ssids; |
| 5514 | if (ie_len) { |
| 5515 | if (request->ssids) |
| 5516 | request->ie = (void *)(request->ssids + n_ssids); |
| 5517 | else |
| 5518 | request->ie = (void *)(request->channels + n_channels); |
| 5519 | } |
| 5520 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5521 | if (n_match_sets) { |
| 5522 | if (request->ie) |
| 5523 | request->match_sets = (void *)(request->ie + ie_len); |
| 5524 | else if (request->ssids) |
| 5525 | request->match_sets = |
| 5526 | (void *)(request->ssids + n_ssids); |
| 5527 | else |
| 5528 | request->match_sets = |
| 5529 | (void *)(request->channels + n_channels); |
| 5530 | } |
| 5531 | request->n_match_sets = n_match_sets; |
| 5532 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5533 | i = 0; |
| 5534 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 5535 | /* user specified, bail out if channel not found */ |
| 5536 | nla_for_each_nested(attr, |
| 5537 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], |
| 5538 | tmp) { |
| 5539 | struct ieee80211_channel *chan; |
| 5540 | |
| 5541 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 5542 | |
| 5543 | if (!chan) { |
| 5544 | err = -EINVAL; |
| 5545 | goto out_free; |
| 5546 | } |
| 5547 | |
| 5548 | /* ignore disabled channels */ |
| 5549 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5550 | continue; |
| 5551 | |
| 5552 | request->channels[i] = chan; |
| 5553 | i++; |
| 5554 | } |
| 5555 | } else { |
| 5556 | /* all channels */ |
| 5557 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 5558 | int j; |
| 5559 | if (!wiphy->bands[band]) |
| 5560 | continue; |
| 5561 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
| 5562 | struct ieee80211_channel *chan; |
| 5563 | |
| 5564 | chan = &wiphy->bands[band]->channels[j]; |
| 5565 | |
| 5566 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5567 | continue; |
| 5568 | |
| 5569 | request->channels[i] = chan; |
| 5570 | i++; |
| 5571 | } |
| 5572 | } |
| 5573 | } |
| 5574 | |
| 5575 | if (!i) { |
| 5576 | err = -EINVAL; |
| 5577 | goto out_free; |
| 5578 | } |
| 5579 | |
| 5580 | request->n_channels = i; |
| 5581 | |
| 5582 | i = 0; |
| 5583 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 5584 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 5585 | tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5586 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5587 | err = -EINVAL; |
| 5588 | goto out_free; |
| 5589 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5590 | request->ssids[i].ssid_len = nla_len(attr); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5591 | memcpy(request->ssids[i].ssid, nla_data(attr), |
| 5592 | nla_len(attr)); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5593 | i++; |
| 5594 | } |
| 5595 | } |
| 5596 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5597 | i = 0; |
| 5598 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
| 5599 | nla_for_each_nested(attr, |
| 5600 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
| 5601 | tmp) { |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 5602 | struct nlattr *ssid, *rssi; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5603 | |
| 5604 | nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
| 5605 | nla_data(attr), nla_len(attr), |
| 5606 | nl80211_match_policy); |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 5607 | ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5608 | if (ssid) { |
| 5609 | if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) { |
| 5610 | err = -EINVAL; |
| 5611 | goto out_free; |
| 5612 | } |
| 5613 | memcpy(request->match_sets[i].ssid.ssid, |
| 5614 | nla_data(ssid), nla_len(ssid)); |
| 5615 | request->match_sets[i].ssid.ssid_len = |
| 5616 | nla_len(ssid); |
| 5617 | } |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 5618 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; |
| 5619 | if (rssi) |
| 5620 | request->rssi_thold = nla_get_u32(rssi); |
| 5621 | else |
| 5622 | request->rssi_thold = |
| 5623 | NL80211_SCAN_RSSI_THOLD_OFF; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5624 | i++; |
| 5625 | } |
| 5626 | } |
| 5627 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5628 | if (info->attrs[NL80211_ATTR_IE]) { |
| 5629 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5630 | memcpy((void *)request->ie, |
| 5631 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 5632 | request->ie_len); |
| 5633 | } |
| 5634 | |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5635 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5636 | request->flags = nla_get_u32( |
| 5637 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); |
Johannes Berg | 00c3a6e | 2013-10-26 17:14:38 +0200 | [diff] [blame] | 5638 | if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 5639 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) { |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5640 | err = -EOPNOTSUPP; |
| 5641 | goto out_free; |
| 5642 | } |
| 5643 | } |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5644 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5645 | request->dev = dev; |
| 5646 | request->wiphy = &rdev->wiphy; |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 5647 | request->interval = interval; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 5648 | request->scan_start = jiffies; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5649 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5650 | err = rdev_sched_scan_start(rdev, dev, request); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5651 | if (!err) { |
| 5652 | rdev->sched_scan_req = request; |
| 5653 | nl80211_send_sched_scan(rdev, dev, |
| 5654 | NL80211_CMD_START_SCHED_SCAN); |
| 5655 | goto out; |
| 5656 | } |
| 5657 | |
| 5658 | out_free: |
| 5659 | kfree(request); |
| 5660 | out: |
| 5661 | return err; |
| 5662 | } |
| 5663 | |
| 5664 | static int nl80211_stop_sched_scan(struct sk_buff *skb, |
| 5665 | struct genl_info *info) |
| 5666 | { |
| 5667 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5668 | |
| 5669 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 5670 | !rdev->ops->sched_scan_stop) |
| 5671 | return -EOPNOTSUPP; |
| 5672 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5673 | return __cfg80211_stop_sched_scan(rdev, false); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5674 | } |
| 5675 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5676 | static int nl80211_start_radar_detection(struct sk_buff *skb, |
| 5677 | struct genl_info *info) |
| 5678 | { |
| 5679 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5680 | struct net_device *dev = info->user_ptr[1]; |
| 5681 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 5682 | struct cfg80211_chan_def chandef; |
Luis R. Rodriguez | 55f7435 | 2013-11-25 20:56:10 +0100 | [diff] [blame] | 5683 | enum nl80211_dfs_regions dfs_region; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5684 | int err; |
| 5685 | |
Luis R. Rodriguez | 55f7435 | 2013-11-25 20:56:10 +0100 | [diff] [blame] | 5686 | dfs_region = reg_get_dfs_region(wdev->wiphy); |
| 5687 | if (dfs_region == NL80211_DFS_UNSET) |
| 5688 | return -EINVAL; |
| 5689 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5690 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 5691 | if (err) |
| 5692 | return err; |
| 5693 | |
Simon Wunderlich | ff311bc | 2013-09-03 19:43:18 +0200 | [diff] [blame] | 5694 | if (netif_carrier_ok(dev)) |
| 5695 | return -EBUSY; |
| 5696 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5697 | if (wdev->cac_started) |
| 5698 | return -EBUSY; |
| 5699 | |
| 5700 | err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef); |
| 5701 | if (err < 0) |
| 5702 | return err; |
| 5703 | |
| 5704 | if (err == 0) |
| 5705 | return -EINVAL; |
| 5706 | |
Janusz Dziedzic | fe7c3a1 | 2013-11-05 14:48:48 +0100 | [diff] [blame] | 5707 | if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef)) |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5708 | return -EINVAL; |
| 5709 | |
| 5710 | if (!rdev->ops->start_radar_detection) |
| 5711 | return -EOPNOTSUPP; |
| 5712 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5713 | err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype, |
| 5714 | chandef.chan, CHAN_MODE_SHARED, |
| 5715 | BIT(chandef.width)); |
| 5716 | if (err) |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5717 | return err; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5718 | |
| 5719 | err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef); |
| 5720 | if (!err) { |
| 5721 | wdev->channel = chandef.chan; |
| 5722 | wdev->cac_started = true; |
| 5723 | wdev->cac_start_time = jiffies; |
| 5724 | } |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5725 | return err; |
| 5726 | } |
| 5727 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5728 | static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info) |
| 5729 | { |
| 5730 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5731 | struct net_device *dev = info->user_ptr[1]; |
| 5732 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 5733 | struct cfg80211_csa_settings params; |
| 5734 | /* csa_attrs is defined static to avoid waste of stack size - this |
| 5735 | * function is called under RTNL lock, so this should not be a problem. |
| 5736 | */ |
| 5737 | static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1]; |
| 5738 | u8 radar_detect_width = 0; |
| 5739 | int err; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5740 | bool need_new_beacon = false; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5741 | |
| 5742 | if (!rdev->ops->channel_switch || |
| 5743 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)) |
| 5744 | return -EOPNOTSUPP; |
| 5745 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5746 | switch (dev->ieee80211_ptr->iftype) { |
| 5747 | case NL80211_IFTYPE_AP: |
| 5748 | case NL80211_IFTYPE_P2P_GO: |
| 5749 | need_new_beacon = true; |
| 5750 | |
| 5751 | /* useless if AP is not running */ |
| 5752 | if (!wdev->beacon_interval) |
| 5753 | return -EINVAL; |
| 5754 | break; |
| 5755 | case NL80211_IFTYPE_ADHOC: |
Chun-Yeow Yeoh | c6da674 | 2013-10-14 19:08:28 -0700 | [diff] [blame] | 5756 | case NL80211_IFTYPE_MESH_POINT: |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5757 | break; |
| 5758 | default: |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5759 | return -EOPNOTSUPP; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5760 | } |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5761 | |
| 5762 | memset(¶ms, 0, sizeof(params)); |
| 5763 | |
| 5764 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 5765 | !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]) |
| 5766 | return -EINVAL; |
| 5767 | |
| 5768 | /* only important for AP, IBSS and mesh create IEs internally */ |
Andrei Otcheretianski | d0a361a | 2013-10-17 10:52:17 +0200 | [diff] [blame] | 5769 | if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES]) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5770 | return -EINVAL; |
| 5771 | |
| 5772 | params.count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]); |
| 5773 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5774 | if (!need_new_beacon) |
| 5775 | goto skip_beacons; |
| 5776 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5777 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon_after); |
| 5778 | if (err) |
| 5779 | return err; |
| 5780 | |
| 5781 | err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX, |
| 5782 | info->attrs[NL80211_ATTR_CSA_IES], |
| 5783 | nl80211_policy); |
| 5784 | if (err) |
| 5785 | return err; |
| 5786 | |
| 5787 | err = nl80211_parse_beacon(csa_attrs, ¶ms.beacon_csa); |
| 5788 | if (err) |
| 5789 | return err; |
| 5790 | |
| 5791 | if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]) |
| 5792 | return -EINVAL; |
| 5793 | |
| 5794 | params.counter_offset_beacon = |
| 5795 | nla_get_u16(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); |
| 5796 | if (params.counter_offset_beacon >= params.beacon_csa.tail_len) |
| 5797 | return -EINVAL; |
| 5798 | |
| 5799 | /* sanity check - counters should be the same */ |
| 5800 | if (params.beacon_csa.tail[params.counter_offset_beacon] != |
| 5801 | params.count) |
| 5802 | return -EINVAL; |
| 5803 | |
| 5804 | if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) { |
| 5805 | params.counter_offset_presp = |
| 5806 | nla_get_u16(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); |
| 5807 | if (params.counter_offset_presp >= |
| 5808 | params.beacon_csa.probe_resp_len) |
| 5809 | return -EINVAL; |
| 5810 | |
| 5811 | if (params.beacon_csa.probe_resp[params.counter_offset_presp] != |
| 5812 | params.count) |
| 5813 | return -EINVAL; |
| 5814 | } |
| 5815 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5816 | skip_beacons: |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5817 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
| 5818 | if (err) |
| 5819 | return err; |
| 5820 | |
| 5821 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, ¶ms.chandef)) |
| 5822 | return -EINVAL; |
| 5823 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5824 | if (dev->ieee80211_ptr->iftype == NL80211_IFTYPE_AP || |
Simon Wunderlich | 5336fa8 | 2013-10-07 18:41:05 +0200 | [diff] [blame] | 5825 | dev->ieee80211_ptr->iftype == NL80211_IFTYPE_P2P_GO || |
| 5826 | dev->ieee80211_ptr->iftype == NL80211_IFTYPE_ADHOC) { |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5827 | err = cfg80211_chandef_dfs_required(wdev->wiphy, |
| 5828 | ¶ms.chandef); |
| 5829 | if (err < 0) { |
| 5830 | return err; |
| 5831 | } else if (err) { |
| 5832 | radar_detect_width = BIT(params.chandef.width); |
| 5833 | params.radar_required = true; |
| 5834 | } |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5835 | } |
| 5836 | |
| 5837 | err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype, |
| 5838 | params.chandef.chan, |
| 5839 | CHAN_MODE_SHARED, |
| 5840 | radar_detect_width); |
| 5841 | if (err) |
| 5842 | return err; |
| 5843 | |
| 5844 | if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX]) |
| 5845 | params.block_tx = true; |
| 5846 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 5847 | wdev_lock(wdev); |
| 5848 | err = rdev_channel_switch(rdev, dev, ¶ms); |
| 5849 | wdev_unlock(wdev); |
| 5850 | |
| 5851 | return err; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5852 | } |
| 5853 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 5854 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
| 5855 | u32 seq, int flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5856 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5857 | struct wireless_dev *wdev, |
| 5858 | struct cfg80211_internal_bss *intbss) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5859 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5860 | struct cfg80211_bss *res = &intbss->pub; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5861 | const struct cfg80211_bss_ies *ies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5862 | void *hdr; |
| 5863 | struct nlattr *bss; |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5864 | bool tsf = false; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5865 | |
| 5866 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5867 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5868 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5869 | NL80211_CMD_NEW_SCAN_RESULTS); |
| 5870 | if (!hdr) |
| 5871 | return -1; |
| 5872 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 5873 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
| 5874 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5875 | if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation)) |
| 5876 | goto nla_put_failure; |
| 5877 | if (wdev->netdev && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5878 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex)) |
| 5879 | goto nla_put_failure; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5880 | if (nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 5881 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5882 | |
| 5883 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); |
| 5884 | if (!bss) |
| 5885 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5886 | if ((!is_zero_ether_addr(res->bssid) && |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5887 | nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5888 | goto nla_put_failure; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5889 | |
| 5890 | rcu_read_lock(); |
| 5891 | ies = rcu_dereference(res->ies); |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5892 | if (ies) { |
| 5893 | if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf)) |
| 5894 | goto fail_unlock_rcu; |
| 5895 | tsf = true; |
| 5896 | if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS, |
| 5897 | ies->len, ies->data)) |
| 5898 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5899 | } |
| 5900 | ies = rcu_dereference(res->beacon_ies); |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5901 | if (ies) { |
| 5902 | if (!tsf && nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf)) |
| 5903 | goto fail_unlock_rcu; |
| 5904 | if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES, |
| 5905 | ies->len, ies->data)) |
| 5906 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5907 | } |
| 5908 | rcu_read_unlock(); |
| 5909 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5910 | if (res->beacon_interval && |
| 5911 | nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval)) |
| 5912 | goto nla_put_failure; |
| 5913 | if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) || |
| 5914 | nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) || |
Simon Wunderlich | dcd6eac | 2013-07-08 16:55:49 +0200 | [diff] [blame] | 5915 | nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5916 | nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO, |
| 5917 | jiffies_to_msecs(jiffies - intbss->ts))) |
| 5918 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5919 | |
Johannes Berg | 77965c9 | 2009-02-18 18:45:06 +0100 | [diff] [blame] | 5920 | switch (rdev->wiphy.signal_type) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5921 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5922 | if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal)) |
| 5923 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5924 | break; |
| 5925 | case CFG80211_SIGNAL_TYPE_UNSPEC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5926 | if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal)) |
| 5927 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5928 | break; |
| 5929 | default: |
| 5930 | break; |
| 5931 | } |
| 5932 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5933 | switch (wdev->iftype) { |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5934 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5935 | case NL80211_IFTYPE_STATION: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5936 | if (intbss == wdev->current_bss && |
| 5937 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 5938 | NL80211_BSS_STATUS_ASSOCIATED)) |
| 5939 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5940 | break; |
| 5941 | case NL80211_IFTYPE_ADHOC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5942 | if (intbss == wdev->current_bss && |
| 5943 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 5944 | NL80211_BSS_STATUS_IBSS_JOINED)) |
| 5945 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5946 | break; |
| 5947 | default: |
| 5948 | break; |
| 5949 | } |
| 5950 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5951 | nla_nest_end(msg, bss); |
| 5952 | |
| 5953 | return genlmsg_end(msg, hdr); |
| 5954 | |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5955 | fail_unlock_rcu: |
| 5956 | rcu_read_unlock(); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5957 | nla_put_failure: |
| 5958 | genlmsg_cancel(msg, hdr); |
| 5959 | return -EMSGSIZE; |
| 5960 | } |
| 5961 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5962 | 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] | 5963 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5964 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5965 | struct cfg80211_internal_bss *scan; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5966 | struct wireless_dev *wdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5967 | int start = cb->args[2], idx = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5968 | int err; |
| 5969 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5970 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5971 | if (err) |
| 5972 | return err; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5973 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5974 | wdev_lock(wdev); |
| 5975 | spin_lock_bh(&rdev->bss_lock); |
| 5976 | cfg80211_bss_expire(rdev); |
| 5977 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 5978 | cb->seq = rdev->bss_generation; |
| 5979 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5980 | list_for_each_entry(scan, &rdev->bss_list, list) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5981 | if (++idx <= start) |
| 5982 | continue; |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 5983 | if (nl80211_send_bss(skb, cb, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5984 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5985 | rdev, wdev, scan) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5986 | idx--; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5987 | break; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5988 | } |
| 5989 | } |
| 5990 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5991 | spin_unlock_bh(&rdev->bss_lock); |
| 5992 | wdev_unlock(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5993 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5994 | cb->args[2] = idx; |
| 5995 | nl80211_finish_wdev_dump(rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5996 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5997 | return skb->len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5998 | } |
| 5999 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6000 | 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] | 6001 | int flags, struct net_device *dev, |
| 6002 | struct survey_info *survey) |
| 6003 | { |
| 6004 | void *hdr; |
| 6005 | struct nlattr *infoattr; |
| 6006 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6007 | hdr = nl80211hdr_put(msg, portid, seq, flags, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6008 | NL80211_CMD_NEW_SURVEY_RESULTS); |
| 6009 | if (!hdr) |
| 6010 | return -ENOMEM; |
| 6011 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6012 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
| 6013 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6014 | |
| 6015 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); |
| 6016 | if (!infoattr) |
| 6017 | goto nla_put_failure; |
| 6018 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6019 | if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY, |
| 6020 | survey->channel->center_freq)) |
| 6021 | goto nla_put_failure; |
| 6022 | |
| 6023 | if ((survey->filled & SURVEY_INFO_NOISE_DBM) && |
| 6024 | nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise)) |
| 6025 | goto nla_put_failure; |
| 6026 | if ((survey->filled & SURVEY_INFO_IN_USE) && |
| 6027 | nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE)) |
| 6028 | goto nla_put_failure; |
| 6029 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) && |
| 6030 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME, |
| 6031 | survey->channel_time)) |
| 6032 | goto nla_put_failure; |
| 6033 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) && |
| 6034 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY, |
| 6035 | survey->channel_time_busy)) |
| 6036 | goto nla_put_failure; |
| 6037 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) && |
| 6038 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY, |
| 6039 | survey->channel_time_ext_busy)) |
| 6040 | goto nla_put_failure; |
| 6041 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) && |
| 6042 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX, |
| 6043 | survey->channel_time_rx)) |
| 6044 | goto nla_put_failure; |
| 6045 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) && |
| 6046 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX, |
| 6047 | survey->channel_time_tx)) |
| 6048 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6049 | |
| 6050 | nla_nest_end(msg, infoattr); |
| 6051 | |
| 6052 | return genlmsg_end(msg, hdr); |
| 6053 | |
| 6054 | nla_put_failure: |
| 6055 | genlmsg_cancel(msg, hdr); |
| 6056 | return -EMSGSIZE; |
| 6057 | } |
| 6058 | |
| 6059 | static int nl80211_dump_survey(struct sk_buff *skb, |
| 6060 | struct netlink_callback *cb) |
| 6061 | { |
| 6062 | struct survey_info survey; |
| 6063 | struct cfg80211_registered_device *dev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6064 | struct wireless_dev *wdev; |
| 6065 | int survey_idx = cb->args[2]; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6066 | int res; |
| 6067 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6068 | res = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 6069 | if (res) |
| 6070 | return res; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6071 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6072 | if (!wdev->netdev) { |
| 6073 | res = -EINVAL; |
| 6074 | goto out_err; |
| 6075 | } |
| 6076 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6077 | if (!dev->ops->dump_survey) { |
| 6078 | res = -EOPNOTSUPP; |
| 6079 | goto out_err; |
| 6080 | } |
| 6081 | |
| 6082 | while (1) { |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 6083 | struct ieee80211_channel *chan; |
| 6084 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6085 | res = rdev_dump_survey(dev, wdev->netdev, survey_idx, &survey); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6086 | if (res == -ENOENT) |
| 6087 | break; |
| 6088 | if (res) |
| 6089 | goto out_err; |
| 6090 | |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 6091 | /* Survey without a channel doesn't make sense */ |
| 6092 | if (!survey.channel) { |
| 6093 | res = -EINVAL; |
| 6094 | goto out; |
| 6095 | } |
| 6096 | |
| 6097 | chan = ieee80211_get_channel(&dev->wiphy, |
| 6098 | survey.channel->center_freq); |
| 6099 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) { |
| 6100 | survey_idx++; |
| 6101 | continue; |
| 6102 | } |
| 6103 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6104 | if (nl80211_send_survey(skb, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6105 | NETLINK_CB(cb->skb).portid, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6106 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6107 | wdev->netdev, &survey) < 0) |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6108 | goto out; |
| 6109 | survey_idx++; |
| 6110 | } |
| 6111 | |
| 6112 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6113 | cb->args[2] = survey_idx; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6114 | res = skb->len; |
| 6115 | out_err: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6116 | nl80211_finish_wdev_dump(dev); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6117 | return res; |
| 6118 | } |
| 6119 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6120 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
| 6121 | { |
| 6122 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | |
| 6123 | NL80211_WPA_VERSION_2)); |
| 6124 | } |
| 6125 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6126 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
| 6127 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6128 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6129 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6130 | struct ieee80211_channel *chan; |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 6131 | const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL; |
| 6132 | int err, ssid_len, ie_len = 0, sae_data_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6133 | enum nl80211_auth_type auth_type; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6134 | struct key_parse key; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6135 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6136 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6137 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6138 | return -EINVAL; |
| 6139 | |
| 6140 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6141 | return -EINVAL; |
| 6142 | |
Jouni Malinen | 1778092 | 2009-03-27 20:52:47 +0200 | [diff] [blame] | 6143 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
| 6144 | return -EINVAL; |
| 6145 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6146 | if (!info->attrs[NL80211_ATTR_SSID]) |
| 6147 | return -EINVAL; |
| 6148 | |
| 6149 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 6150 | return -EINVAL; |
| 6151 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6152 | err = nl80211_parse_key(info, &key); |
| 6153 | if (err) |
| 6154 | return err; |
| 6155 | |
| 6156 | if (key.idx >= 0) { |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 6157 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
| 6158 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6159 | if (!key.p.key || !key.p.key_len) |
| 6160 | return -EINVAL; |
| 6161 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || |
| 6162 | key.p.key_len != WLAN_KEY_LEN_WEP40) && |
| 6163 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || |
| 6164 | key.p.key_len != WLAN_KEY_LEN_WEP104)) |
| 6165 | return -EINVAL; |
| 6166 | if (key.idx > 4) |
| 6167 | return -EINVAL; |
| 6168 | } else { |
| 6169 | key.p.key_len = 0; |
| 6170 | key.p.key = NULL; |
| 6171 | } |
| 6172 | |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 6173 | if (key.idx >= 0) { |
| 6174 | int i; |
| 6175 | bool ok = false; |
| 6176 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { |
| 6177 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { |
| 6178 | ok = true; |
| 6179 | break; |
| 6180 | } |
| 6181 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6182 | if (!ok) |
| 6183 | return -EINVAL; |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 6184 | } |
| 6185 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6186 | if (!rdev->ops->auth) |
| 6187 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6188 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6189 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6190 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6191 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6192 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6193 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 6194 | chan = ieee80211_get_channel(&rdev->wiphy, |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6195 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6196 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
| 6197 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6198 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6199 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 6200 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 6201 | |
| 6202 | if (info->attrs[NL80211_ATTR_IE]) { |
| 6203 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6204 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 6205 | } |
| 6206 | |
| 6207 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 6208 | if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6209 | return -EINVAL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6210 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 6211 | if (auth_type == NL80211_AUTHTYPE_SAE && |
| 6212 | !info->attrs[NL80211_ATTR_SAE_DATA]) |
| 6213 | return -EINVAL; |
| 6214 | |
| 6215 | if (info->attrs[NL80211_ATTR_SAE_DATA]) { |
| 6216 | if (auth_type != NL80211_AUTHTYPE_SAE) |
| 6217 | return -EINVAL; |
| 6218 | sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]); |
| 6219 | sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]); |
| 6220 | /* need to include at least Auth Transaction and Status Code */ |
| 6221 | if (sae_data_len < 4) |
| 6222 | return -EINVAL; |
| 6223 | } |
| 6224 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6225 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 6226 | |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 6227 | /* |
| 6228 | * Since we no longer track auth state, ignore |
| 6229 | * requests to only change local state. |
| 6230 | */ |
| 6231 | if (local_state_change) |
| 6232 | return 0; |
| 6233 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6234 | wdev_lock(dev->ieee80211_ptr); |
| 6235 | err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, |
| 6236 | ssid, ssid_len, ie, ie_len, |
| 6237 | key.p.key, key.p.key_len, key.idx, |
| 6238 | sae_data, sae_data_len); |
| 6239 | wdev_unlock(dev->ieee80211_ptr); |
| 6240 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6241 | } |
| 6242 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 6243 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 6244 | struct genl_info *info, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 6245 | struct cfg80211_crypto_settings *settings, |
| 6246 | int cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6247 | { |
Johannes Berg | c0b2bbd | 2009-07-25 16:54:36 +0200 | [diff] [blame] | 6248 | memset(settings, 0, sizeof(*settings)); |
| 6249 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6250 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
| 6251 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 6252 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
| 6253 | u16 proto; |
| 6254 | proto = nla_get_u16( |
| 6255 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); |
| 6256 | settings->control_port_ethertype = cpu_to_be16(proto); |
| 6257 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 6258 | proto != ETH_P_PAE) |
| 6259 | return -EINVAL; |
| 6260 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) |
| 6261 | settings->control_port_no_encrypt = true; |
| 6262 | } else |
| 6263 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); |
| 6264 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6265 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
| 6266 | void *data; |
| 6267 | int len, i; |
| 6268 | |
| 6269 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 6270 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 6271 | settings->n_ciphers_pairwise = len / sizeof(u32); |
| 6272 | |
| 6273 | if (len % sizeof(u32)) |
| 6274 | return -EINVAL; |
| 6275 | |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 6276 | if (settings->n_ciphers_pairwise > cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6277 | return -EINVAL; |
| 6278 | |
| 6279 | memcpy(settings->ciphers_pairwise, data, len); |
| 6280 | |
| 6281 | for (i = 0; i < settings->n_ciphers_pairwise; i++) |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 6282 | if (!cfg80211_supported_cipher_suite( |
| 6283 | &rdev->wiphy, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6284 | settings->ciphers_pairwise[i])) |
| 6285 | return -EINVAL; |
| 6286 | } |
| 6287 | |
| 6288 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { |
| 6289 | settings->cipher_group = |
| 6290 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 6291 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
| 6292 | settings->cipher_group)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6293 | return -EINVAL; |
| 6294 | } |
| 6295 | |
| 6296 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { |
| 6297 | settings->wpa_versions = |
| 6298 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); |
| 6299 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) |
| 6300 | return -EINVAL; |
| 6301 | } |
| 6302 | |
| 6303 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { |
| 6304 | void *data; |
Jouni Malinen | 6d30240 | 2011-09-21 18:11:33 +0300 | [diff] [blame] | 6305 | int len; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6306 | |
| 6307 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 6308 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 6309 | settings->n_akm_suites = len / sizeof(u32); |
| 6310 | |
| 6311 | if (len % sizeof(u32)) |
| 6312 | return -EINVAL; |
| 6313 | |
Jouni Malinen | 1b9ca02 | 2011-09-21 16:13:07 +0300 | [diff] [blame] | 6314 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) |
| 6315 | return -EINVAL; |
| 6316 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6317 | memcpy(settings->akm_suites, data, len); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6318 | } |
| 6319 | |
| 6320 | return 0; |
| 6321 | } |
| 6322 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6323 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
| 6324 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6325 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6326 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 6327 | struct ieee80211_channel *chan; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6328 | struct cfg80211_assoc_request req = {}; |
| 6329 | const u8 *bssid, *ssid; |
| 6330 | int err, ssid_len = 0; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6331 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6332 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6333 | return -EINVAL; |
| 6334 | |
| 6335 | if (!info->attrs[NL80211_ATTR_MAC] || |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6336 | !info->attrs[NL80211_ATTR_SSID] || |
| 6337 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6338 | return -EINVAL; |
| 6339 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6340 | if (!rdev->ops->assoc) |
| 6341 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6342 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6343 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6344 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6345 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6346 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6347 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6348 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6349 | chan = ieee80211_get_channel(&rdev->wiphy, |
| 6350 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6351 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
| 6352 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6353 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6354 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 6355 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6356 | |
| 6357 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6358 | req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6359 | req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6360 | } |
| 6361 | |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 6362 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 6363 | enum nl80211_mfp mfp = |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 6364 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 6365 | if (mfp == NL80211_MFP_REQUIRED) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6366 | req.use_mfp = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6367 | else if (mfp != NL80211_MFP_NO) |
| 6368 | return -EINVAL; |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 6369 | } |
| 6370 | |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 6371 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6372 | req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 6373 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6374 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6375 | req.flags |= ASSOC_REQ_DISABLE_HT; |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6376 | |
| 6377 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6378 | memcpy(&req.ht_capa_mask, |
| 6379 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 6380 | sizeof(req.ht_capa_mask)); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6381 | |
| 6382 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6383 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6384 | return -EINVAL; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6385 | memcpy(&req.ht_capa, |
| 6386 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 6387 | sizeof(req.ht_capa)); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6388 | } |
| 6389 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6390 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6391 | req.flags |= ASSOC_REQ_DISABLE_VHT; |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6392 | |
| 6393 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6394 | memcpy(&req.vht_capa_mask, |
| 6395 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), |
| 6396 | sizeof(req.vht_capa_mask)); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6397 | |
| 6398 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6399 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6400 | return -EINVAL; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6401 | memcpy(&req.vht_capa, |
| 6402 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), |
| 6403 | sizeof(req.vht_capa)); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6404 | } |
| 6405 | |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6406 | err = nl80211_crypto_settings(rdev, info, &req.crypto, 1); |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6407 | if (!err) { |
| 6408 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6409 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, |
| 6410 | ssid, ssid_len, &req); |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6411 | wdev_unlock(dev->ieee80211_ptr); |
| 6412 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6413 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6414 | return err; |
| 6415 | } |
| 6416 | |
| 6417 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) |
| 6418 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6419 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6420 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6421 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6422 | int ie_len = 0, err; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6423 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6424 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6425 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6426 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6427 | return -EINVAL; |
| 6428 | |
| 6429 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6430 | return -EINVAL; |
| 6431 | |
| 6432 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 6433 | return -EINVAL; |
| 6434 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6435 | if (!rdev->ops->deauth) |
| 6436 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6437 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6438 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6439 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6440 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6441 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6442 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6443 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6444 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 6445 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6446 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6447 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 6448 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6449 | |
| 6450 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6451 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6452 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6453 | } |
| 6454 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6455 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 6456 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6457 | wdev_lock(dev->ieee80211_ptr); |
| 6458 | err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, |
| 6459 | local_state_change); |
| 6460 | wdev_unlock(dev->ieee80211_ptr); |
| 6461 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6462 | } |
| 6463 | |
| 6464 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) |
| 6465 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6466 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6467 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6468 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6469 | int ie_len = 0, err; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6470 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6471 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6472 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6473 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6474 | return -EINVAL; |
| 6475 | |
| 6476 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6477 | return -EINVAL; |
| 6478 | |
| 6479 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 6480 | return -EINVAL; |
| 6481 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6482 | if (!rdev->ops->disassoc) |
| 6483 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6484 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6485 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6486 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6487 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6488 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6489 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6490 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6491 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 6492 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6493 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6494 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 6495 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6496 | |
| 6497 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6498 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6499 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6500 | } |
| 6501 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6502 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 6503 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6504 | wdev_lock(dev->ieee80211_ptr); |
| 6505 | err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, |
| 6506 | local_state_change); |
| 6507 | wdev_unlock(dev->ieee80211_ptr); |
| 6508 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6509 | } |
| 6510 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 6511 | static bool |
| 6512 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, |
| 6513 | int mcast_rate[IEEE80211_NUM_BANDS], |
| 6514 | int rateval) |
| 6515 | { |
| 6516 | struct wiphy *wiphy = &rdev->wiphy; |
| 6517 | bool found = false; |
| 6518 | int band, i; |
| 6519 | |
| 6520 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 6521 | struct ieee80211_supported_band *sband; |
| 6522 | |
| 6523 | sband = wiphy->bands[band]; |
| 6524 | if (!sband) |
| 6525 | continue; |
| 6526 | |
| 6527 | for (i = 0; i < sband->n_bitrates; i++) { |
| 6528 | if (sband->bitrates[i].bitrate == rateval) { |
| 6529 | mcast_rate[band] = i + 1; |
| 6530 | found = true; |
| 6531 | break; |
| 6532 | } |
| 6533 | } |
| 6534 | } |
| 6535 | |
| 6536 | return found; |
| 6537 | } |
| 6538 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6539 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
| 6540 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6541 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6542 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6543 | struct cfg80211_ibss_params ibss; |
| 6544 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6545 | struct cfg80211_cached_keys *connkeys = NULL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6546 | int err; |
| 6547 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 6548 | memset(&ibss, 0, sizeof(ibss)); |
| 6549 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6550 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6551 | return -EINVAL; |
| 6552 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6553 | if (!info->attrs[NL80211_ATTR_SSID] || |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6554 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 6555 | return -EINVAL; |
| 6556 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 6557 | ibss.beacon_interval = 100; |
| 6558 | |
| 6559 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 6560 | ibss.beacon_interval = |
| 6561 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 6562 | if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000) |
| 6563 | return -EINVAL; |
| 6564 | } |
| 6565 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6566 | if (!rdev->ops->join_ibss) |
| 6567 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6568 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6569 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 6570 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6571 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 6572 | wiphy = &rdev->wiphy; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6573 | |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 6574 | if (info->attrs[NL80211_ATTR_MAC]) { |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6575 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 6576 | |
| 6577 | if (!is_valid_ether_addr(ibss.bssid)) |
| 6578 | return -EINVAL; |
| 6579 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6580 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 6581 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 6582 | |
| 6583 | if (info->attrs[NL80211_ATTR_IE]) { |
| 6584 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6585 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 6586 | } |
| 6587 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6588 | err = nl80211_parse_chandef(rdev, info, &ibss.chandef); |
| 6589 | if (err) |
| 6590 | return err; |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 6591 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6592 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef)) |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 6593 | return -EINVAL; |
| 6594 | |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 6595 | switch (ibss.chandef.width) { |
Simon Wunderlich | bf37264 | 2013-07-08 16:55:58 +0200 | [diff] [blame] | 6596 | case NL80211_CHAN_WIDTH_5: |
| 6597 | case NL80211_CHAN_WIDTH_10: |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 6598 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 6599 | break; |
| 6600 | case NL80211_CHAN_WIDTH_20: |
| 6601 | case NL80211_CHAN_WIDTH_40: |
| 6602 | if (rdev->wiphy.features & NL80211_FEATURE_HT_IBSS) |
| 6603 | break; |
| 6604 | default: |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 6605 | return -EINVAL; |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 6606 | } |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 6607 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6608 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6609 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6610 | |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 6611 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 6612 | u8 *rates = |
| 6613 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 6614 | int n_rates = |
| 6615 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 6616 | struct ieee80211_supported_band *sband = |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6617 | wiphy->bands[ibss.chandef.chan->band]; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 6618 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 6619 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 6620 | &ibss.basic_rates); |
| 6621 | if (err) |
| 6622 | return err; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 6623 | } |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 6624 | |
Simon Wunderlich | 803768f | 2013-06-28 10:39:58 +0200 | [diff] [blame] | 6625 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 6626 | memcpy(&ibss.ht_capa_mask, |
| 6627 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 6628 | sizeof(ibss.ht_capa_mask)); |
| 6629 | |
| 6630 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
| 6631 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 6632 | return -EINVAL; |
| 6633 | memcpy(&ibss.ht_capa, |
| 6634 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 6635 | sizeof(ibss.ht_capa)); |
| 6636 | } |
| 6637 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 6638 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 6639 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, |
| 6640 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 6641 | return -EINVAL; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 6642 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6643 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6644 | bool no_ht = false; |
| 6645 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6646 | connkeys = nl80211_parse_connkeys(rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6647 | info->attrs[NL80211_ATTR_KEYS], |
| 6648 | &no_ht); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6649 | if (IS_ERR(connkeys)) |
| 6650 | return PTR_ERR(connkeys); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6651 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 6652 | if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) && |
| 6653 | no_ht) { |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6654 | kfree(connkeys); |
| 6655 | return -EINVAL; |
| 6656 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6657 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6658 | |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 6659 | ibss.control_port = |
| 6660 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]); |
| 6661 | |
Simon Wunderlich | 5336fa8 | 2013-10-07 18:41:05 +0200 | [diff] [blame] | 6662 | ibss.userspace_handles_dfs = |
| 6663 | nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]); |
| 6664 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6665 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6666 | if (err) |
| 6667 | kfree(connkeys); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6668 | return err; |
| 6669 | } |
| 6670 | |
| 6671 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) |
| 6672 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6673 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6674 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6675 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6676 | if (!rdev->ops->leave_ibss) |
| 6677 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6678 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6679 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 6680 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6681 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6682 | return cfg80211_leave_ibss(rdev, dev, false); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6683 | } |
| 6684 | |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 6685 | static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info) |
| 6686 | { |
| 6687 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6688 | struct net_device *dev = info->user_ptr[1]; |
| 6689 | int mcast_rate[IEEE80211_NUM_BANDS]; |
| 6690 | u32 nla_rate; |
| 6691 | int err; |
| 6692 | |
| 6693 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
| 6694 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 6695 | return -EOPNOTSUPP; |
| 6696 | |
| 6697 | if (!rdev->ops->set_mcast_rate) |
| 6698 | return -EOPNOTSUPP; |
| 6699 | |
| 6700 | memset(mcast_rate, 0, sizeof(mcast_rate)); |
| 6701 | |
| 6702 | if (!info->attrs[NL80211_ATTR_MCAST_RATE]) |
| 6703 | return -EINVAL; |
| 6704 | |
| 6705 | nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]); |
| 6706 | if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate)) |
| 6707 | return -EINVAL; |
| 6708 | |
| 6709 | err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate); |
| 6710 | |
| 6711 | return err; |
| 6712 | } |
| 6713 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 6714 | static struct sk_buff * |
| 6715 | __cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev, |
| 6716 | int approxlen, u32 portid, u32 seq, |
| 6717 | enum nl80211_commands cmd, |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 6718 | enum nl80211_attrs attr, |
| 6719 | const struct nl80211_vendor_cmd_info *info, |
| 6720 | gfp_t gfp) |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 6721 | { |
| 6722 | struct sk_buff *skb; |
| 6723 | void *hdr; |
| 6724 | struct nlattr *data; |
| 6725 | |
| 6726 | skb = nlmsg_new(approxlen + 100, gfp); |
| 6727 | if (!skb) |
| 6728 | return NULL; |
| 6729 | |
| 6730 | hdr = nl80211hdr_put(skb, portid, seq, 0, cmd); |
| 6731 | if (!hdr) { |
| 6732 | kfree_skb(skb); |
| 6733 | return NULL; |
| 6734 | } |
| 6735 | |
| 6736 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 6737 | goto nla_put_failure; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 6738 | |
| 6739 | if (info) { |
| 6740 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID, |
| 6741 | info->vendor_id)) |
| 6742 | goto nla_put_failure; |
| 6743 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD, |
| 6744 | info->subcmd)) |
| 6745 | goto nla_put_failure; |
| 6746 | } |
| 6747 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 6748 | data = nla_nest_start(skb, attr); |
| 6749 | |
| 6750 | ((void **)skb->cb)[0] = rdev; |
| 6751 | ((void **)skb->cb)[1] = hdr; |
| 6752 | ((void **)skb->cb)[2] = data; |
| 6753 | |
| 6754 | return skb; |
| 6755 | |
| 6756 | nla_put_failure: |
| 6757 | kfree_skb(skb); |
| 6758 | return NULL; |
| 6759 | } |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 6760 | |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 6761 | struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy, |
| 6762 | enum nl80211_commands cmd, |
| 6763 | enum nl80211_attrs attr, |
| 6764 | int vendor_event_idx, |
| 6765 | int approxlen, gfp_t gfp) |
| 6766 | { |
| 6767 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 6768 | const struct nl80211_vendor_cmd_info *info; |
| 6769 | |
| 6770 | switch (cmd) { |
| 6771 | case NL80211_CMD_TESTMODE: |
| 6772 | if (WARN_ON(vendor_event_idx != -1)) |
| 6773 | return NULL; |
| 6774 | info = NULL; |
| 6775 | break; |
| 6776 | case NL80211_CMD_VENDOR: |
| 6777 | if (WARN_ON(vendor_event_idx < 0 || |
| 6778 | vendor_event_idx >= wiphy->n_vendor_events)) |
| 6779 | return NULL; |
| 6780 | info = &wiphy->vendor_events[vendor_event_idx]; |
| 6781 | break; |
| 6782 | default: |
| 6783 | WARN_ON(1); |
| 6784 | return NULL; |
| 6785 | } |
| 6786 | |
| 6787 | return __cfg80211_alloc_vendor_skb(rdev, approxlen, 0, 0, |
| 6788 | cmd, attr, info, gfp); |
| 6789 | } |
| 6790 | EXPORT_SYMBOL(__cfg80211_alloc_event_skb); |
| 6791 | |
| 6792 | void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp) |
| 6793 | { |
| 6794 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 6795 | void *hdr = ((void **)skb->cb)[1]; |
| 6796 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 6797 | enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE; |
| 6798 | |
| 6799 | nla_nest_end(skb, data); |
| 6800 | genlmsg_end(skb, hdr); |
| 6801 | |
| 6802 | if (data->nla_type == NL80211_ATTR_VENDOR_DATA) |
| 6803 | mcgrp = NL80211_MCGRP_VENDOR; |
| 6804 | |
| 6805 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0, |
| 6806 | mcgrp, gfp); |
| 6807 | } |
| 6808 | EXPORT_SYMBOL(__cfg80211_send_event_skb); |
| 6809 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6810 | #ifdef CONFIG_NL80211_TESTMODE |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6811 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
| 6812 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6813 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 6814 | struct wireless_dev *wdev = |
| 6815 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6816 | int err; |
| 6817 | |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 6818 | if (!rdev->ops->testmode_cmd) |
| 6819 | return -EOPNOTSUPP; |
| 6820 | |
| 6821 | if (IS_ERR(wdev)) { |
| 6822 | err = PTR_ERR(wdev); |
| 6823 | if (err != -EINVAL) |
| 6824 | return err; |
| 6825 | wdev = NULL; |
| 6826 | } else if (wdev->wiphy != &rdev->wiphy) { |
| 6827 | return -EINVAL; |
| 6828 | } |
| 6829 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6830 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
| 6831 | return -EINVAL; |
| 6832 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 6833 | rdev->cur_cmd_info = info; |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 6834 | err = rdev_testmode_cmd(rdev, wdev, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6835 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
| 6836 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 6837 | rdev->cur_cmd_info = NULL; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6838 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6839 | return err; |
| 6840 | } |
| 6841 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6842 | static int nl80211_testmode_dump(struct sk_buff *skb, |
| 6843 | struct netlink_callback *cb) |
| 6844 | { |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6845 | struct cfg80211_registered_device *rdev; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6846 | int err; |
| 6847 | long phy_idx; |
| 6848 | void *data = NULL; |
| 6849 | int data_len = 0; |
| 6850 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6851 | rtnl_lock(); |
| 6852 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6853 | if (cb->args[0]) { |
| 6854 | /* |
| 6855 | * 0 is a valid index, but not valid for args[0], |
| 6856 | * so we need to offset by 1. |
| 6857 | */ |
| 6858 | phy_idx = cb->args[0] - 1; |
| 6859 | } else { |
| 6860 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 6861 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 6862 | nl80211_policy); |
| 6863 | if (err) |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6864 | goto out_err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6865 | |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 6866 | rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), |
| 6867 | nl80211_fam.attrbuf); |
| 6868 | if (IS_ERR(rdev)) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6869 | err = PTR_ERR(rdev); |
| 6870 | goto out_err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6871 | } |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 6872 | phy_idx = rdev->wiphy_idx; |
| 6873 | rdev = NULL; |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 6874 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6875 | if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]) |
| 6876 | cb->args[1] = |
| 6877 | (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]; |
| 6878 | } |
| 6879 | |
| 6880 | if (cb->args[1]) { |
| 6881 | data = nla_data((void *)cb->args[1]); |
| 6882 | data_len = nla_len((void *)cb->args[1]); |
| 6883 | } |
| 6884 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6885 | rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
| 6886 | if (!rdev) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6887 | err = -ENOENT; |
| 6888 | goto out_err; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6889 | } |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6890 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6891 | if (!rdev->ops->testmode_dump) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6892 | err = -EOPNOTSUPP; |
| 6893 | goto out_err; |
| 6894 | } |
| 6895 | |
| 6896 | while (1) { |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6897 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6898 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 6899 | NL80211_CMD_TESTMODE); |
| 6900 | struct nlattr *tmdata; |
| 6901 | |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 6902 | if (!hdr) |
| 6903 | break; |
| 6904 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6905 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6906 | genlmsg_cancel(skb, hdr); |
| 6907 | break; |
| 6908 | } |
| 6909 | |
| 6910 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 6911 | if (!tmdata) { |
| 6912 | genlmsg_cancel(skb, hdr); |
| 6913 | break; |
| 6914 | } |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6915 | err = rdev_testmode_dump(rdev, skb, cb, data, data_len); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6916 | nla_nest_end(skb, tmdata); |
| 6917 | |
| 6918 | if (err == -ENOBUFS || err == -ENOENT) { |
| 6919 | genlmsg_cancel(skb, hdr); |
| 6920 | break; |
| 6921 | } else if (err) { |
| 6922 | genlmsg_cancel(skb, hdr); |
| 6923 | goto out_err; |
| 6924 | } |
| 6925 | |
| 6926 | genlmsg_end(skb, hdr); |
| 6927 | } |
| 6928 | |
| 6929 | err = skb->len; |
| 6930 | /* see above */ |
| 6931 | cb->args[0] = phy_idx + 1; |
| 6932 | out_err: |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6933 | rtnl_unlock(); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6934 | return err; |
| 6935 | } |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6936 | #endif |
| 6937 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6938 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
| 6939 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6940 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6941 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6942 | struct cfg80211_connect_params connect; |
| 6943 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6944 | struct cfg80211_cached_keys *connkeys = NULL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6945 | int err; |
| 6946 | |
| 6947 | memset(&connect, 0, sizeof(connect)); |
| 6948 | |
| 6949 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6950 | return -EINVAL; |
| 6951 | |
| 6952 | if (!info->attrs[NL80211_ATTR_SSID] || |
| 6953 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 6954 | return -EINVAL; |
| 6955 | |
| 6956 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 6957 | connect.auth_type = |
| 6958 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 6959 | if (!nl80211_valid_auth_type(rdev, connect.auth_type, |
| 6960 | NL80211_CMD_CONNECT)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6961 | return -EINVAL; |
| 6962 | } else |
| 6963 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 6964 | |
| 6965 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; |
| 6966 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 6967 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 6968 | NL80211_MAX_NR_CIPHER_SUITES); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6969 | if (err) |
| 6970 | return err; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6971 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6972 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6973 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6974 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6975 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 6976 | wiphy = &rdev->wiphy; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6977 | |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 6978 | connect.bg_scan_period = -1; |
| 6979 | if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] && |
| 6980 | (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) { |
| 6981 | connect.bg_scan_period = |
| 6982 | nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]); |
| 6983 | } |
| 6984 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6985 | if (info->attrs[NL80211_ATTR_MAC]) |
| 6986 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6987 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 6988 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 6989 | |
| 6990 | if (info->attrs[NL80211_ATTR_IE]) { |
| 6991 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6992 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 6993 | } |
| 6994 | |
Jouni Malinen | cee00a9 | 2013-01-15 17:15:57 +0200 | [diff] [blame] | 6995 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
| 6996 | connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
| 6997 | if (connect.mfp != NL80211_MFP_REQUIRED && |
| 6998 | connect.mfp != NL80211_MFP_NO) |
| 6999 | return -EINVAL; |
| 7000 | } else { |
| 7001 | connect.mfp = NL80211_MFP_NO; |
| 7002 | } |
| 7003 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7004 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 7005 | connect.channel = |
| 7006 | ieee80211_get_channel(wiphy, |
| 7007 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
| 7008 | if (!connect.channel || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7009 | connect.channel->flags & IEEE80211_CHAN_DISABLED) |
| 7010 | return -EINVAL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7011 | } |
| 7012 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7013 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
| 7014 | connkeys = nl80211_parse_connkeys(rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 7015 | info->attrs[NL80211_ATTR_KEYS], NULL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7016 | if (IS_ERR(connkeys)) |
| 7017 | return PTR_ERR(connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7018 | } |
| 7019 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 7020 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
| 7021 | connect.flags |= ASSOC_REQ_DISABLE_HT; |
| 7022 | |
| 7023 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 7024 | memcpy(&connect.ht_capa_mask, |
| 7025 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 7026 | sizeof(connect.ht_capa_mask)); |
| 7027 | |
| 7028 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 7029 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) { |
| 7030 | kfree(connkeys); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 7031 | return -EINVAL; |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 7032 | } |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 7033 | memcpy(&connect.ht_capa, |
| 7034 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 7035 | sizeof(connect.ht_capa)); |
| 7036 | } |
| 7037 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 7038 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
| 7039 | connect.flags |= ASSOC_REQ_DISABLE_VHT; |
| 7040 | |
| 7041 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
| 7042 | memcpy(&connect.vht_capa_mask, |
| 7043 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), |
| 7044 | sizeof(connect.vht_capa_mask)); |
| 7045 | |
| 7046 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { |
| 7047 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) { |
| 7048 | kfree(connkeys); |
| 7049 | return -EINVAL; |
| 7050 | } |
| 7051 | memcpy(&connect.vht_capa, |
| 7052 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), |
| 7053 | sizeof(connect.vht_capa)); |
| 7054 | } |
| 7055 | |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7056 | wdev_lock(dev->ieee80211_ptr); |
| 7057 | err = cfg80211_connect(rdev, dev, &connect, connkeys, NULL); |
| 7058 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7059 | if (err) |
| 7060 | kfree(connkeys); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7061 | return err; |
| 7062 | } |
| 7063 | |
| 7064 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) |
| 7065 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7066 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7067 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7068 | u16 reason; |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7069 | int ret; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7070 | |
| 7071 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 7072 | reason = WLAN_REASON_DEAUTH_LEAVING; |
| 7073 | else |
| 7074 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 7075 | |
| 7076 | if (reason == 0) |
| 7077 | return -EINVAL; |
| 7078 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7079 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7080 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7081 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7082 | |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7083 | wdev_lock(dev->ieee80211_ptr); |
| 7084 | ret = cfg80211_disconnect(rdev, dev, reason, true); |
| 7085 | wdev_unlock(dev->ieee80211_ptr); |
| 7086 | return ret; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7087 | } |
| 7088 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7089 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
| 7090 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7091 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7092 | struct net *net; |
| 7093 | int err; |
| 7094 | u32 pid; |
| 7095 | |
| 7096 | if (!info->attrs[NL80211_ATTR_PID]) |
| 7097 | return -EINVAL; |
| 7098 | |
| 7099 | pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); |
| 7100 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7101 | net = get_net_ns_by_pid(pid); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7102 | if (IS_ERR(net)) |
| 7103 | return PTR_ERR(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7104 | |
| 7105 | err = 0; |
| 7106 | |
| 7107 | /* check if anything to do */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7108 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
| 7109 | err = cfg80211_switch_netns(rdev, net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7110 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7111 | put_net(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7112 | return err; |
| 7113 | } |
| 7114 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7115 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 7116 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7117 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7118 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
| 7119 | struct cfg80211_pmksa *pmksa) = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7120 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7121 | struct cfg80211_pmksa pmksa; |
| 7122 | |
| 7123 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); |
| 7124 | |
| 7125 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 7126 | return -EINVAL; |
| 7127 | |
| 7128 | if (!info->attrs[NL80211_ATTR_PMKID]) |
| 7129 | return -EINVAL; |
| 7130 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7131 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
| 7132 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 7133 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7134 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7135 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7136 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7137 | |
| 7138 | switch (info->genlhdr->cmd) { |
| 7139 | case NL80211_CMD_SET_PMKSA: |
| 7140 | rdev_ops = rdev->ops->set_pmksa; |
| 7141 | break; |
| 7142 | case NL80211_CMD_DEL_PMKSA: |
| 7143 | rdev_ops = rdev->ops->del_pmksa; |
| 7144 | break; |
| 7145 | default: |
| 7146 | WARN_ON(1); |
| 7147 | break; |
| 7148 | } |
| 7149 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7150 | if (!rdev_ops) |
| 7151 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7152 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7153 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7154 | } |
| 7155 | |
| 7156 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 7157 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7158 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7159 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7160 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7161 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7162 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7163 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7164 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7165 | if (!rdev->ops->flush_pmksa) |
| 7166 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7167 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7168 | return rdev_flush_pmksa(rdev, dev); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7169 | } |
| 7170 | |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7171 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) |
| 7172 | { |
| 7173 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7174 | struct net_device *dev = info->user_ptr[1]; |
| 7175 | u8 action_code, dialog_token; |
| 7176 | u16 status_code; |
| 7177 | u8 *peer; |
| 7178 | |
| 7179 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 7180 | !rdev->ops->tdls_mgmt) |
| 7181 | return -EOPNOTSUPP; |
| 7182 | |
| 7183 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || |
| 7184 | !info->attrs[NL80211_ATTR_STATUS_CODE] || |
| 7185 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || |
| 7186 | !info->attrs[NL80211_ATTR_IE] || |
| 7187 | !info->attrs[NL80211_ATTR_MAC]) |
| 7188 | return -EINVAL; |
| 7189 | |
| 7190 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 7191 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); |
| 7192 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); |
| 7193 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); |
| 7194 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7195 | return rdev_tdls_mgmt(rdev, dev, peer, action_code, |
| 7196 | dialog_token, status_code, |
| 7197 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 7198 | nla_len(info->attrs[NL80211_ATTR_IE])); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7199 | } |
| 7200 | |
| 7201 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) |
| 7202 | { |
| 7203 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7204 | struct net_device *dev = info->user_ptr[1]; |
| 7205 | enum nl80211_tdls_operation operation; |
| 7206 | u8 *peer; |
| 7207 | |
| 7208 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 7209 | !rdev->ops->tdls_oper) |
| 7210 | return -EOPNOTSUPP; |
| 7211 | |
| 7212 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || |
| 7213 | !info->attrs[NL80211_ATTR_MAC]) |
| 7214 | return -EINVAL; |
| 7215 | |
| 7216 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); |
| 7217 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 7218 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7219 | return rdev_tdls_oper(rdev, dev, peer, operation); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7220 | } |
| 7221 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7222 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
| 7223 | 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 | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7226 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7227 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7228 | struct sk_buff *msg; |
| 7229 | void *hdr; |
| 7230 | u64 cookie; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7231 | u32 duration; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7232 | int err; |
| 7233 | |
| 7234 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 7235 | !info->attrs[NL80211_ATTR_DURATION]) |
| 7236 | return -EINVAL; |
| 7237 | |
| 7238 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
| 7239 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 7240 | if (!rdev->ops->remain_on_channel || |
| 7241 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7242 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7243 | |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 7244 | /* |
| 7245 | * We should be on that channel for at least a minimum amount of |
| 7246 | * time (10ms) but no longer than the driver supports. |
| 7247 | */ |
| 7248 | if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 7249 | duration > rdev->wiphy.max_remain_on_channel_duration) |
| 7250 | return -EINVAL; |
| 7251 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7252 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 7253 | if (err) |
| 7254 | return err; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7255 | |
| 7256 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7257 | if (!msg) |
| 7258 | return -ENOMEM; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7259 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7260 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7261 | NL80211_CMD_REMAIN_ON_CHANNEL); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 7262 | if (!hdr) { |
| 7263 | err = -ENOBUFS; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7264 | goto free_msg; |
| 7265 | } |
| 7266 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7267 | err = rdev_remain_on_channel(rdev, wdev, chandef.chan, |
| 7268 | duration, &cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7269 | |
| 7270 | if (err) |
| 7271 | goto free_msg; |
| 7272 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7273 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 7274 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7275 | |
| 7276 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7277 | |
| 7278 | return genlmsg_reply(msg, info); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7279 | |
| 7280 | nla_put_failure: |
| 7281 | err = -ENOBUFS; |
| 7282 | free_msg: |
| 7283 | nlmsg_free(msg); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7284 | return err; |
| 7285 | } |
| 7286 | |
| 7287 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, |
| 7288 | struct genl_info *info) |
| 7289 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7290 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7291 | struct wireless_dev *wdev = info->user_ptr[1]; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7292 | u64 cookie; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7293 | |
| 7294 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 7295 | return -EINVAL; |
| 7296 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7297 | if (!rdev->ops->cancel_remain_on_channel) |
| 7298 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7299 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7300 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 7301 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7302 | return rdev_cancel_remain_on_channel(rdev, wdev, cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7303 | } |
| 7304 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7305 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
| 7306 | u8 *rates, u8 rates_len) |
| 7307 | { |
| 7308 | u8 i; |
| 7309 | u32 mask = 0; |
| 7310 | |
| 7311 | for (i = 0; i < rates_len; i++) { |
| 7312 | int rate = (rates[i] & 0x7f) * 5; |
| 7313 | int ridx; |
| 7314 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { |
| 7315 | struct ieee80211_rate *srate = |
| 7316 | &sband->bitrates[ridx]; |
| 7317 | if (rate == srate->bitrate) { |
| 7318 | mask |= 1 << ridx; |
| 7319 | break; |
| 7320 | } |
| 7321 | } |
| 7322 | if (ridx == sband->n_bitrates) |
| 7323 | return 0; /* rate not found */ |
| 7324 | } |
| 7325 | |
| 7326 | return mask; |
| 7327 | } |
| 7328 | |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7329 | static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, |
| 7330 | u8 *rates, u8 rates_len, |
| 7331 | u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) |
| 7332 | { |
| 7333 | u8 i; |
| 7334 | |
| 7335 | memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); |
| 7336 | |
| 7337 | for (i = 0; i < rates_len; i++) { |
| 7338 | int ridx, rbit; |
| 7339 | |
| 7340 | ridx = rates[i] / 8; |
| 7341 | rbit = BIT(rates[i] % 8); |
| 7342 | |
| 7343 | /* check validity */ |
Dan Carpenter | 910570b5 | 2012-02-01 10:42:11 +0300 | [diff] [blame] | 7344 | if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7345 | return false; |
| 7346 | |
| 7347 | /* check availability */ |
| 7348 | if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) |
| 7349 | mcs[ridx] |= rbit; |
| 7350 | else |
| 7351 | return false; |
| 7352 | } |
| 7353 | |
| 7354 | return true; |
| 7355 | } |
| 7356 | |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 7357 | static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map) |
| 7358 | { |
| 7359 | u16 mcs_mask = 0; |
| 7360 | |
| 7361 | switch (vht_mcs_map) { |
| 7362 | case IEEE80211_VHT_MCS_NOT_SUPPORTED: |
| 7363 | break; |
| 7364 | case IEEE80211_VHT_MCS_SUPPORT_0_7: |
| 7365 | mcs_mask = 0x00FF; |
| 7366 | break; |
| 7367 | case IEEE80211_VHT_MCS_SUPPORT_0_8: |
| 7368 | mcs_mask = 0x01FF; |
| 7369 | break; |
| 7370 | case IEEE80211_VHT_MCS_SUPPORT_0_9: |
| 7371 | mcs_mask = 0x03FF; |
| 7372 | break; |
| 7373 | default: |
| 7374 | break; |
| 7375 | } |
| 7376 | |
| 7377 | return mcs_mask; |
| 7378 | } |
| 7379 | |
| 7380 | static void vht_build_mcs_mask(u16 vht_mcs_map, |
| 7381 | u16 vht_mcs_mask[NL80211_VHT_NSS_MAX]) |
| 7382 | { |
| 7383 | u8 nss; |
| 7384 | |
| 7385 | for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) { |
| 7386 | vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03); |
| 7387 | vht_mcs_map >>= 2; |
| 7388 | } |
| 7389 | } |
| 7390 | |
| 7391 | static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband, |
| 7392 | struct nl80211_txrate_vht *txrate, |
| 7393 | u16 mcs[NL80211_VHT_NSS_MAX]) |
| 7394 | { |
| 7395 | u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); |
| 7396 | u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {}; |
| 7397 | u8 i; |
| 7398 | |
| 7399 | if (!sband->vht_cap.vht_supported) |
| 7400 | return false; |
| 7401 | |
| 7402 | memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX); |
| 7403 | |
| 7404 | /* Build vht_mcs_mask from VHT capabilities */ |
| 7405 | vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask); |
| 7406 | |
| 7407 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) { |
| 7408 | if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i]) |
| 7409 | mcs[i] = txrate->mcs[i]; |
| 7410 | else |
| 7411 | return false; |
| 7412 | } |
| 7413 | |
| 7414 | return true; |
| 7415 | } |
| 7416 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 7417 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7418 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
| 7419 | .len = NL80211_MAX_SUPP_RATES }, |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 7420 | [NL80211_TXRATE_HT] = { .type = NLA_BINARY, |
| 7421 | .len = NL80211_MAX_SUPP_HT_RATES }, |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 7422 | [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)}, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7423 | }; |
| 7424 | |
| 7425 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, |
| 7426 | struct genl_info *info) |
| 7427 | { |
| 7428 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7429 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7430 | struct cfg80211_bitrate_mask mask; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7431 | int rem, i; |
| 7432 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7433 | struct nlattr *tx_rates; |
| 7434 | struct ieee80211_supported_band *sband; |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 7435 | u16 vht_tx_mcs_map; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7436 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7437 | if (!rdev->ops->set_bitrate_mask) |
| 7438 | return -EOPNOTSUPP; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7439 | |
| 7440 | memset(&mask, 0, sizeof(mask)); |
| 7441 | /* Default to all rates enabled */ |
| 7442 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) { |
| 7443 | sband = rdev->wiphy.bands[i]; |
Janusz Dziedzic | 7869303 | 2013-12-03 09:50:44 +0100 | [diff] [blame] | 7444 | |
| 7445 | if (!sband) |
| 7446 | continue; |
| 7447 | |
| 7448 | mask.control[i].legacy = (1 << sband->n_bitrates) - 1; |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 7449 | memcpy(mask.control[i].ht_mcs, |
Janusz Dziedzic | 7869303 | 2013-12-03 09:50:44 +0100 | [diff] [blame] | 7450 | sband->ht_cap.mcs.rx_mask, |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 7451 | sizeof(mask.control[i].ht_mcs)); |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 7452 | |
| 7453 | if (!sband->vht_cap.vht_supported) |
| 7454 | continue; |
| 7455 | |
| 7456 | vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); |
| 7457 | 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] | 7458 | } |
| 7459 | |
Janusz Dziedzic | b9243ab | 2013-12-05 10:02:14 +0100 | [diff] [blame] | 7460 | /* if no rates are given set it back to the defaults */ |
| 7461 | if (!info->attrs[NL80211_ATTR_TX_RATES]) |
| 7462 | goto out; |
| 7463 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7464 | /* |
| 7465 | * The nested attribute uses enum nl80211_band as the index. This maps |
| 7466 | * directly to the enum ieee80211_band values used in cfg80211. |
| 7467 | */ |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7468 | BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7469 | nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) |
| 7470 | { |
| 7471 | enum ieee80211_band band = nla_type(tx_rates); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7472 | if (band < 0 || band >= IEEE80211_NUM_BANDS) |
| 7473 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7474 | sband = rdev->wiphy.bands[band]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7475 | if (sband == NULL) |
| 7476 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7477 | nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), |
| 7478 | nla_len(tx_rates), nl80211_txattr_policy); |
| 7479 | if (tb[NL80211_TXRATE_LEGACY]) { |
| 7480 | mask.control[band].legacy = rateset_to_mask( |
| 7481 | sband, |
| 7482 | nla_data(tb[NL80211_TXRATE_LEGACY]), |
| 7483 | nla_len(tb[NL80211_TXRATE_LEGACY])); |
Bala Shanmugam | 218d2e2 | 2012-04-20 19:12:58 +0530 | [diff] [blame] | 7484 | if ((mask.control[band].legacy == 0) && |
| 7485 | nla_len(tb[NL80211_TXRATE_LEGACY])) |
| 7486 | return -EINVAL; |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7487 | } |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 7488 | if (tb[NL80211_TXRATE_HT]) { |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7489 | if (!ht_rateset_to_mask( |
| 7490 | sband, |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 7491 | nla_data(tb[NL80211_TXRATE_HT]), |
| 7492 | nla_len(tb[NL80211_TXRATE_HT]), |
| 7493 | mask.control[band].ht_mcs)) |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7494 | return -EINVAL; |
| 7495 | } |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 7496 | if (tb[NL80211_TXRATE_VHT]) { |
| 7497 | if (!vht_set_mcs_mask( |
| 7498 | sband, |
| 7499 | nla_data(tb[NL80211_TXRATE_VHT]), |
| 7500 | mask.control[band].vht_mcs)) |
| 7501 | return -EINVAL; |
| 7502 | } |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7503 | |
| 7504 | if (mask.control[band].legacy == 0) { |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 7505 | /* don't allow empty legacy rates if HT or VHT |
| 7506 | * are not even supported. |
| 7507 | */ |
| 7508 | if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported || |
| 7509 | rdev->wiphy.bands[band]->vht_cap.vht_supported)) |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7510 | return -EINVAL; |
| 7511 | |
| 7512 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 7513 | if (mask.control[band].ht_mcs[i]) |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 7514 | goto out; |
| 7515 | |
| 7516 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) |
| 7517 | if (mask.control[band].vht_mcs[i]) |
| 7518 | goto out; |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7519 | |
| 7520 | /* legacy and mcs rates may not be both empty */ |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 7521 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7522 | } |
| 7523 | } |
| 7524 | |
Janusz Dziedzic | b9243ab | 2013-12-05 10:02:14 +0100 | [diff] [blame] | 7525 | out: |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7526 | return rdev_set_bitrate_mask(rdev, dev, NULL, &mask); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7527 | } |
| 7528 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7529 | 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] | 7530 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7531 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7532 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7533 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7534 | |
| 7535 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) |
| 7536 | return -EINVAL; |
| 7537 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7538 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
| 7539 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7540 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7541 | switch (wdev->iftype) { |
| 7542 | case NL80211_IFTYPE_STATION: |
| 7543 | case NL80211_IFTYPE_ADHOC: |
| 7544 | case NL80211_IFTYPE_P2P_CLIENT: |
| 7545 | case NL80211_IFTYPE_AP: |
| 7546 | case NL80211_IFTYPE_AP_VLAN: |
| 7547 | case NL80211_IFTYPE_MESH_POINT: |
| 7548 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7549 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7550 | break; |
| 7551 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7552 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7553 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7554 | |
| 7555 | /* not much point in registering if we can't reply */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7556 | if (!rdev->ops->mgmt_tx) |
| 7557 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7558 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7559 | return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7560 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
| 7561 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7562 | } |
| 7563 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7564 | 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] | 7565 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7566 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7567 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7568 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7569 | int err; |
Johannes Berg | d64d373 | 2011-11-10 09:44:46 +0100 | [diff] [blame] | 7570 | void *hdr = NULL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7571 | u64 cookie; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7572 | struct sk_buff *msg = NULL; |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7573 | struct cfg80211_mgmt_tx_params params = { |
| 7574 | .dont_wait_for_ack = |
| 7575 | info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK], |
| 7576 | }; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7577 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7578 | if (!info->attrs[NL80211_ATTR_FRAME]) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7579 | return -EINVAL; |
| 7580 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7581 | if (!rdev->ops->mgmt_tx) |
| 7582 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7583 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7584 | switch (wdev->iftype) { |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 7585 | case NL80211_IFTYPE_P2P_DEVICE: |
| 7586 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 7587 | return -EINVAL; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7588 | case NL80211_IFTYPE_STATION: |
| 7589 | case NL80211_IFTYPE_ADHOC: |
| 7590 | case NL80211_IFTYPE_P2P_CLIENT: |
| 7591 | case NL80211_IFTYPE_AP: |
| 7592 | case NL80211_IFTYPE_AP_VLAN: |
| 7593 | case NL80211_IFTYPE_MESH_POINT: |
| 7594 | case NL80211_IFTYPE_P2P_GO: |
| 7595 | break; |
| 7596 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7597 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7598 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7599 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7600 | if (info->attrs[NL80211_ATTR_DURATION]) { |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 7601 | if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7602 | return -EINVAL; |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7603 | params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 7604 | |
| 7605 | /* |
| 7606 | * We should wait on the channel for at least a minimum amount |
| 7607 | * of time (10ms) but no longer than the driver supports. |
| 7608 | */ |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7609 | if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 7610 | params.wait > rdev->wiphy.max_remain_on_channel_duration) |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 7611 | return -EINVAL; |
| 7612 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7613 | } |
| 7614 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7615 | params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7616 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7617 | if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 7618 | return -EINVAL; |
| 7619 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7620 | 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] | 7621 | |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 7622 | /* get the channel if any has been specified, otherwise pass NULL to |
| 7623 | * the driver. The latter will use the current one |
| 7624 | */ |
| 7625 | chandef.chan = NULL; |
| 7626 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 7627 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 7628 | if (err) |
| 7629 | return err; |
| 7630 | } |
| 7631 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7632 | if (!chandef.chan && params.offchan) |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 7633 | return -EINVAL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7634 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7635 | if (!params.dont_wait_for_ack) { |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7636 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 7637 | if (!msg) |
| 7638 | return -ENOMEM; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7639 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7640 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7641 | NL80211_CMD_FRAME); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 7642 | if (!hdr) { |
| 7643 | err = -ENOBUFS; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7644 | goto free_msg; |
| 7645 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7646 | } |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7647 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7648 | params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]); |
| 7649 | params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]); |
| 7650 | params.chan = chandef.chan; |
| 7651 | err = cfg80211_mlme_mgmt_tx(rdev, wdev, ¶ms, &cookie); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7652 | if (err) |
| 7653 | goto free_msg; |
| 7654 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7655 | if (msg) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7656 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 7657 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7658 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7659 | genlmsg_end(msg, hdr); |
| 7660 | return genlmsg_reply(msg, info); |
| 7661 | } |
| 7662 | |
| 7663 | return 0; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7664 | |
| 7665 | nla_put_failure: |
| 7666 | err = -ENOBUFS; |
| 7667 | free_msg: |
| 7668 | nlmsg_free(msg); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7669 | return err; |
| 7670 | } |
| 7671 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7672 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
| 7673 | { |
| 7674 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7675 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7676 | u64 cookie; |
| 7677 | |
| 7678 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 7679 | return -EINVAL; |
| 7680 | |
| 7681 | if (!rdev->ops->mgmt_tx_cancel_wait) |
| 7682 | return -EOPNOTSUPP; |
| 7683 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7684 | switch (wdev->iftype) { |
| 7685 | case NL80211_IFTYPE_STATION: |
| 7686 | case NL80211_IFTYPE_ADHOC: |
| 7687 | case NL80211_IFTYPE_P2P_CLIENT: |
| 7688 | case NL80211_IFTYPE_AP: |
| 7689 | case NL80211_IFTYPE_AP_VLAN: |
| 7690 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7691 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7692 | break; |
| 7693 | default: |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7694 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7695 | } |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7696 | |
| 7697 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 7698 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7699 | return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie); |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7700 | } |
| 7701 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7702 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
| 7703 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7704 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7705 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7706 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7707 | u8 ps_state; |
| 7708 | bool state; |
| 7709 | int err; |
| 7710 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7711 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
| 7712 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7713 | |
| 7714 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); |
| 7715 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7716 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
| 7717 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7718 | |
| 7719 | wdev = dev->ieee80211_ptr; |
| 7720 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7721 | if (!rdev->ops->set_power_mgmt) |
| 7722 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7723 | |
| 7724 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; |
| 7725 | |
| 7726 | if (state == wdev->ps) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7727 | return 0; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7728 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7729 | err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7730 | if (!err) |
| 7731 | wdev->ps = state; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7732 | return err; |
| 7733 | } |
| 7734 | |
| 7735 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) |
| 7736 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7737 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7738 | enum nl80211_ps_state ps_state; |
| 7739 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7740 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7741 | struct sk_buff *msg; |
| 7742 | void *hdr; |
| 7743 | int err; |
| 7744 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7745 | wdev = dev->ieee80211_ptr; |
| 7746 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7747 | if (!rdev->ops->set_power_mgmt) |
| 7748 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7749 | |
| 7750 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7751 | if (!msg) |
| 7752 | return -ENOMEM; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7753 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7754 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7755 | NL80211_CMD_GET_POWER_SAVE); |
| 7756 | if (!hdr) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7757 | err = -ENOBUFS; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7758 | goto free_msg; |
| 7759 | } |
| 7760 | |
| 7761 | if (wdev->ps) |
| 7762 | ps_state = NL80211_PS_ENABLED; |
| 7763 | else |
| 7764 | ps_state = NL80211_PS_DISABLED; |
| 7765 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7766 | if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) |
| 7767 | goto nla_put_failure; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7768 | |
| 7769 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7770 | return genlmsg_reply(msg, info); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7771 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7772 | nla_put_failure: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7773 | err = -ENOBUFS; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7774 | free_msg: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7775 | nlmsg_free(msg); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7776 | return err; |
| 7777 | } |
| 7778 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7779 | static struct nla_policy |
| 7780 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = { |
| 7781 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, |
| 7782 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, |
| 7783 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7784 | [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 }, |
| 7785 | [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 }, |
| 7786 | [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7787 | }; |
| 7788 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7789 | static int nl80211_set_cqm_txe(struct genl_info *info, |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 7790 | u32 rate, u32 pkts, u32 intvl) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7791 | { |
| 7792 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7793 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 7794 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7795 | |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 7796 | if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7797 | return -EINVAL; |
| 7798 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7799 | if (!rdev->ops->set_cqm_txe_config) |
| 7800 | return -EOPNOTSUPP; |
| 7801 | |
| 7802 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
| 7803 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7804 | return -EOPNOTSUPP; |
| 7805 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7806 | return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7807 | } |
| 7808 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7809 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
| 7810 | s32 threshold, u32 hysteresis) |
| 7811 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7812 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7813 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 7814 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7815 | |
| 7816 | if (threshold > 0) |
| 7817 | return -EINVAL; |
| 7818 | |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 7819 | /* disabling - hysteresis should also be zero then */ |
| 7820 | if (threshold == 0) |
| 7821 | hysteresis = 0; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7822 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7823 | if (!rdev->ops->set_cqm_rssi_config) |
| 7824 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7825 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7826 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7827 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7828 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7829 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7830 | return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7831 | } |
| 7832 | |
| 7833 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) |
| 7834 | { |
| 7835 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; |
| 7836 | struct nlattr *cqm; |
| 7837 | int err; |
| 7838 | |
| 7839 | cqm = info->attrs[NL80211_ATTR_CQM]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 7840 | if (!cqm) |
| 7841 | return -EINVAL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7842 | |
| 7843 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, |
| 7844 | nl80211_attr_cqm_policy); |
| 7845 | if (err) |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 7846 | return err; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7847 | |
| 7848 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && |
| 7849 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 7850 | s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
| 7851 | u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7852 | |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 7853 | return nl80211_set_cqm_rssi(info, threshold, hysteresis); |
| 7854 | } |
| 7855 | |
| 7856 | if (attrs[NL80211_ATTR_CQM_TXE_RATE] && |
| 7857 | attrs[NL80211_ATTR_CQM_TXE_PKTS] && |
| 7858 | attrs[NL80211_ATTR_CQM_TXE_INTVL]) { |
| 7859 | u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]); |
| 7860 | u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]); |
| 7861 | u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]); |
| 7862 | |
| 7863 | return nl80211_set_cqm_txe(info, rate, pkts, intvl); |
| 7864 | } |
| 7865 | |
| 7866 | return -EINVAL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7867 | } |
| 7868 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7869 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
| 7870 | { |
| 7871 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7872 | struct net_device *dev = info->user_ptr[1]; |
| 7873 | struct mesh_config cfg; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7874 | struct mesh_setup setup; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7875 | int err; |
| 7876 | |
| 7877 | /* start with default */ |
| 7878 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7879 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7880 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 7881 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7882 | /* and parse parameters if given */ |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 7883 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7884 | if (err) |
| 7885 | return err; |
| 7886 | } |
| 7887 | |
| 7888 | if (!info->attrs[NL80211_ATTR_MESH_ID] || |
| 7889 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) |
| 7890 | return -EINVAL; |
| 7891 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7892 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
| 7893 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 7894 | |
Chun-Yeow Yeoh | 4bb6234 | 2011-11-24 17:15:20 -0800 | [diff] [blame] | 7895 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 7896 | !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, |
| 7897 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 7898 | return -EINVAL; |
| 7899 | |
Marco Porsch | 9bdbf04 | 2013-01-07 16:04:51 +0100 | [diff] [blame] | 7900 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 7901 | setup.beacon_interval = |
| 7902 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 7903 | if (setup.beacon_interval < 10 || |
| 7904 | setup.beacon_interval > 10000) |
| 7905 | return -EINVAL; |
| 7906 | } |
| 7907 | |
| 7908 | if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) { |
| 7909 | setup.dtim_period = |
| 7910 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 7911 | if (setup.dtim_period < 1 || setup.dtim_period > 100) |
| 7912 | return -EINVAL; |
| 7913 | } |
| 7914 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7915 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
| 7916 | /* parse additional setup parameters if given */ |
| 7917 | err = nl80211_parse_mesh_setup(info, &setup); |
| 7918 | if (err) |
| 7919 | return err; |
| 7920 | } |
| 7921 | |
Thomas Pedersen | d37bb18 | 2013-03-04 13:06:13 -0800 | [diff] [blame] | 7922 | if (setup.user_mpm) |
| 7923 | cfg.auto_open_plinks = false; |
| 7924 | |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 7925 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7926 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
| 7927 | if (err) |
| 7928 | return err; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 7929 | } else { |
| 7930 | /* cfg80211_join_mesh() will sort it out */ |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7931 | setup.chandef.chan = NULL; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 7932 | } |
| 7933 | |
Ashok Nagarajan | ffb3cf3 | 2013-06-03 10:33:36 -0700 | [diff] [blame] | 7934 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 7935 | u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 7936 | int n_rates = |
| 7937 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 7938 | struct ieee80211_supported_band *sband; |
| 7939 | |
| 7940 | if (!setup.chandef.chan) |
| 7941 | return -EINVAL; |
| 7942 | |
| 7943 | sband = rdev->wiphy.bands[setup.chandef.chan->band]; |
| 7944 | |
| 7945 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 7946 | &setup.basic_rates); |
| 7947 | if (err) |
| 7948 | return err; |
| 7949 | } |
| 7950 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7951 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7952 | } |
| 7953 | |
| 7954 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) |
| 7955 | { |
| 7956 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7957 | struct net_device *dev = info->user_ptr[1]; |
| 7958 | |
| 7959 | return cfg80211_leave_mesh(rdev, dev); |
| 7960 | } |
| 7961 | |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 7962 | #ifdef CONFIG_PM |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7963 | static int nl80211_send_wowlan_patterns(struct sk_buff *msg, |
| 7964 | struct cfg80211_registered_device *rdev) |
| 7965 | { |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7966 | struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config; |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7967 | struct nlattr *nl_pats, *nl_pat; |
| 7968 | int i, pat_len; |
| 7969 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7970 | if (!wowlan->n_patterns) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7971 | return 0; |
| 7972 | |
| 7973 | nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN); |
| 7974 | if (!nl_pats) |
| 7975 | return -ENOBUFS; |
| 7976 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7977 | for (i = 0; i < wowlan->n_patterns; i++) { |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7978 | nl_pat = nla_nest_start(msg, i + 1); |
| 7979 | if (!nl_pat) |
| 7980 | return -ENOBUFS; |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7981 | pat_len = wowlan->patterns[i].pattern_len; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 7982 | 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] | 7983 | wowlan->patterns[i].mask) || |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 7984 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
| 7985 | wowlan->patterns[i].pattern) || |
| 7986 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7987 | wowlan->patterns[i].pkt_offset)) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7988 | return -ENOBUFS; |
| 7989 | nla_nest_end(msg, nl_pat); |
| 7990 | } |
| 7991 | nla_nest_end(msg, nl_pats); |
| 7992 | |
| 7993 | return 0; |
| 7994 | } |
| 7995 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7996 | static int nl80211_send_wowlan_tcp(struct sk_buff *msg, |
| 7997 | struct cfg80211_wowlan_tcp *tcp) |
| 7998 | { |
| 7999 | struct nlattr *nl_tcp; |
| 8000 | |
| 8001 | if (!tcp) |
| 8002 | return 0; |
| 8003 | |
| 8004 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); |
| 8005 | if (!nl_tcp) |
| 8006 | return -ENOBUFS; |
| 8007 | |
| 8008 | if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) || |
| 8009 | nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) || |
| 8010 | nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) || |
| 8011 | nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) || |
| 8012 | nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) || |
| 8013 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 8014 | tcp->payload_len, tcp->payload) || |
| 8015 | nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, |
| 8016 | tcp->data_interval) || |
| 8017 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, |
| 8018 | tcp->wake_len, tcp->wake_data) || |
| 8019 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK, |
| 8020 | DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask)) |
| 8021 | return -ENOBUFS; |
| 8022 | |
| 8023 | if (tcp->payload_seq.len && |
| 8024 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ, |
| 8025 | sizeof(tcp->payload_seq), &tcp->payload_seq)) |
| 8026 | return -ENOBUFS; |
| 8027 | |
| 8028 | if (tcp->payload_tok.len && |
| 8029 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, |
| 8030 | sizeof(tcp->payload_tok) + tcp->tokens_size, |
| 8031 | &tcp->payload_tok)) |
| 8032 | return -ENOBUFS; |
| 8033 | |
Johannes Berg | e248ad3 | 2013-05-16 10:24:28 +0200 | [diff] [blame] | 8034 | nla_nest_end(msg, nl_tcp); |
| 8035 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8036 | return 0; |
| 8037 | } |
| 8038 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8039 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 8040 | { |
| 8041 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8042 | struct sk_buff *msg; |
| 8043 | void *hdr; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8044 | u32 size = NLMSG_DEFAULT_SIZE; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8045 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8046 | if (!rdev->wiphy.wowlan) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8047 | return -EOPNOTSUPP; |
| 8048 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8049 | if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) { |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8050 | /* adjust size to have room for all the data */ |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8051 | size += rdev->wiphy.wowlan_config->tcp->tokens_size + |
| 8052 | rdev->wiphy.wowlan_config->tcp->payload_len + |
| 8053 | rdev->wiphy.wowlan_config->tcp->wake_len + |
| 8054 | rdev->wiphy.wowlan_config->tcp->wake_len / 8; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8055 | } |
| 8056 | |
| 8057 | msg = nlmsg_new(size, GFP_KERNEL); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8058 | if (!msg) |
| 8059 | return -ENOMEM; |
| 8060 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8061 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8062 | NL80211_CMD_GET_WOWLAN); |
| 8063 | if (!hdr) |
| 8064 | goto nla_put_failure; |
| 8065 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8066 | if (rdev->wiphy.wowlan_config) { |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8067 | struct nlattr *nl_wowlan; |
| 8068 | |
| 8069 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
| 8070 | if (!nl_wowlan) |
| 8071 | goto nla_put_failure; |
| 8072 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8073 | if ((rdev->wiphy.wowlan_config->any && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8074 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8075 | (rdev->wiphy.wowlan_config->disconnect && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8076 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8077 | (rdev->wiphy.wowlan_config->magic_pkt && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8078 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8079 | (rdev->wiphy.wowlan_config->gtk_rekey_failure && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8080 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8081 | (rdev->wiphy.wowlan_config->eap_identity_req && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8082 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8083 | (rdev->wiphy.wowlan_config->four_way_handshake && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8084 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8085 | (rdev->wiphy.wowlan_config->rfkill_release && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8086 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 8087 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8088 | |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8089 | if (nl80211_send_wowlan_patterns(msg, rdev)) |
| 8090 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8091 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8092 | if (nl80211_send_wowlan_tcp(msg, |
| 8093 | rdev->wiphy.wowlan_config->tcp)) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8094 | goto nla_put_failure; |
| 8095 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8096 | nla_nest_end(msg, nl_wowlan); |
| 8097 | } |
| 8098 | |
| 8099 | genlmsg_end(msg, hdr); |
| 8100 | return genlmsg_reply(msg, info); |
| 8101 | |
| 8102 | nla_put_failure: |
| 8103 | nlmsg_free(msg); |
| 8104 | return -ENOBUFS; |
| 8105 | } |
| 8106 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8107 | static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev, |
| 8108 | struct nlattr *attr, |
| 8109 | struct cfg80211_wowlan *trig) |
| 8110 | { |
| 8111 | struct nlattr *tb[NUM_NL80211_WOWLAN_TCP]; |
| 8112 | struct cfg80211_wowlan_tcp *cfg; |
| 8113 | struct nl80211_wowlan_tcp_data_token *tok = NULL; |
| 8114 | struct nl80211_wowlan_tcp_data_seq *seq = NULL; |
| 8115 | u32 size; |
| 8116 | u32 data_size, wake_size, tokens_size = 0, wake_mask_size; |
| 8117 | int err, port; |
| 8118 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8119 | if (!rdev->wiphy.wowlan->tcp) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8120 | return -EINVAL; |
| 8121 | |
| 8122 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP, |
| 8123 | nla_data(attr), nla_len(attr), |
| 8124 | nl80211_wowlan_tcp_policy); |
| 8125 | if (err) |
| 8126 | return err; |
| 8127 | |
| 8128 | if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] || |
| 8129 | !tb[NL80211_WOWLAN_TCP_DST_IPV4] || |
| 8130 | !tb[NL80211_WOWLAN_TCP_DST_MAC] || |
| 8131 | !tb[NL80211_WOWLAN_TCP_DST_PORT] || |
| 8132 | !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] || |
| 8133 | !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] || |
| 8134 | !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] || |
| 8135 | !tb[NL80211_WOWLAN_TCP_WAKE_MASK]) |
| 8136 | return -EINVAL; |
| 8137 | |
| 8138 | data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8139 | if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8140 | return -EINVAL; |
| 8141 | |
| 8142 | if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) > |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8143 | rdev->wiphy.wowlan->tcp->data_interval_max || |
Johannes Berg | 723d568 | 2013-02-26 13:56:40 +0100 | [diff] [blame] | 8144 | nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8145 | return -EINVAL; |
| 8146 | |
| 8147 | wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8148 | if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8149 | return -EINVAL; |
| 8150 | |
| 8151 | wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]); |
| 8152 | if (wake_mask_size != DIV_ROUND_UP(wake_size, 8)) |
| 8153 | return -EINVAL; |
| 8154 | |
| 8155 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) { |
| 8156 | u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 8157 | |
| 8158 | tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 8159 | tokens_size = tokln - sizeof(*tok); |
| 8160 | |
| 8161 | if (!tok->len || tokens_size % tok->len) |
| 8162 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8163 | if (!rdev->wiphy.wowlan->tcp->tok) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8164 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8165 | if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8166 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8167 | if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8168 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8169 | if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8170 | return -EINVAL; |
| 8171 | if (tok->offset + tok->len > data_size) |
| 8172 | return -EINVAL; |
| 8173 | } |
| 8174 | |
| 8175 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) { |
| 8176 | seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8177 | if (!rdev->wiphy.wowlan->tcp->seq) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8178 | return -EINVAL; |
| 8179 | if (seq->len == 0 || seq->len > 4) |
| 8180 | return -EINVAL; |
| 8181 | if (seq->len + seq->offset > data_size) |
| 8182 | return -EINVAL; |
| 8183 | } |
| 8184 | |
| 8185 | size = sizeof(*cfg); |
| 8186 | size += data_size; |
| 8187 | size += wake_size + wake_mask_size; |
| 8188 | size += tokens_size; |
| 8189 | |
| 8190 | cfg = kzalloc(size, GFP_KERNEL); |
| 8191 | if (!cfg) |
| 8192 | return -ENOMEM; |
| 8193 | cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]); |
| 8194 | cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]); |
| 8195 | memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]), |
| 8196 | ETH_ALEN); |
| 8197 | if (tb[NL80211_WOWLAN_TCP_SRC_PORT]) |
| 8198 | port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]); |
| 8199 | else |
| 8200 | port = 0; |
| 8201 | #ifdef CONFIG_INET |
| 8202 | /* allocate a socket and port for it and use it */ |
| 8203 | err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM, |
| 8204 | IPPROTO_TCP, &cfg->sock, 1); |
| 8205 | if (err) { |
| 8206 | kfree(cfg); |
| 8207 | return err; |
| 8208 | } |
| 8209 | if (inet_csk_get_port(cfg->sock->sk, port)) { |
| 8210 | sock_release(cfg->sock); |
| 8211 | kfree(cfg); |
| 8212 | return -EADDRINUSE; |
| 8213 | } |
| 8214 | cfg->src_port = inet_sk(cfg->sock->sk)->inet_num; |
| 8215 | #else |
| 8216 | if (!port) { |
| 8217 | kfree(cfg); |
| 8218 | return -EINVAL; |
| 8219 | } |
| 8220 | cfg->src_port = port; |
| 8221 | #endif |
| 8222 | |
| 8223 | cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]); |
| 8224 | cfg->payload_len = data_size; |
| 8225 | cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size; |
| 8226 | memcpy((void *)cfg->payload, |
| 8227 | nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]), |
| 8228 | data_size); |
| 8229 | if (seq) |
| 8230 | cfg->payload_seq = *seq; |
| 8231 | cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]); |
| 8232 | cfg->wake_len = wake_size; |
| 8233 | cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size; |
| 8234 | memcpy((void *)cfg->wake_data, |
| 8235 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]), |
| 8236 | wake_size); |
| 8237 | cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size + |
| 8238 | data_size + wake_size; |
| 8239 | memcpy((void *)cfg->wake_mask, |
| 8240 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]), |
| 8241 | wake_mask_size); |
| 8242 | if (tok) { |
| 8243 | cfg->tokens_size = tokens_size; |
| 8244 | memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size); |
| 8245 | } |
| 8246 | |
| 8247 | trig->tcp = cfg; |
| 8248 | |
| 8249 | return 0; |
| 8250 | } |
| 8251 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8252 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 8253 | { |
| 8254 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8255 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8256 | struct cfg80211_wowlan new_triggers = {}; |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8257 | struct cfg80211_wowlan *ntrig; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8258 | const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8259 | int err, i; |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8260 | bool prev_enabled = rdev->wiphy.wowlan_config; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8261 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8262 | if (!wowlan) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8263 | return -EOPNOTSUPP; |
| 8264 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8265 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) { |
| 8266 | cfg80211_rdev_free_wowlan(rdev); |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8267 | rdev->wiphy.wowlan_config = NULL; |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8268 | goto set_wakeup; |
| 8269 | } |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8270 | |
| 8271 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG, |
| 8272 | nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 8273 | nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 8274 | nl80211_wowlan_policy); |
| 8275 | if (err) |
| 8276 | return err; |
| 8277 | |
| 8278 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { |
| 8279 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) |
| 8280 | return -EINVAL; |
| 8281 | new_triggers.any = true; |
| 8282 | } |
| 8283 | |
| 8284 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { |
| 8285 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) |
| 8286 | return -EINVAL; |
| 8287 | new_triggers.disconnect = true; |
| 8288 | } |
| 8289 | |
| 8290 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { |
| 8291 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) |
| 8292 | return -EINVAL; |
| 8293 | new_triggers.magic_pkt = true; |
| 8294 | } |
| 8295 | |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 8296 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
| 8297 | return -EINVAL; |
| 8298 | |
| 8299 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { |
| 8300 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) |
| 8301 | return -EINVAL; |
| 8302 | new_triggers.gtk_rekey_failure = true; |
| 8303 | } |
| 8304 | |
| 8305 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { |
| 8306 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) |
| 8307 | return -EINVAL; |
| 8308 | new_triggers.eap_identity_req = true; |
| 8309 | } |
| 8310 | |
| 8311 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { |
| 8312 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) |
| 8313 | return -EINVAL; |
| 8314 | new_triggers.four_way_handshake = true; |
| 8315 | } |
| 8316 | |
| 8317 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { |
| 8318 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) |
| 8319 | return -EINVAL; |
| 8320 | new_triggers.rfkill_release = true; |
| 8321 | } |
| 8322 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8323 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
| 8324 | struct nlattr *pat; |
| 8325 | int n_patterns = 0; |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8326 | int rem, pat_len, mask_len, pkt_offset; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8327 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8328 | |
| 8329 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 8330 | rem) |
| 8331 | n_patterns++; |
| 8332 | if (n_patterns > wowlan->n_patterns) |
| 8333 | return -EINVAL; |
| 8334 | |
| 8335 | new_triggers.patterns = kcalloc(n_patterns, |
| 8336 | sizeof(new_triggers.patterns[0]), |
| 8337 | GFP_KERNEL); |
| 8338 | if (!new_triggers.patterns) |
| 8339 | return -ENOMEM; |
| 8340 | |
| 8341 | new_triggers.n_patterns = n_patterns; |
| 8342 | i = 0; |
| 8343 | |
| 8344 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 8345 | rem) { |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8346 | nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat), |
| 8347 | nla_len(pat), NULL); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8348 | err = -EINVAL; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8349 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
| 8350 | !pat_tb[NL80211_PKTPAT_PATTERN]) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8351 | goto error; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8352 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8353 | mask_len = DIV_ROUND_UP(pat_len, 8); |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8354 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8355 | goto error; |
| 8356 | if (pat_len > wowlan->pattern_max_len || |
| 8357 | pat_len < wowlan->pattern_min_len) |
| 8358 | goto error; |
| 8359 | |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8360 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8361 | pkt_offset = 0; |
| 8362 | else |
| 8363 | pkt_offset = nla_get_u32( |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8364 | pat_tb[NL80211_PKTPAT_OFFSET]); |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8365 | if (pkt_offset > wowlan->max_pkt_offset) |
| 8366 | goto error; |
| 8367 | new_triggers.patterns[i].pkt_offset = pkt_offset; |
| 8368 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8369 | new_triggers.patterns[i].mask = |
| 8370 | kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 8371 | if (!new_triggers.patterns[i].mask) { |
| 8372 | err = -ENOMEM; |
| 8373 | goto error; |
| 8374 | } |
| 8375 | new_triggers.patterns[i].pattern = |
| 8376 | new_triggers.patterns[i].mask + mask_len; |
| 8377 | memcpy(new_triggers.patterns[i].mask, |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8378 | nla_data(pat_tb[NL80211_PKTPAT_MASK]), |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8379 | mask_len); |
| 8380 | new_triggers.patterns[i].pattern_len = pat_len; |
| 8381 | memcpy(new_triggers.patterns[i].pattern, |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8382 | nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8383 | pat_len); |
| 8384 | i++; |
| 8385 | } |
| 8386 | } |
| 8387 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8388 | if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) { |
| 8389 | err = nl80211_parse_wowlan_tcp( |
| 8390 | rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION], |
| 8391 | &new_triggers); |
| 8392 | if (err) |
| 8393 | goto error; |
| 8394 | } |
| 8395 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8396 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL); |
| 8397 | if (!ntrig) { |
| 8398 | err = -ENOMEM; |
| 8399 | goto error; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8400 | } |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8401 | cfg80211_rdev_free_wowlan(rdev); |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8402 | rdev->wiphy.wowlan_config = ntrig; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8403 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8404 | set_wakeup: |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8405 | if (rdev->ops->set_wakeup && |
| 8406 | prev_enabled != !!rdev->wiphy.wowlan_config) |
| 8407 | rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config); |
Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame] | 8408 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8409 | return 0; |
| 8410 | error: |
| 8411 | for (i = 0; i < new_triggers.n_patterns; i++) |
| 8412 | kfree(new_triggers.patterns[i].mask); |
| 8413 | kfree(new_triggers.patterns); |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8414 | if (new_triggers.tcp && new_triggers.tcp->sock) |
| 8415 | sock_release(new_triggers.tcp->sock); |
| 8416 | kfree(new_triggers.tcp); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8417 | return err; |
| 8418 | } |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 8419 | #endif |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8420 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 8421 | static int nl80211_send_coalesce_rules(struct sk_buff *msg, |
| 8422 | struct cfg80211_registered_device *rdev) |
| 8423 | { |
| 8424 | struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules; |
| 8425 | int i, j, pat_len; |
| 8426 | struct cfg80211_coalesce_rules *rule; |
| 8427 | |
| 8428 | if (!rdev->coalesce->n_rules) |
| 8429 | return 0; |
| 8430 | |
| 8431 | nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE); |
| 8432 | if (!nl_rules) |
| 8433 | return -ENOBUFS; |
| 8434 | |
| 8435 | for (i = 0; i < rdev->coalesce->n_rules; i++) { |
| 8436 | nl_rule = nla_nest_start(msg, i + 1); |
| 8437 | if (!nl_rule) |
| 8438 | return -ENOBUFS; |
| 8439 | |
| 8440 | rule = &rdev->coalesce->rules[i]; |
| 8441 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY, |
| 8442 | rule->delay)) |
| 8443 | return -ENOBUFS; |
| 8444 | |
| 8445 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION, |
| 8446 | rule->condition)) |
| 8447 | return -ENOBUFS; |
| 8448 | |
| 8449 | nl_pats = nla_nest_start(msg, |
| 8450 | NL80211_ATTR_COALESCE_RULE_PKT_PATTERN); |
| 8451 | if (!nl_pats) |
| 8452 | return -ENOBUFS; |
| 8453 | |
| 8454 | for (j = 0; j < rule->n_patterns; j++) { |
| 8455 | nl_pat = nla_nest_start(msg, j + 1); |
| 8456 | if (!nl_pat) |
| 8457 | return -ENOBUFS; |
| 8458 | pat_len = rule->patterns[j].pattern_len; |
| 8459 | if (nla_put(msg, NL80211_PKTPAT_MASK, |
| 8460 | DIV_ROUND_UP(pat_len, 8), |
| 8461 | rule->patterns[j].mask) || |
| 8462 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
| 8463 | rule->patterns[j].pattern) || |
| 8464 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, |
| 8465 | rule->patterns[j].pkt_offset)) |
| 8466 | return -ENOBUFS; |
| 8467 | nla_nest_end(msg, nl_pat); |
| 8468 | } |
| 8469 | nla_nest_end(msg, nl_pats); |
| 8470 | nla_nest_end(msg, nl_rule); |
| 8471 | } |
| 8472 | nla_nest_end(msg, nl_rules); |
| 8473 | |
| 8474 | return 0; |
| 8475 | } |
| 8476 | |
| 8477 | static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info) |
| 8478 | { |
| 8479 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8480 | struct sk_buff *msg; |
| 8481 | void *hdr; |
| 8482 | |
| 8483 | if (!rdev->wiphy.coalesce) |
| 8484 | return -EOPNOTSUPP; |
| 8485 | |
| 8486 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 8487 | if (!msg) |
| 8488 | return -ENOMEM; |
| 8489 | |
| 8490 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 8491 | NL80211_CMD_GET_COALESCE); |
| 8492 | if (!hdr) |
| 8493 | goto nla_put_failure; |
| 8494 | |
| 8495 | if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev)) |
| 8496 | goto nla_put_failure; |
| 8497 | |
| 8498 | genlmsg_end(msg, hdr); |
| 8499 | return genlmsg_reply(msg, info); |
| 8500 | |
| 8501 | nla_put_failure: |
| 8502 | nlmsg_free(msg); |
| 8503 | return -ENOBUFS; |
| 8504 | } |
| 8505 | |
| 8506 | void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev) |
| 8507 | { |
| 8508 | struct cfg80211_coalesce *coalesce = rdev->coalesce; |
| 8509 | int i, j; |
| 8510 | struct cfg80211_coalesce_rules *rule; |
| 8511 | |
| 8512 | if (!coalesce) |
| 8513 | return; |
| 8514 | |
| 8515 | for (i = 0; i < coalesce->n_rules; i++) { |
| 8516 | rule = &coalesce->rules[i]; |
| 8517 | for (j = 0; j < rule->n_patterns; j++) |
| 8518 | kfree(rule->patterns[j].mask); |
| 8519 | kfree(rule->patterns); |
| 8520 | } |
| 8521 | kfree(coalesce->rules); |
| 8522 | kfree(coalesce); |
| 8523 | rdev->coalesce = NULL; |
| 8524 | } |
| 8525 | |
| 8526 | static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev, |
| 8527 | struct nlattr *rule, |
| 8528 | struct cfg80211_coalesce_rules *new_rule) |
| 8529 | { |
| 8530 | int err, i; |
| 8531 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; |
| 8532 | struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat; |
| 8533 | int rem, pat_len, mask_len, pkt_offset, n_patterns = 0; |
| 8534 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
| 8535 | |
| 8536 | err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule), |
| 8537 | nla_len(rule), nl80211_coalesce_policy); |
| 8538 | if (err) |
| 8539 | return err; |
| 8540 | |
| 8541 | if (tb[NL80211_ATTR_COALESCE_RULE_DELAY]) |
| 8542 | new_rule->delay = |
| 8543 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]); |
| 8544 | if (new_rule->delay > coalesce->max_delay) |
| 8545 | return -EINVAL; |
| 8546 | |
| 8547 | if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION]) |
| 8548 | new_rule->condition = |
| 8549 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]); |
| 8550 | if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH && |
| 8551 | new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH) |
| 8552 | return -EINVAL; |
| 8553 | |
| 8554 | if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN]) |
| 8555 | return -EINVAL; |
| 8556 | |
| 8557 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], |
| 8558 | rem) |
| 8559 | n_patterns++; |
| 8560 | if (n_patterns > coalesce->n_patterns) |
| 8561 | return -EINVAL; |
| 8562 | |
| 8563 | new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]), |
| 8564 | GFP_KERNEL); |
| 8565 | if (!new_rule->patterns) |
| 8566 | return -ENOMEM; |
| 8567 | |
| 8568 | new_rule->n_patterns = n_patterns; |
| 8569 | i = 0; |
| 8570 | |
| 8571 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], |
| 8572 | rem) { |
| 8573 | nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat), |
| 8574 | nla_len(pat), NULL); |
| 8575 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
| 8576 | !pat_tb[NL80211_PKTPAT_PATTERN]) |
| 8577 | return -EINVAL; |
| 8578 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
| 8579 | mask_len = DIV_ROUND_UP(pat_len, 8); |
| 8580 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
| 8581 | return -EINVAL; |
| 8582 | if (pat_len > coalesce->pattern_max_len || |
| 8583 | pat_len < coalesce->pattern_min_len) |
| 8584 | return -EINVAL; |
| 8585 | |
| 8586 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
| 8587 | pkt_offset = 0; |
| 8588 | else |
| 8589 | pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]); |
| 8590 | if (pkt_offset > coalesce->max_pkt_offset) |
| 8591 | return -EINVAL; |
| 8592 | new_rule->patterns[i].pkt_offset = pkt_offset; |
| 8593 | |
| 8594 | new_rule->patterns[i].mask = |
| 8595 | kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 8596 | if (!new_rule->patterns[i].mask) |
| 8597 | return -ENOMEM; |
| 8598 | new_rule->patterns[i].pattern = |
| 8599 | new_rule->patterns[i].mask + mask_len; |
| 8600 | memcpy(new_rule->patterns[i].mask, |
| 8601 | nla_data(pat_tb[NL80211_PKTPAT_MASK]), mask_len); |
| 8602 | new_rule->patterns[i].pattern_len = pat_len; |
| 8603 | memcpy(new_rule->patterns[i].pattern, |
| 8604 | nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), pat_len); |
| 8605 | i++; |
| 8606 | } |
| 8607 | |
| 8608 | return 0; |
| 8609 | } |
| 8610 | |
| 8611 | static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info) |
| 8612 | { |
| 8613 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8614 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; |
| 8615 | struct cfg80211_coalesce new_coalesce = {}; |
| 8616 | struct cfg80211_coalesce *n_coalesce; |
| 8617 | int err, rem_rule, n_rules = 0, i, j; |
| 8618 | struct nlattr *rule; |
| 8619 | struct cfg80211_coalesce_rules *tmp_rule; |
| 8620 | |
| 8621 | if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce) |
| 8622 | return -EOPNOTSUPP; |
| 8623 | |
| 8624 | if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) { |
| 8625 | cfg80211_rdev_free_coalesce(rdev); |
| 8626 | rdev->ops->set_coalesce(&rdev->wiphy, NULL); |
| 8627 | return 0; |
| 8628 | } |
| 8629 | |
| 8630 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], |
| 8631 | rem_rule) |
| 8632 | n_rules++; |
| 8633 | if (n_rules > coalesce->n_rules) |
| 8634 | return -EINVAL; |
| 8635 | |
| 8636 | new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]), |
| 8637 | GFP_KERNEL); |
| 8638 | if (!new_coalesce.rules) |
| 8639 | return -ENOMEM; |
| 8640 | |
| 8641 | new_coalesce.n_rules = n_rules; |
| 8642 | i = 0; |
| 8643 | |
| 8644 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], |
| 8645 | rem_rule) { |
| 8646 | err = nl80211_parse_coalesce_rule(rdev, rule, |
| 8647 | &new_coalesce.rules[i]); |
| 8648 | if (err) |
| 8649 | goto error; |
| 8650 | |
| 8651 | i++; |
| 8652 | } |
| 8653 | |
| 8654 | err = rdev->ops->set_coalesce(&rdev->wiphy, &new_coalesce); |
| 8655 | if (err) |
| 8656 | goto error; |
| 8657 | |
| 8658 | n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL); |
| 8659 | if (!n_coalesce) { |
| 8660 | err = -ENOMEM; |
| 8661 | goto error; |
| 8662 | } |
| 8663 | cfg80211_rdev_free_coalesce(rdev); |
| 8664 | rdev->coalesce = n_coalesce; |
| 8665 | |
| 8666 | return 0; |
| 8667 | error: |
| 8668 | for (i = 0; i < new_coalesce.n_rules; i++) { |
| 8669 | tmp_rule = &new_coalesce.rules[i]; |
| 8670 | for (j = 0; j < tmp_rule->n_patterns; j++) |
| 8671 | kfree(tmp_rule->patterns[j].mask); |
| 8672 | kfree(tmp_rule->patterns); |
| 8673 | } |
| 8674 | kfree(new_coalesce.rules); |
| 8675 | |
| 8676 | return err; |
| 8677 | } |
| 8678 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 8679 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
| 8680 | { |
| 8681 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8682 | struct net_device *dev = info->user_ptr[1]; |
| 8683 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 8684 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; |
| 8685 | struct cfg80211_gtk_rekey_data rekey_data; |
| 8686 | int err; |
| 8687 | |
| 8688 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) |
| 8689 | return -EINVAL; |
| 8690 | |
| 8691 | err = nla_parse(tb, MAX_NL80211_REKEY_DATA, |
| 8692 | nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 8693 | nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 8694 | nl80211_rekey_policy); |
| 8695 | if (err) |
| 8696 | return err; |
| 8697 | |
| 8698 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) |
| 8699 | return -ERANGE; |
| 8700 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) |
| 8701 | return -ERANGE; |
| 8702 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) |
| 8703 | return -ERANGE; |
| 8704 | |
| 8705 | memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]), |
| 8706 | NL80211_KEK_LEN); |
| 8707 | memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]), |
| 8708 | NL80211_KCK_LEN); |
| 8709 | memcpy(rekey_data.replay_ctr, |
| 8710 | nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]), |
| 8711 | NL80211_REPLAY_CTR_LEN); |
| 8712 | |
| 8713 | wdev_lock(wdev); |
| 8714 | if (!wdev->current_bss) { |
| 8715 | err = -ENOTCONN; |
| 8716 | goto out; |
| 8717 | } |
| 8718 | |
| 8719 | if (!rdev->ops->set_rekey_data) { |
| 8720 | err = -EOPNOTSUPP; |
| 8721 | goto out; |
| 8722 | } |
| 8723 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8724 | err = rdev_set_rekey_data(rdev, dev, &rekey_data); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 8725 | out: |
| 8726 | wdev_unlock(wdev); |
| 8727 | return err; |
| 8728 | } |
| 8729 | |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8730 | static int nl80211_register_unexpected_frame(struct sk_buff *skb, |
| 8731 | struct genl_info *info) |
| 8732 | { |
| 8733 | struct net_device *dev = info->user_ptr[1]; |
| 8734 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 8735 | |
| 8736 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 8737 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 8738 | return -EINVAL; |
| 8739 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8740 | if (wdev->ap_unexpected_nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8741 | return -EBUSY; |
| 8742 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8743 | wdev->ap_unexpected_nlportid = info->snd_portid; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8744 | return 0; |
| 8745 | } |
| 8746 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8747 | static int nl80211_probe_client(struct sk_buff *skb, |
| 8748 | struct genl_info *info) |
| 8749 | { |
| 8750 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8751 | struct net_device *dev = info->user_ptr[1]; |
| 8752 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 8753 | struct sk_buff *msg; |
| 8754 | void *hdr; |
| 8755 | const u8 *addr; |
| 8756 | u64 cookie; |
| 8757 | int err; |
| 8758 | |
| 8759 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 8760 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 8761 | return -EOPNOTSUPP; |
| 8762 | |
| 8763 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 8764 | return -EINVAL; |
| 8765 | |
| 8766 | if (!rdev->ops->probe_client) |
| 8767 | return -EOPNOTSUPP; |
| 8768 | |
| 8769 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 8770 | if (!msg) |
| 8771 | return -ENOMEM; |
| 8772 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8773 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8774 | NL80211_CMD_PROBE_CLIENT); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 8775 | if (!hdr) { |
| 8776 | err = -ENOBUFS; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8777 | goto free_msg; |
| 8778 | } |
| 8779 | |
| 8780 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 8781 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8782 | err = rdev_probe_client(rdev, dev, addr, &cookie); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8783 | if (err) |
| 8784 | goto free_msg; |
| 8785 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8786 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 8787 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8788 | |
| 8789 | genlmsg_end(msg, hdr); |
| 8790 | |
| 8791 | return genlmsg_reply(msg, info); |
| 8792 | |
| 8793 | nla_put_failure: |
| 8794 | err = -ENOBUFS; |
| 8795 | free_msg: |
| 8796 | nlmsg_free(msg); |
| 8797 | return err; |
| 8798 | } |
| 8799 | |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8800 | static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) |
| 8801 | { |
| 8802 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 8803 | struct cfg80211_beacon_registration *reg, *nreg; |
| 8804 | int rv; |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8805 | |
| 8806 | if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) |
| 8807 | return -EOPNOTSUPP; |
| 8808 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 8809 | nreg = kzalloc(sizeof(*nreg), GFP_KERNEL); |
| 8810 | if (!nreg) |
| 8811 | return -ENOMEM; |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8812 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 8813 | /* First, check if already registered. */ |
| 8814 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 8815 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 8816 | if (reg->nlportid == info->snd_portid) { |
| 8817 | rv = -EALREADY; |
| 8818 | goto out_err; |
| 8819 | } |
| 8820 | } |
| 8821 | /* Add it to the list */ |
| 8822 | nreg->nlportid = info->snd_portid; |
| 8823 | list_add(&nreg->list, &rdev->beacon_registrations); |
| 8824 | |
| 8825 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8826 | |
| 8827 | return 0; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 8828 | out_err: |
| 8829 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 8830 | kfree(nreg); |
| 8831 | return rv; |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8832 | } |
| 8833 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8834 | static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 8835 | { |
| 8836 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8837 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 8838 | int err; |
| 8839 | |
| 8840 | if (!rdev->ops->start_p2p_device) |
| 8841 | return -EOPNOTSUPP; |
| 8842 | |
| 8843 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 8844 | return -EOPNOTSUPP; |
| 8845 | |
| 8846 | if (wdev->p2p_started) |
| 8847 | return 0; |
| 8848 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8849 | err = cfg80211_can_add_interface(rdev, wdev->iftype); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8850 | if (err) |
| 8851 | return err; |
| 8852 | |
Johannes Berg | eeb126e | 2012-10-23 15:16:50 +0200 | [diff] [blame] | 8853 | err = rdev_start_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8854 | if (err) |
| 8855 | return err; |
| 8856 | |
| 8857 | wdev->p2p_started = true; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8858 | rdev->opencount++; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8859 | |
| 8860 | return 0; |
| 8861 | } |
| 8862 | |
| 8863 | static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 8864 | { |
| 8865 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8866 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 8867 | |
| 8868 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 8869 | return -EOPNOTSUPP; |
| 8870 | |
| 8871 | if (!rdev->ops->stop_p2p_device) |
| 8872 | return -EOPNOTSUPP; |
| 8873 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 8874 | cfg80211_stop_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8875 | |
| 8876 | return 0; |
| 8877 | } |
| 8878 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 8879 | static int nl80211_get_protocol_features(struct sk_buff *skb, |
| 8880 | struct genl_info *info) |
| 8881 | { |
| 8882 | void *hdr; |
| 8883 | struct sk_buff *msg; |
| 8884 | |
| 8885 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 8886 | if (!msg) |
| 8887 | return -ENOMEM; |
| 8888 | |
| 8889 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 8890 | NL80211_CMD_GET_PROTOCOL_FEATURES); |
| 8891 | if (!hdr) |
| 8892 | goto nla_put_failure; |
| 8893 | |
| 8894 | if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES, |
| 8895 | NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)) |
| 8896 | goto nla_put_failure; |
| 8897 | |
| 8898 | genlmsg_end(msg, hdr); |
| 8899 | return genlmsg_reply(msg, info); |
| 8900 | |
| 8901 | nla_put_failure: |
| 8902 | kfree_skb(msg); |
| 8903 | return -ENOBUFS; |
| 8904 | } |
| 8905 | |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 8906 | static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info) |
| 8907 | { |
| 8908 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8909 | struct cfg80211_update_ft_ies_params ft_params; |
| 8910 | struct net_device *dev = info->user_ptr[1]; |
| 8911 | |
| 8912 | if (!rdev->ops->update_ft_ies) |
| 8913 | return -EOPNOTSUPP; |
| 8914 | |
| 8915 | if (!info->attrs[NL80211_ATTR_MDID] || |
| 8916 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 8917 | return -EINVAL; |
| 8918 | |
| 8919 | memset(&ft_params, 0, sizeof(ft_params)); |
| 8920 | ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]); |
| 8921 | ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 8922 | ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 8923 | |
| 8924 | return rdev_update_ft_ies(rdev, dev, &ft_params); |
| 8925 | } |
| 8926 | |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 8927 | static int nl80211_crit_protocol_start(struct sk_buff *skb, |
| 8928 | struct genl_info *info) |
| 8929 | { |
| 8930 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8931 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 8932 | enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC; |
| 8933 | u16 duration; |
| 8934 | int ret; |
| 8935 | |
| 8936 | if (!rdev->ops->crit_proto_start) |
| 8937 | return -EOPNOTSUPP; |
| 8938 | |
| 8939 | if (WARN_ON(!rdev->ops->crit_proto_stop)) |
| 8940 | return -EINVAL; |
| 8941 | |
| 8942 | if (rdev->crit_proto_nlportid) |
| 8943 | return -EBUSY; |
| 8944 | |
| 8945 | /* determine protocol if provided */ |
| 8946 | if (info->attrs[NL80211_ATTR_CRIT_PROT_ID]) |
| 8947 | proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]); |
| 8948 | |
| 8949 | if (proto >= NUM_NL80211_CRIT_PROTO) |
| 8950 | return -EINVAL; |
| 8951 | |
| 8952 | /* timeout must be provided */ |
| 8953 | if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]) |
| 8954 | return -EINVAL; |
| 8955 | |
| 8956 | duration = |
| 8957 | nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]); |
| 8958 | |
| 8959 | if (duration > NL80211_CRIT_PROTO_MAX_DURATION) |
| 8960 | return -ERANGE; |
| 8961 | |
| 8962 | ret = rdev_crit_proto_start(rdev, wdev, proto, duration); |
| 8963 | if (!ret) |
| 8964 | rdev->crit_proto_nlportid = info->snd_portid; |
| 8965 | |
| 8966 | return ret; |
| 8967 | } |
| 8968 | |
| 8969 | static int nl80211_crit_protocol_stop(struct sk_buff *skb, |
| 8970 | struct genl_info *info) |
| 8971 | { |
| 8972 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8973 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 8974 | |
| 8975 | if (!rdev->ops->crit_proto_stop) |
| 8976 | return -EOPNOTSUPP; |
| 8977 | |
| 8978 | if (rdev->crit_proto_nlportid) { |
| 8979 | rdev->crit_proto_nlportid = 0; |
| 8980 | rdev_crit_proto_stop(rdev, wdev); |
| 8981 | } |
| 8982 | return 0; |
| 8983 | } |
| 8984 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 8985 | static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info) |
| 8986 | { |
| 8987 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8988 | struct wireless_dev *wdev = |
| 8989 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); |
| 8990 | int i, err; |
| 8991 | u32 vid, subcmd; |
| 8992 | |
| 8993 | if (!rdev->wiphy.vendor_commands) |
| 8994 | return -EOPNOTSUPP; |
| 8995 | |
| 8996 | if (IS_ERR(wdev)) { |
| 8997 | err = PTR_ERR(wdev); |
| 8998 | if (err != -EINVAL) |
| 8999 | return err; |
| 9000 | wdev = NULL; |
| 9001 | } else if (wdev->wiphy != &rdev->wiphy) { |
| 9002 | return -EINVAL; |
| 9003 | } |
| 9004 | |
| 9005 | if (!info->attrs[NL80211_ATTR_VENDOR_ID] || |
| 9006 | !info->attrs[NL80211_ATTR_VENDOR_SUBCMD]) |
| 9007 | return -EINVAL; |
| 9008 | |
| 9009 | vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]); |
| 9010 | subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]); |
| 9011 | for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { |
| 9012 | const struct wiphy_vendor_command *vcmd; |
| 9013 | void *data = NULL; |
| 9014 | int len = 0; |
| 9015 | |
| 9016 | vcmd = &rdev->wiphy.vendor_commands[i]; |
| 9017 | |
| 9018 | if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd) |
| 9019 | continue; |
| 9020 | |
| 9021 | if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV | |
| 9022 | WIPHY_VENDOR_CMD_NEED_NETDEV)) { |
| 9023 | if (!wdev) |
| 9024 | return -EINVAL; |
| 9025 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV && |
| 9026 | !wdev->netdev) |
| 9027 | return -EINVAL; |
| 9028 | |
| 9029 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) { |
| 9030 | if (wdev->netdev && |
| 9031 | !netif_running(wdev->netdev)) |
| 9032 | return -ENETDOWN; |
| 9033 | if (!wdev->netdev && !wdev->p2p_started) |
| 9034 | return -ENETDOWN; |
| 9035 | } |
| 9036 | } else { |
| 9037 | wdev = NULL; |
| 9038 | } |
| 9039 | |
| 9040 | if (info->attrs[NL80211_ATTR_VENDOR_DATA]) { |
| 9041 | data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]); |
| 9042 | len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]); |
| 9043 | } |
| 9044 | |
| 9045 | rdev->cur_cmd_info = info; |
| 9046 | err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev, |
| 9047 | data, len); |
| 9048 | rdev->cur_cmd_info = NULL; |
| 9049 | return err; |
| 9050 | } |
| 9051 | |
| 9052 | return -EOPNOTSUPP; |
| 9053 | } |
| 9054 | |
| 9055 | struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy, |
| 9056 | enum nl80211_commands cmd, |
| 9057 | enum nl80211_attrs attr, |
| 9058 | int approxlen) |
| 9059 | { |
| 9060 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 9061 | |
| 9062 | if (WARN_ON(!rdev->cur_cmd_info)) |
| 9063 | return NULL; |
| 9064 | |
| 9065 | return __cfg80211_alloc_vendor_skb(rdev, approxlen, |
| 9066 | rdev->cur_cmd_info->snd_portid, |
| 9067 | rdev->cur_cmd_info->snd_seq, |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 9068 | cmd, attr, NULL, GFP_KERNEL); |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 9069 | } |
| 9070 | EXPORT_SYMBOL(__cfg80211_alloc_reply_skb); |
| 9071 | |
| 9072 | int cfg80211_vendor_cmd_reply(struct sk_buff *skb) |
| 9073 | { |
| 9074 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 9075 | void *hdr = ((void **)skb->cb)[1]; |
| 9076 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 9077 | |
| 9078 | if (WARN_ON(!rdev->cur_cmd_info)) { |
| 9079 | kfree_skb(skb); |
| 9080 | return -EINVAL; |
| 9081 | } |
| 9082 | |
| 9083 | nla_nest_end(skb, data); |
| 9084 | genlmsg_end(skb, hdr); |
| 9085 | return genlmsg_reply(skb, rdev->cur_cmd_info); |
| 9086 | } |
| 9087 | EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply); |
| 9088 | |
| 9089 | |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 9090 | static int nl80211_set_qos_map(struct sk_buff *skb, |
| 9091 | struct genl_info *info) |
| 9092 | { |
| 9093 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9094 | struct cfg80211_qos_map *qos_map = NULL; |
| 9095 | struct net_device *dev = info->user_ptr[1]; |
| 9096 | u8 *pos, len, num_des, des_len, des; |
| 9097 | int ret; |
| 9098 | |
| 9099 | if (!rdev->ops->set_qos_map) |
| 9100 | return -EOPNOTSUPP; |
| 9101 | |
| 9102 | if (info->attrs[NL80211_ATTR_QOS_MAP]) { |
| 9103 | pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]); |
| 9104 | len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]); |
| 9105 | |
| 9106 | if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN || |
| 9107 | len > IEEE80211_QOS_MAP_LEN_MAX) |
| 9108 | return -EINVAL; |
| 9109 | |
| 9110 | qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL); |
| 9111 | if (!qos_map) |
| 9112 | return -ENOMEM; |
| 9113 | |
| 9114 | num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1; |
| 9115 | if (num_des) { |
| 9116 | des_len = num_des * |
| 9117 | sizeof(struct cfg80211_dscp_exception); |
| 9118 | memcpy(qos_map->dscp_exception, pos, des_len); |
| 9119 | qos_map->num_des = num_des; |
| 9120 | for (des = 0; des < num_des; des++) { |
| 9121 | if (qos_map->dscp_exception[des].up > 7) { |
| 9122 | kfree(qos_map); |
| 9123 | return -EINVAL; |
| 9124 | } |
| 9125 | } |
| 9126 | pos += des_len; |
| 9127 | } |
| 9128 | memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN); |
| 9129 | } |
| 9130 | |
| 9131 | wdev_lock(dev->ieee80211_ptr); |
| 9132 | ret = nl80211_key_allowed(dev->ieee80211_ptr); |
| 9133 | if (!ret) |
| 9134 | ret = rdev_set_qos_map(rdev, dev, qos_map); |
| 9135 | wdev_unlock(dev->ieee80211_ptr); |
| 9136 | |
| 9137 | kfree(qos_map); |
| 9138 | return ret; |
| 9139 | } |
| 9140 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9141 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
| 9142 | #define NL80211_FLAG_NEED_NETDEV 0x02 |
| 9143 | #define NL80211_FLAG_NEED_RTNL 0x04 |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9144 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
| 9145 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ |
| 9146 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 9147 | #define NL80211_FLAG_NEED_WDEV 0x10 |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9148 | /* 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] | 9149 | #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\ |
| 9150 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9151 | |
Johannes Berg | f84f771 | 2013-11-14 17:14:45 +0100 | [diff] [blame] | 9152 | 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] | 9153 | struct genl_info *info) |
| 9154 | { |
| 9155 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 9156 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9157 | struct net_device *dev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9158 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
| 9159 | |
| 9160 | if (rtnl) |
| 9161 | rtnl_lock(); |
| 9162 | |
| 9163 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 9164 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9165 | if (IS_ERR(rdev)) { |
| 9166 | if (rtnl) |
| 9167 | rtnl_unlock(); |
| 9168 | return PTR_ERR(rdev); |
| 9169 | } |
| 9170 | info->user_ptr[0] = rdev; |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 9171 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV || |
| 9172 | ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 9173 | ASSERT_RTNL(); |
| 9174 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 9175 | wdev = __cfg80211_wdev_from_attrs(genl_info_net(info), |
| 9176 | info->attrs); |
| 9177 | if (IS_ERR(wdev)) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9178 | if (rtnl) |
| 9179 | rtnl_unlock(); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 9180 | return PTR_ERR(wdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9181 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 9182 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 9183 | dev = wdev->netdev; |
| 9184 | rdev = wiphy_to_dev(wdev->wiphy); |
| 9185 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 9186 | if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
| 9187 | if (!dev) { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 9188 | if (rtnl) |
| 9189 | rtnl_unlock(); |
| 9190 | return -EINVAL; |
| 9191 | } |
| 9192 | |
| 9193 | info->user_ptr[1] = dev; |
| 9194 | } else { |
| 9195 | info->user_ptr[1] = wdev; |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9196 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 9197 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 9198 | if (dev) { |
| 9199 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && |
| 9200 | !netif_running(dev)) { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 9201 | if (rtnl) |
| 9202 | rtnl_unlock(); |
| 9203 | return -ENETDOWN; |
| 9204 | } |
| 9205 | |
| 9206 | dev_hold(dev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9207 | } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) { |
| 9208 | if (!wdev->p2p_started) { |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9209 | if (rtnl) |
| 9210 | rtnl_unlock(); |
| 9211 | return -ENETDOWN; |
| 9212 | } |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 9213 | } |
| 9214 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9215 | info->user_ptr[0] = rdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9216 | } |
| 9217 | |
| 9218 | return 0; |
| 9219 | } |
| 9220 | |
Johannes Berg | f84f771 | 2013-11-14 17:14:45 +0100 | [diff] [blame] | 9221 | 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] | 9222 | struct genl_info *info) |
| 9223 | { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 9224 | if (info->user_ptr[1]) { |
| 9225 | if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
| 9226 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 9227 | |
| 9228 | if (wdev->netdev) |
| 9229 | dev_put(wdev->netdev); |
| 9230 | } else { |
| 9231 | dev_put(info->user_ptr[1]); |
| 9232 | } |
| 9233 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9234 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
| 9235 | rtnl_unlock(); |
| 9236 | } |
| 9237 | |
Johannes Berg | 4534de8 | 2013-11-14 17:14:46 +0100 | [diff] [blame] | 9238 | static const struct genl_ops nl80211_ops[] = { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9239 | { |
| 9240 | .cmd = NL80211_CMD_GET_WIPHY, |
| 9241 | .doit = nl80211_get_wiphy, |
| 9242 | .dumpit = nl80211_dump_wiphy, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 9243 | .done = nl80211_dump_wiphy_done, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9244 | .policy = nl80211_policy, |
| 9245 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 9246 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9247 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9248 | }, |
| 9249 | { |
| 9250 | .cmd = NL80211_CMD_SET_WIPHY, |
| 9251 | .doit = nl80211_set_wiphy, |
| 9252 | .policy = nl80211_policy, |
| 9253 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9254 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9255 | }, |
| 9256 | { |
| 9257 | .cmd = NL80211_CMD_GET_INTERFACE, |
| 9258 | .doit = nl80211_get_interface, |
| 9259 | .dumpit = nl80211_dump_interface, |
| 9260 | .policy = nl80211_policy, |
| 9261 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 9262 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 9263 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9264 | }, |
| 9265 | { |
| 9266 | .cmd = NL80211_CMD_SET_INTERFACE, |
| 9267 | .doit = nl80211_set_interface, |
| 9268 | .policy = nl80211_policy, |
| 9269 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9270 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9271 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9272 | }, |
| 9273 | { |
| 9274 | .cmd = NL80211_CMD_NEW_INTERFACE, |
| 9275 | .doit = nl80211_new_interface, |
| 9276 | .policy = nl80211_policy, |
| 9277 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9278 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9279 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9280 | }, |
| 9281 | { |
| 9282 | .cmd = NL80211_CMD_DEL_INTERFACE, |
| 9283 | .doit = nl80211_del_interface, |
| 9284 | .policy = nl80211_policy, |
| 9285 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 9286 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9287 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9288 | }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 9289 | { |
| 9290 | .cmd = NL80211_CMD_GET_KEY, |
| 9291 | .doit = nl80211_get_key, |
| 9292 | .policy = nl80211_policy, |
| 9293 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9294 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9295 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 9296 | }, |
| 9297 | { |
| 9298 | .cmd = NL80211_CMD_SET_KEY, |
| 9299 | .doit = nl80211_set_key, |
| 9300 | .policy = nl80211_policy, |
| 9301 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9302 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9303 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 9304 | }, |
| 9305 | { |
| 9306 | .cmd = NL80211_CMD_NEW_KEY, |
| 9307 | .doit = nl80211_new_key, |
| 9308 | .policy = nl80211_policy, |
| 9309 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9310 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9311 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 9312 | }, |
| 9313 | { |
| 9314 | .cmd = NL80211_CMD_DEL_KEY, |
| 9315 | .doit = nl80211_del_key, |
| 9316 | .policy = nl80211_policy, |
| 9317 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9318 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9319 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 9320 | }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 9321 | { |
| 9322 | .cmd = NL80211_CMD_SET_BEACON, |
| 9323 | .policy = nl80211_policy, |
| 9324 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 9325 | .doit = nl80211_set_beacon, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9326 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9327 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 9328 | }, |
| 9329 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 9330 | .cmd = NL80211_CMD_START_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 9331 | .policy = nl80211_policy, |
| 9332 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 9333 | .doit = nl80211_start_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9334 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9335 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 9336 | }, |
| 9337 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 9338 | .cmd = NL80211_CMD_STOP_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 9339 | .policy = nl80211_policy, |
| 9340 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 9341 | .doit = nl80211_stop_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9342 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9343 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 9344 | }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 9345 | { |
| 9346 | .cmd = NL80211_CMD_GET_STATION, |
| 9347 | .doit = nl80211_get_station, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9348 | .dumpit = nl80211_dump_station, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 9349 | .policy = nl80211_policy, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9350 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9351 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 9352 | }, |
| 9353 | { |
| 9354 | .cmd = NL80211_CMD_SET_STATION, |
| 9355 | .doit = nl80211_set_station, |
| 9356 | .policy = nl80211_policy, |
| 9357 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9358 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9359 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 9360 | }, |
| 9361 | { |
| 9362 | .cmd = NL80211_CMD_NEW_STATION, |
| 9363 | .doit = nl80211_new_station, |
| 9364 | .policy = nl80211_policy, |
| 9365 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9366 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9367 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 9368 | }, |
| 9369 | { |
| 9370 | .cmd = NL80211_CMD_DEL_STATION, |
| 9371 | .doit = nl80211_del_station, |
| 9372 | .policy = nl80211_policy, |
| 9373 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9374 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9375 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 9376 | }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9377 | { |
| 9378 | .cmd = NL80211_CMD_GET_MPATH, |
| 9379 | .doit = nl80211_get_mpath, |
| 9380 | .dumpit = nl80211_dump_mpath, |
| 9381 | .policy = nl80211_policy, |
| 9382 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9383 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9384 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9385 | }, |
| 9386 | { |
| 9387 | .cmd = NL80211_CMD_SET_MPATH, |
| 9388 | .doit = nl80211_set_mpath, |
| 9389 | .policy = nl80211_policy, |
| 9390 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9391 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9392 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9393 | }, |
| 9394 | { |
| 9395 | .cmd = NL80211_CMD_NEW_MPATH, |
| 9396 | .doit = nl80211_new_mpath, |
| 9397 | .policy = nl80211_policy, |
| 9398 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9399 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9400 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9401 | }, |
| 9402 | { |
| 9403 | .cmd = NL80211_CMD_DEL_MPATH, |
| 9404 | .doit = nl80211_del_mpath, |
| 9405 | .policy = nl80211_policy, |
| 9406 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9407 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9408 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9409 | }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 9410 | { |
| 9411 | .cmd = NL80211_CMD_SET_BSS, |
| 9412 | .doit = nl80211_set_bss, |
| 9413 | .policy = nl80211_policy, |
| 9414 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9415 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9416 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 9417 | }, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 9418 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 9419 | .cmd = NL80211_CMD_GET_REG, |
| 9420 | .doit = nl80211_get_reg, |
| 9421 | .policy = nl80211_policy, |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 9422 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 9423 | /* can be retrieved by unprivileged users */ |
| 9424 | }, |
| 9425 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 9426 | .cmd = NL80211_CMD_SET_REG, |
| 9427 | .doit = nl80211_set_reg, |
| 9428 | .policy = nl80211_policy, |
| 9429 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 9430 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 9431 | }, |
| 9432 | { |
| 9433 | .cmd = NL80211_CMD_REQ_SET_REG, |
| 9434 | .doit = nl80211_req_set_reg, |
| 9435 | .policy = nl80211_policy, |
| 9436 | .flags = GENL_ADMIN_PERM, |
| 9437 | }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 9438 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 9439 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
| 9440 | .doit = nl80211_get_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 9441 | .policy = nl80211_policy, |
| 9442 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9443 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9444 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 9445 | }, |
| 9446 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 9447 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
| 9448 | .doit = nl80211_update_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 9449 | .policy = nl80211_policy, |
| 9450 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 9451 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9452 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 9453 | }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 9454 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9455 | .cmd = NL80211_CMD_TRIGGER_SCAN, |
| 9456 | .doit = nl80211_trigger_scan, |
| 9457 | .policy = nl80211_policy, |
| 9458 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9459 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9460 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9461 | }, |
| 9462 | { |
| 9463 | .cmd = NL80211_CMD_GET_SCAN, |
| 9464 | .policy = nl80211_policy, |
| 9465 | .dumpit = nl80211_dump_scan, |
| 9466 | }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9467 | { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9468 | .cmd = NL80211_CMD_START_SCHED_SCAN, |
| 9469 | .doit = nl80211_start_sched_scan, |
| 9470 | .policy = nl80211_policy, |
| 9471 | .flags = GENL_ADMIN_PERM, |
| 9472 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9473 | NL80211_FLAG_NEED_RTNL, |
| 9474 | }, |
| 9475 | { |
| 9476 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, |
| 9477 | .doit = nl80211_stop_sched_scan, |
| 9478 | .policy = nl80211_policy, |
| 9479 | .flags = GENL_ADMIN_PERM, |
| 9480 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9481 | NL80211_FLAG_NEED_RTNL, |
| 9482 | }, |
| 9483 | { |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9484 | .cmd = NL80211_CMD_AUTHENTICATE, |
| 9485 | .doit = nl80211_authenticate, |
| 9486 | .policy = nl80211_policy, |
| 9487 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9488 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9489 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9490 | }, |
| 9491 | { |
| 9492 | .cmd = NL80211_CMD_ASSOCIATE, |
| 9493 | .doit = nl80211_associate, |
| 9494 | .policy = nl80211_policy, |
| 9495 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9496 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9497 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9498 | }, |
| 9499 | { |
| 9500 | .cmd = NL80211_CMD_DEAUTHENTICATE, |
| 9501 | .doit = nl80211_deauthenticate, |
| 9502 | .policy = nl80211_policy, |
| 9503 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9504 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9505 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9506 | }, |
| 9507 | { |
| 9508 | .cmd = NL80211_CMD_DISASSOCIATE, |
| 9509 | .doit = nl80211_disassociate, |
| 9510 | .policy = nl80211_policy, |
| 9511 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9512 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9513 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9514 | }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9515 | { |
| 9516 | .cmd = NL80211_CMD_JOIN_IBSS, |
| 9517 | .doit = nl80211_join_ibss, |
| 9518 | .policy = nl80211_policy, |
| 9519 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9520 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9521 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9522 | }, |
| 9523 | { |
| 9524 | .cmd = NL80211_CMD_LEAVE_IBSS, |
| 9525 | .doit = nl80211_leave_ibss, |
| 9526 | .policy = nl80211_policy, |
| 9527 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9528 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9529 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9530 | }, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 9531 | #ifdef CONFIG_NL80211_TESTMODE |
| 9532 | { |
| 9533 | .cmd = NL80211_CMD_TESTMODE, |
| 9534 | .doit = nl80211_testmode_do, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 9535 | .dumpit = nl80211_testmode_dump, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 9536 | .policy = nl80211_policy, |
| 9537 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9538 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9539 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 9540 | }, |
| 9541 | #endif |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9542 | { |
| 9543 | .cmd = NL80211_CMD_CONNECT, |
| 9544 | .doit = nl80211_connect, |
| 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, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9549 | }, |
| 9550 | { |
| 9551 | .cmd = NL80211_CMD_DISCONNECT, |
| 9552 | .doit = nl80211_disconnect, |
| 9553 | .policy = nl80211_policy, |
| 9554 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +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, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9557 | }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9558 | { |
| 9559 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, |
| 9560 | .doit = nl80211_wiphy_netns, |
| 9561 | .policy = nl80211_policy, |
| 9562 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9563 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9564 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9565 | }, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 9566 | { |
| 9567 | .cmd = NL80211_CMD_GET_SURVEY, |
| 9568 | .policy = nl80211_policy, |
| 9569 | .dumpit = nl80211_dump_survey, |
| 9570 | }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9571 | { |
| 9572 | .cmd = NL80211_CMD_SET_PMKSA, |
| 9573 | .doit = nl80211_setdel_pmksa, |
| 9574 | .policy = nl80211_policy, |
| 9575 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9576 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9577 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9578 | }, |
| 9579 | { |
| 9580 | .cmd = NL80211_CMD_DEL_PMKSA, |
| 9581 | .doit = nl80211_setdel_pmksa, |
| 9582 | .policy = nl80211_policy, |
| 9583 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9584 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9585 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9586 | }, |
| 9587 | { |
| 9588 | .cmd = NL80211_CMD_FLUSH_PMKSA, |
| 9589 | .doit = nl80211_flush_pmksa, |
| 9590 | .policy = nl80211_policy, |
| 9591 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9592 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9593 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9594 | }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9595 | { |
| 9596 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, |
| 9597 | .doit = nl80211_remain_on_channel, |
| 9598 | .policy = nl80211_policy, |
| 9599 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9600 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9601 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9602 | }, |
| 9603 | { |
| 9604 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
| 9605 | .doit = nl80211_cancel_remain_on_channel, |
| 9606 | .policy = nl80211_policy, |
| 9607 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9608 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9609 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9610 | }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 9611 | { |
| 9612 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, |
| 9613 | .doit = nl80211_set_tx_bitrate_mask, |
| 9614 | .policy = nl80211_policy, |
| 9615 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9616 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9617 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 9618 | }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9619 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9620 | .cmd = NL80211_CMD_REGISTER_FRAME, |
| 9621 | .doit = nl80211_register_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9622 | .policy = nl80211_policy, |
| 9623 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9624 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9625 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9626 | }, |
| 9627 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9628 | .cmd = NL80211_CMD_FRAME, |
| 9629 | .doit = nl80211_tx_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9630 | .policy = nl80211_policy, |
| 9631 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9632 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9633 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9634 | }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9635 | { |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 9636 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, |
| 9637 | .doit = nl80211_tx_mgmt_cancel_wait, |
| 9638 | .policy = nl80211_policy, |
| 9639 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9640 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 9641 | NL80211_FLAG_NEED_RTNL, |
| 9642 | }, |
| 9643 | { |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9644 | .cmd = NL80211_CMD_SET_POWER_SAVE, |
| 9645 | .doit = nl80211_set_power_save, |
| 9646 | .policy = nl80211_policy, |
| 9647 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9648 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9649 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9650 | }, |
| 9651 | { |
| 9652 | .cmd = NL80211_CMD_GET_POWER_SAVE, |
| 9653 | .doit = nl80211_get_power_save, |
| 9654 | .policy = nl80211_policy, |
| 9655 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9656 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9657 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9658 | }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9659 | { |
| 9660 | .cmd = NL80211_CMD_SET_CQM, |
| 9661 | .doit = nl80211_set_cqm, |
| 9662 | .policy = nl80211_policy, |
| 9663 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9664 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9665 | NL80211_FLAG_NEED_RTNL, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9666 | }, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 9667 | { |
| 9668 | .cmd = NL80211_CMD_SET_CHANNEL, |
| 9669 | .doit = nl80211_set_channel, |
| 9670 | .policy = nl80211_policy, |
| 9671 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9672 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9673 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 9674 | }, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 9675 | { |
| 9676 | .cmd = NL80211_CMD_SET_WDS_PEER, |
| 9677 | .doit = nl80211_set_wds_peer, |
| 9678 | .policy = nl80211_policy, |
| 9679 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 9680 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9681 | NL80211_FLAG_NEED_RTNL, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 9682 | }, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 9683 | { |
| 9684 | .cmd = NL80211_CMD_JOIN_MESH, |
| 9685 | .doit = nl80211_join_mesh, |
| 9686 | .policy = nl80211_policy, |
| 9687 | .flags = GENL_ADMIN_PERM, |
| 9688 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9689 | NL80211_FLAG_NEED_RTNL, |
| 9690 | }, |
| 9691 | { |
| 9692 | .cmd = NL80211_CMD_LEAVE_MESH, |
| 9693 | .doit = nl80211_leave_mesh, |
| 9694 | .policy = nl80211_policy, |
| 9695 | .flags = GENL_ADMIN_PERM, |
| 9696 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9697 | NL80211_FLAG_NEED_RTNL, |
| 9698 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 9699 | #ifdef CONFIG_PM |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9700 | { |
| 9701 | .cmd = NL80211_CMD_GET_WOWLAN, |
| 9702 | .doit = nl80211_get_wowlan, |
| 9703 | .policy = nl80211_policy, |
| 9704 | /* can be retrieved by unprivileged users */ |
| 9705 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9706 | NL80211_FLAG_NEED_RTNL, |
| 9707 | }, |
| 9708 | { |
| 9709 | .cmd = NL80211_CMD_SET_WOWLAN, |
| 9710 | .doit = nl80211_set_wowlan, |
| 9711 | .policy = nl80211_policy, |
| 9712 | .flags = GENL_ADMIN_PERM, |
| 9713 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9714 | NL80211_FLAG_NEED_RTNL, |
| 9715 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 9716 | #endif |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 9717 | { |
| 9718 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, |
| 9719 | .doit = nl80211_set_rekey_data, |
| 9720 | .policy = nl80211_policy, |
| 9721 | .flags = GENL_ADMIN_PERM, |
| 9722 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9723 | NL80211_FLAG_NEED_RTNL, |
| 9724 | }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 9725 | { |
| 9726 | .cmd = NL80211_CMD_TDLS_MGMT, |
| 9727 | .doit = nl80211_tdls_mgmt, |
| 9728 | .policy = nl80211_policy, |
| 9729 | .flags = GENL_ADMIN_PERM, |
| 9730 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9731 | NL80211_FLAG_NEED_RTNL, |
| 9732 | }, |
| 9733 | { |
| 9734 | .cmd = NL80211_CMD_TDLS_OPER, |
| 9735 | .doit = nl80211_tdls_oper, |
| 9736 | .policy = nl80211_policy, |
| 9737 | .flags = GENL_ADMIN_PERM, |
| 9738 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9739 | NL80211_FLAG_NEED_RTNL, |
| 9740 | }, |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9741 | { |
| 9742 | .cmd = NL80211_CMD_UNEXPECTED_FRAME, |
| 9743 | .doit = nl80211_register_unexpected_frame, |
| 9744 | .policy = nl80211_policy, |
| 9745 | .flags = GENL_ADMIN_PERM, |
| 9746 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9747 | NL80211_FLAG_NEED_RTNL, |
| 9748 | }, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9749 | { |
| 9750 | .cmd = NL80211_CMD_PROBE_CLIENT, |
| 9751 | .doit = nl80211_probe_client, |
| 9752 | .policy = nl80211_policy, |
| 9753 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9754 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9755 | NL80211_FLAG_NEED_RTNL, |
| 9756 | }, |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9757 | { |
| 9758 | .cmd = NL80211_CMD_REGISTER_BEACONS, |
| 9759 | .doit = nl80211_register_beacons, |
| 9760 | .policy = nl80211_policy, |
| 9761 | .flags = GENL_ADMIN_PERM, |
| 9762 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9763 | NL80211_FLAG_NEED_RTNL, |
| 9764 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 9765 | { |
| 9766 | .cmd = NL80211_CMD_SET_NOACK_MAP, |
| 9767 | .doit = nl80211_set_noack_map, |
| 9768 | .policy = nl80211_policy, |
| 9769 | .flags = GENL_ADMIN_PERM, |
| 9770 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9771 | NL80211_FLAG_NEED_RTNL, |
| 9772 | }, |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9773 | { |
| 9774 | .cmd = NL80211_CMD_START_P2P_DEVICE, |
| 9775 | .doit = nl80211_start_p2p_device, |
| 9776 | .policy = nl80211_policy, |
| 9777 | .flags = GENL_ADMIN_PERM, |
| 9778 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 9779 | NL80211_FLAG_NEED_RTNL, |
| 9780 | }, |
| 9781 | { |
| 9782 | .cmd = NL80211_CMD_STOP_P2P_DEVICE, |
| 9783 | .doit = nl80211_stop_p2p_device, |
| 9784 | .policy = nl80211_policy, |
| 9785 | .flags = GENL_ADMIN_PERM, |
| 9786 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 9787 | NL80211_FLAG_NEED_RTNL, |
| 9788 | }, |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 9789 | { |
| 9790 | .cmd = NL80211_CMD_SET_MCAST_RATE, |
| 9791 | .doit = nl80211_set_mcast_rate, |
| 9792 | .policy = nl80211_policy, |
| 9793 | .flags = GENL_ADMIN_PERM, |
| 9794 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9795 | NL80211_FLAG_NEED_RTNL, |
| 9796 | }, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 9797 | { |
| 9798 | .cmd = NL80211_CMD_SET_MAC_ACL, |
| 9799 | .doit = nl80211_set_mac_acl, |
| 9800 | .policy = nl80211_policy, |
| 9801 | .flags = GENL_ADMIN_PERM, |
| 9802 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9803 | NL80211_FLAG_NEED_RTNL, |
| 9804 | }, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 9805 | { |
| 9806 | .cmd = NL80211_CMD_RADAR_DETECT, |
| 9807 | .doit = nl80211_start_radar_detection, |
| 9808 | .policy = nl80211_policy, |
| 9809 | .flags = GENL_ADMIN_PERM, |
| 9810 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9811 | NL80211_FLAG_NEED_RTNL, |
| 9812 | }, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 9813 | { |
| 9814 | .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES, |
| 9815 | .doit = nl80211_get_protocol_features, |
| 9816 | .policy = nl80211_policy, |
| 9817 | }, |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 9818 | { |
| 9819 | .cmd = NL80211_CMD_UPDATE_FT_IES, |
| 9820 | .doit = nl80211_update_ft_ies, |
| 9821 | .policy = nl80211_policy, |
| 9822 | .flags = GENL_ADMIN_PERM, |
| 9823 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9824 | NL80211_FLAG_NEED_RTNL, |
| 9825 | }, |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 9826 | { |
| 9827 | .cmd = NL80211_CMD_CRIT_PROTOCOL_START, |
| 9828 | .doit = nl80211_crit_protocol_start, |
| 9829 | .policy = nl80211_policy, |
| 9830 | .flags = GENL_ADMIN_PERM, |
| 9831 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 9832 | NL80211_FLAG_NEED_RTNL, |
| 9833 | }, |
| 9834 | { |
| 9835 | .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP, |
| 9836 | .doit = nl80211_crit_protocol_stop, |
| 9837 | .policy = nl80211_policy, |
| 9838 | .flags = GENL_ADMIN_PERM, |
| 9839 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 9840 | NL80211_FLAG_NEED_RTNL, |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 9841 | }, |
| 9842 | { |
| 9843 | .cmd = NL80211_CMD_GET_COALESCE, |
| 9844 | .doit = nl80211_get_coalesce, |
| 9845 | .policy = nl80211_policy, |
| 9846 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9847 | NL80211_FLAG_NEED_RTNL, |
| 9848 | }, |
| 9849 | { |
| 9850 | .cmd = NL80211_CMD_SET_COALESCE, |
| 9851 | .doit = nl80211_set_coalesce, |
| 9852 | .policy = nl80211_policy, |
| 9853 | .flags = GENL_ADMIN_PERM, |
| 9854 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9855 | NL80211_FLAG_NEED_RTNL, |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 9856 | }, |
| 9857 | { |
| 9858 | .cmd = NL80211_CMD_CHANNEL_SWITCH, |
| 9859 | .doit = nl80211_channel_switch, |
| 9860 | .policy = nl80211_policy, |
| 9861 | .flags = GENL_ADMIN_PERM, |
| 9862 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9863 | NL80211_FLAG_NEED_RTNL, |
| 9864 | }, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 9865 | { |
| 9866 | .cmd = NL80211_CMD_VENDOR, |
| 9867 | .doit = nl80211_vendor_cmd, |
| 9868 | .policy = nl80211_policy, |
| 9869 | .flags = GENL_ADMIN_PERM, |
| 9870 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9871 | NL80211_FLAG_NEED_RTNL, |
| 9872 | }, |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 9873 | { |
| 9874 | .cmd = NL80211_CMD_SET_QOS_MAP, |
| 9875 | .doit = nl80211_set_qos_map, |
| 9876 | .policy = nl80211_policy, |
| 9877 | .flags = GENL_ADMIN_PERM, |
| 9878 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9879 | NL80211_FLAG_NEED_RTNL, |
| 9880 | }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9881 | }; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9882 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9883 | /* notification functions */ |
| 9884 | |
| 9885 | void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev) |
| 9886 | { |
| 9887 | struct sk_buff *msg; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 9888 | struct nl80211_dump_wiphy_state state = {}; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9889 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 9890 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9891 | if (!msg) |
| 9892 | return; |
| 9893 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 9894 | if (nl80211_send_wiphy(rdev, msg, 0, 0, 0, &state) < 0) { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9895 | nlmsg_free(msg); |
| 9896 | return; |
| 9897 | } |
| 9898 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 9899 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 9900 | NL80211_MCGRP_CONFIG, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9901 | } |
| 9902 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 9903 | static int nl80211_add_scan_req(struct sk_buff *msg, |
| 9904 | struct cfg80211_registered_device *rdev) |
| 9905 | { |
| 9906 | struct cfg80211_scan_request *req = rdev->scan_req; |
| 9907 | struct nlattr *nest; |
| 9908 | int i; |
| 9909 | |
| 9910 | if (WARN_ON(!req)) |
| 9911 | return 0; |
| 9912 | |
| 9913 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); |
| 9914 | if (!nest) |
| 9915 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9916 | for (i = 0; i < req->n_ssids; i++) { |
| 9917 | if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) |
| 9918 | goto nla_put_failure; |
| 9919 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 9920 | nla_nest_end(msg, nest); |
| 9921 | |
| 9922 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 9923 | if (!nest) |
| 9924 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9925 | for (i = 0; i < req->n_channels; i++) { |
| 9926 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) |
| 9927 | goto nla_put_failure; |
| 9928 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 9929 | nla_nest_end(msg, nest); |
| 9930 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9931 | if (req->ie && |
| 9932 | nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie)) |
| 9933 | goto nla_put_failure; |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 9934 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 9935 | if (req->flags && |
| 9936 | nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags)) |
| 9937 | goto nla_put_failure; |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 9938 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 9939 | return 0; |
| 9940 | nla_put_failure: |
| 9941 | return -ENOBUFS; |
| 9942 | } |
| 9943 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9944 | static int nl80211_send_scan_msg(struct sk_buff *msg, |
| 9945 | struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9946 | struct wireless_dev *wdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9947 | u32 portid, u32 seq, int flags, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9948 | u32 cmd) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9949 | { |
| 9950 | void *hdr; |
| 9951 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9952 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9953 | if (!hdr) |
| 9954 | return -1; |
| 9955 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9956 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9957 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 9958 | wdev->netdev->ifindex)) || |
| 9959 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9960 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9961 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 9962 | /* ignore errors and send incomplete event anyway */ |
| 9963 | nl80211_add_scan_req(msg, rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9964 | |
| 9965 | return genlmsg_end(msg, hdr); |
| 9966 | |
| 9967 | nla_put_failure: |
| 9968 | genlmsg_cancel(msg, hdr); |
| 9969 | return -EMSGSIZE; |
| 9970 | } |
| 9971 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9972 | static int |
| 9973 | nl80211_send_sched_scan_msg(struct sk_buff *msg, |
| 9974 | struct cfg80211_registered_device *rdev, |
| 9975 | struct net_device *netdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9976 | u32 portid, u32 seq, int flags, u32 cmd) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9977 | { |
| 9978 | void *hdr; |
| 9979 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9980 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9981 | if (!hdr) |
| 9982 | return -1; |
| 9983 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9984 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9985 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 9986 | goto nla_put_failure; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9987 | |
| 9988 | return genlmsg_end(msg, hdr); |
| 9989 | |
| 9990 | nla_put_failure: |
| 9991 | genlmsg_cancel(msg, hdr); |
| 9992 | return -EMSGSIZE; |
| 9993 | } |
| 9994 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9995 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9996 | struct wireless_dev *wdev) |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9997 | { |
| 9998 | struct sk_buff *msg; |
| 9999 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10000 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 10001 | if (!msg) |
| 10002 | return; |
| 10003 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 10004 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 10005 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
| 10006 | nlmsg_free(msg); |
| 10007 | return; |
| 10008 | } |
| 10009 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10010 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10011 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 10012 | } |
| 10013 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10014 | void nl80211_send_scan_done(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 10015 | struct wireless_dev *wdev) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10016 | { |
| 10017 | struct sk_buff *msg; |
| 10018 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 10019 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10020 | if (!msg) |
| 10021 | return; |
| 10022 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 10023 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 10024 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10025 | nlmsg_free(msg); |
| 10026 | return; |
| 10027 | } |
| 10028 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10029 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10030 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10031 | } |
| 10032 | |
| 10033 | void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 10034 | struct wireless_dev *wdev) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10035 | { |
| 10036 | struct sk_buff *msg; |
| 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 | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10039 | if (!msg) |
| 10040 | return; |
| 10041 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 10042 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 10043 | NL80211_CMD_SCAN_ABORTED) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10044 | nlmsg_free(msg); |
| 10045 | return; |
| 10046 | } |
| 10047 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10048 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10049 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10050 | } |
| 10051 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 10052 | void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev, |
| 10053 | struct net_device *netdev) |
| 10054 | { |
| 10055 | struct sk_buff *msg; |
| 10056 | |
| 10057 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 10058 | if (!msg) |
| 10059 | return; |
| 10060 | |
| 10061 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 10062 | NL80211_CMD_SCHED_SCAN_RESULTS) < 0) { |
| 10063 | nlmsg_free(msg); |
| 10064 | return; |
| 10065 | } |
| 10066 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10067 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10068 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 10069 | } |
| 10070 | |
| 10071 | void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev, |
| 10072 | struct net_device *netdev, u32 cmd) |
| 10073 | { |
| 10074 | struct sk_buff *msg; |
| 10075 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10076 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 10077 | if (!msg) |
| 10078 | return; |
| 10079 | |
| 10080 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) { |
| 10081 | nlmsg_free(msg); |
| 10082 | return; |
| 10083 | } |
| 10084 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10085 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10086 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 10087 | } |
| 10088 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 10089 | /* |
| 10090 | * This can happen on global regulatory changes or device specific settings |
| 10091 | * based on custom world regulatory domains. |
| 10092 | */ |
| 10093 | void nl80211_send_reg_change_event(struct regulatory_request *request) |
| 10094 | { |
| 10095 | struct sk_buff *msg; |
| 10096 | void *hdr; |
| 10097 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 10098 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 10099 | if (!msg) |
| 10100 | return; |
| 10101 | |
| 10102 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE); |
| 10103 | if (!hdr) { |
| 10104 | nlmsg_free(msg); |
| 10105 | return; |
| 10106 | } |
| 10107 | |
| 10108 | /* Userspace can always count this one always being set */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10109 | if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator)) |
| 10110 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 10111 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10112 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') { |
| 10113 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 10114 | NL80211_REGDOM_TYPE_WORLD)) |
| 10115 | goto nla_put_failure; |
| 10116 | } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') { |
| 10117 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 10118 | NL80211_REGDOM_TYPE_CUSTOM_WORLD)) |
| 10119 | goto nla_put_failure; |
| 10120 | } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || |
| 10121 | request->intersect) { |
| 10122 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 10123 | NL80211_REGDOM_TYPE_INTERSECTION)) |
| 10124 | goto nla_put_failure; |
| 10125 | } else { |
| 10126 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 10127 | NL80211_REGDOM_TYPE_COUNTRY) || |
| 10128 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, |
| 10129 | request->alpha2)) |
| 10130 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 10131 | } |
| 10132 | |
Johannes Berg | f417376 | 2012-12-03 18:23:37 +0100 | [diff] [blame] | 10133 | if (request->wiphy_idx != WIPHY_IDX_INVALID && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10134 | nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) |
| 10135 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 10136 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10137 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 10138 | |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 10139 | rcu_read_lock(); |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10140 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10141 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 10142 | rcu_read_unlock(); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 10143 | |
| 10144 | return; |
| 10145 | |
| 10146 | nla_put_failure: |
| 10147 | genlmsg_cancel(msg, hdr); |
| 10148 | nlmsg_free(msg); |
| 10149 | } |
| 10150 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10151 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
| 10152 | struct net_device *netdev, |
| 10153 | const u8 *buf, size_t len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10154 | enum nl80211_commands cmd, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10155 | { |
| 10156 | struct sk_buff *msg; |
| 10157 | void *hdr; |
| 10158 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10159 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10160 | if (!msg) |
| 10161 | return; |
| 10162 | |
| 10163 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 10164 | if (!hdr) { |
| 10165 | nlmsg_free(msg); |
| 10166 | return; |
| 10167 | } |
| 10168 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10169 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10170 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10171 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) |
| 10172 | goto nla_put_failure; |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10173 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10174 | genlmsg_end(msg, hdr); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10175 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10176 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10177 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10178 | return; |
| 10179 | |
| 10180 | nla_put_failure: |
| 10181 | genlmsg_cancel(msg, hdr); |
| 10182 | nlmsg_free(msg); |
| 10183 | } |
| 10184 | |
| 10185 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10186 | struct net_device *netdev, const u8 *buf, |
| 10187 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10188 | { |
| 10189 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10190 | NL80211_CMD_AUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10191 | } |
| 10192 | |
| 10193 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, |
| 10194 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10195 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10196 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10197 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 10198 | NL80211_CMD_ASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10199 | } |
| 10200 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 10201 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10202 | struct net_device *netdev, const u8 *buf, |
| 10203 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10204 | { |
| 10205 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10206 | NL80211_CMD_DEAUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10207 | } |
| 10208 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 10209 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
| 10210 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10211 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10212 | { |
| 10213 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10214 | NL80211_CMD_DISASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10215 | } |
| 10216 | |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 10217 | void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf, |
| 10218 | size_t len) |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 10219 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10220 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10221 | struct wiphy *wiphy = wdev->wiphy; |
| 10222 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 10223 | const struct ieee80211_mgmt *mgmt = (void *)buf; |
| 10224 | u32 cmd; |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 10225 | |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 10226 | if (WARN_ON(len < 2)) |
| 10227 | return; |
| 10228 | |
| 10229 | if (ieee80211_is_deauth(mgmt->frame_control)) |
| 10230 | cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE; |
| 10231 | else |
| 10232 | cmd = NL80211_CMD_UNPROT_DISASSOCIATE; |
| 10233 | |
| 10234 | trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len); |
| 10235 | nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC); |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 10236 | } |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 10237 | EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt); |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 10238 | |
Luis R. Rodriguez | 1b06bb4 | 2009-05-02 00:34:48 -0400 | [diff] [blame] | 10239 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
| 10240 | struct net_device *netdev, int cmd, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10241 | const u8 *addr, gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10242 | { |
| 10243 | struct sk_buff *msg; |
| 10244 | void *hdr; |
| 10245 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10246 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10247 | if (!msg) |
| 10248 | return; |
| 10249 | |
| 10250 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 10251 | if (!hdr) { |
| 10252 | nlmsg_free(msg); |
| 10253 | return; |
| 10254 | } |
| 10255 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10256 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10257 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10258 | nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || |
| 10259 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 10260 | goto nla_put_failure; |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10261 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10262 | genlmsg_end(msg, hdr); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10263 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10264 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10265 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10266 | return; |
| 10267 | |
| 10268 | nla_put_failure: |
| 10269 | genlmsg_cancel(msg, hdr); |
| 10270 | nlmsg_free(msg); |
| 10271 | } |
| 10272 | |
| 10273 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10274 | struct net_device *netdev, const u8 *addr, |
| 10275 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10276 | { |
| 10277 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10278 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10279 | } |
| 10280 | |
| 10281 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10282 | struct net_device *netdev, const u8 *addr, |
| 10283 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10284 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10285 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
| 10286 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10287 | } |
| 10288 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10289 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
| 10290 | struct net_device *netdev, const u8 *bssid, |
| 10291 | const u8 *req_ie, size_t req_ie_len, |
| 10292 | const u8 *resp_ie, size_t resp_ie_len, |
| 10293 | u16 status, gfp_t gfp) |
| 10294 | { |
| 10295 | struct sk_buff *msg; |
| 10296 | void *hdr; |
| 10297 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10298 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10299 | if (!msg) |
| 10300 | return; |
| 10301 | |
| 10302 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); |
| 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 | (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) || |
| 10311 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) || |
| 10312 | (req_ie && |
| 10313 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 10314 | (resp_ie && |
| 10315 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 10316 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10317 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10318 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10319 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10320 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10321 | NL80211_MCGRP_MLME, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10322 | return; |
| 10323 | |
| 10324 | nla_put_failure: |
| 10325 | genlmsg_cancel(msg, hdr); |
| 10326 | nlmsg_free(msg); |
| 10327 | |
| 10328 | } |
| 10329 | |
| 10330 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, |
| 10331 | struct net_device *netdev, const u8 *bssid, |
| 10332 | const u8 *req_ie, size_t req_ie_len, |
| 10333 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) |
| 10334 | { |
| 10335 | struct sk_buff *msg; |
| 10336 | void *hdr; |
| 10337 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10338 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10339 | if (!msg) |
| 10340 | return; |
| 10341 | |
| 10342 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); |
| 10343 | if (!hdr) { |
| 10344 | nlmsg_free(msg); |
| 10345 | return; |
| 10346 | } |
| 10347 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10348 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10349 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10350 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) || |
| 10351 | (req_ie && |
| 10352 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 10353 | (resp_ie && |
| 10354 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 10355 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10356 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10357 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10358 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10359 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10360 | NL80211_MCGRP_MLME, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10361 | return; |
| 10362 | |
| 10363 | nla_put_failure: |
| 10364 | genlmsg_cancel(msg, hdr); |
| 10365 | nlmsg_free(msg); |
| 10366 | |
| 10367 | } |
| 10368 | |
| 10369 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, |
| 10370 | struct net_device *netdev, u16 reason, |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 10371 | const u8 *ie, size_t ie_len, bool from_ap) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10372 | { |
| 10373 | struct sk_buff *msg; |
| 10374 | void *hdr; |
| 10375 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10376 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10377 | if (!msg) |
| 10378 | return; |
| 10379 | |
| 10380 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); |
| 10381 | if (!hdr) { |
| 10382 | nlmsg_free(msg); |
| 10383 | return; |
| 10384 | } |
| 10385 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10386 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10387 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10388 | (from_ap && reason && |
| 10389 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) || |
| 10390 | (from_ap && |
| 10391 | nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) || |
| 10392 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) |
| 10393 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10394 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10395 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10396 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10397 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10398 | NL80211_MCGRP_MLME, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10399 | return; |
| 10400 | |
| 10401 | nla_put_failure: |
| 10402 | genlmsg_cancel(msg, hdr); |
| 10403 | nlmsg_free(msg); |
| 10404 | |
| 10405 | } |
| 10406 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10407 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
| 10408 | struct net_device *netdev, const u8 *bssid, |
| 10409 | gfp_t gfp) |
| 10410 | { |
| 10411 | struct sk_buff *msg; |
| 10412 | void *hdr; |
| 10413 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 10414 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10415 | if (!msg) |
| 10416 | return; |
| 10417 | |
| 10418 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); |
| 10419 | if (!hdr) { |
| 10420 | nlmsg_free(msg); |
| 10421 | return; |
| 10422 | } |
| 10423 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10424 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10425 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10426 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 10427 | goto nla_put_failure; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10428 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10429 | genlmsg_end(msg, hdr); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10430 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10431 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10432 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10433 | return; |
| 10434 | |
| 10435 | nla_put_failure: |
| 10436 | genlmsg_cancel(msg, hdr); |
| 10437 | nlmsg_free(msg); |
| 10438 | } |
| 10439 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10440 | void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr, |
| 10441 | const u8* ie, u8 ie_len, gfp_t gfp) |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10442 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10443 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10444 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10445 | struct sk_buff *msg; |
| 10446 | void *hdr; |
| 10447 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10448 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT)) |
| 10449 | return; |
| 10450 | |
| 10451 | trace_cfg80211_notify_new_peer_candidate(dev, addr); |
| 10452 | |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10453 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 10454 | if (!msg) |
| 10455 | return; |
| 10456 | |
| 10457 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); |
| 10458 | if (!hdr) { |
| 10459 | nlmsg_free(msg); |
| 10460 | return; |
| 10461 | } |
| 10462 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10463 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10464 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 10465 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10466 | (ie_len && ie && |
| 10467 | nla_put(msg, NL80211_ATTR_IE, ie_len , ie))) |
| 10468 | goto nla_put_failure; |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10469 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10470 | genlmsg_end(msg, hdr); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10471 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10472 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10473 | NL80211_MCGRP_MLME, gfp); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10474 | return; |
| 10475 | |
| 10476 | nla_put_failure: |
| 10477 | genlmsg_cancel(msg, hdr); |
| 10478 | nlmsg_free(msg); |
| 10479 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10480 | EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10481 | |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 10482 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
| 10483 | struct net_device *netdev, const u8 *addr, |
| 10484 | enum nl80211_key_type key_type, int key_id, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10485 | const u8 *tsc, gfp_t gfp) |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 10486 | { |
| 10487 | struct sk_buff *msg; |
| 10488 | void *hdr; |
| 10489 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10490 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 10491 | if (!msg) |
| 10492 | return; |
| 10493 | |
| 10494 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); |
| 10495 | if (!hdr) { |
| 10496 | nlmsg_free(msg); |
| 10497 | return; |
| 10498 | } |
| 10499 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10500 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10501 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10502 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
| 10503 | nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) || |
| 10504 | (key_id != -1 && |
| 10505 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) || |
| 10506 | (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc))) |
| 10507 | goto nla_put_failure; |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 10508 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10509 | genlmsg_end(msg, hdr); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 10510 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10511 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10512 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 10513 | return; |
| 10514 | |
| 10515 | nla_put_failure: |
| 10516 | genlmsg_cancel(msg, hdr); |
| 10517 | nlmsg_free(msg); |
| 10518 | } |
| 10519 | |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10520 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
| 10521 | struct ieee80211_channel *channel_before, |
| 10522 | struct ieee80211_channel *channel_after) |
| 10523 | { |
| 10524 | struct sk_buff *msg; |
| 10525 | void *hdr; |
| 10526 | struct nlattr *nl_freq; |
| 10527 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 10528 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10529 | if (!msg) |
| 10530 | return; |
| 10531 | |
| 10532 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); |
| 10533 | if (!hdr) { |
| 10534 | nlmsg_free(msg); |
| 10535 | return; |
| 10536 | } |
| 10537 | |
| 10538 | /* |
| 10539 | * Since we are applying the beacon hint to a wiphy we know its |
| 10540 | * wiphy_idx is valid |
| 10541 | */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10542 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 10543 | goto nla_put_failure; |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10544 | |
| 10545 | /* Before */ |
| 10546 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); |
| 10547 | if (!nl_freq) |
| 10548 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 10549 | if (nl80211_msg_put_channel(msg, channel_before, false)) |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10550 | goto nla_put_failure; |
| 10551 | nla_nest_end(msg, nl_freq); |
| 10552 | |
| 10553 | /* After */ |
| 10554 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); |
| 10555 | if (!nl_freq) |
| 10556 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 10557 | if (nl80211_msg_put_channel(msg, channel_after, false)) |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10558 | goto nla_put_failure; |
| 10559 | nla_nest_end(msg, nl_freq); |
| 10560 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10561 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10562 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 10563 | rcu_read_lock(); |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10564 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10565 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 10566 | rcu_read_unlock(); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10567 | |
| 10568 | return; |
| 10569 | |
| 10570 | nla_put_failure: |
| 10571 | genlmsg_cancel(msg, hdr); |
| 10572 | nlmsg_free(msg); |
| 10573 | } |
| 10574 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10575 | static void nl80211_send_remain_on_chan_event( |
| 10576 | int cmd, struct cfg80211_registered_device *rdev, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10577 | struct wireless_dev *wdev, u64 cookie, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10578 | struct ieee80211_channel *chan, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10579 | unsigned int duration, gfp_t gfp) |
| 10580 | { |
| 10581 | struct sk_buff *msg; |
| 10582 | void *hdr; |
| 10583 | |
| 10584 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 10585 | if (!msg) |
| 10586 | return; |
| 10587 | |
| 10588 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 10589 | if (!hdr) { |
| 10590 | nlmsg_free(msg); |
| 10591 | return; |
| 10592 | } |
| 10593 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10594 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10595 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 10596 | wdev->netdev->ifindex)) || |
Johannes Berg | 00f5335 | 2012-07-17 11:53:12 +0200 | [diff] [blame] | 10597 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10598 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) || |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 10599 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 10600 | NL80211_CHAN_NO_HT) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10601 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 10602 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10603 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10604 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL && |
| 10605 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) |
| 10606 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10607 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10608 | genlmsg_end(msg, hdr); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10609 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10610 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10611 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10612 | return; |
| 10613 | |
| 10614 | nla_put_failure: |
| 10615 | genlmsg_cancel(msg, hdr); |
| 10616 | nlmsg_free(msg); |
| 10617 | } |
| 10618 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10619 | void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie, |
| 10620 | struct ieee80211_channel *chan, |
| 10621 | unsigned int duration, gfp_t gfp) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10622 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10623 | struct wiphy *wiphy = wdev->wiphy; |
| 10624 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 10625 | |
| 10626 | trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10627 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10628 | rdev, wdev, cookie, chan, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 10629 | duration, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10630 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10631 | EXPORT_SYMBOL(cfg80211_ready_on_channel); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10632 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10633 | void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie, |
| 10634 | struct ieee80211_channel *chan, |
| 10635 | gfp_t gfp) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10636 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10637 | struct wiphy *wiphy = wdev->wiphy; |
| 10638 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 10639 | |
| 10640 | trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10641 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 10642 | rdev, wdev, cookie, chan, 0, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10643 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10644 | EXPORT_SYMBOL(cfg80211_remain_on_channel_expired); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10645 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10646 | void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr, |
| 10647 | struct station_info *sinfo, gfp_t gfp) |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 10648 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10649 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
| 10650 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 10651 | struct sk_buff *msg; |
| 10652 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10653 | trace_cfg80211_new_sta(dev, mac_addr, sinfo); |
| 10654 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10655 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 10656 | if (!msg) |
| 10657 | return; |
| 10658 | |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 10659 | if (nl80211_send_station(msg, 0, 0, 0, |
| 10660 | rdev, dev, mac_addr, sinfo) < 0) { |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 10661 | nlmsg_free(msg); |
| 10662 | return; |
| 10663 | } |
| 10664 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10665 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10666 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 10667 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10668 | EXPORT_SYMBOL(cfg80211_new_sta); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 10669 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10670 | 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] | 10671 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10672 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
| 10673 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 10674 | struct sk_buff *msg; |
| 10675 | void *hdr; |
| 10676 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10677 | trace_cfg80211_del_sta(dev, mac_addr); |
| 10678 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10679 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 10680 | if (!msg) |
| 10681 | return; |
| 10682 | |
| 10683 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION); |
| 10684 | if (!hdr) { |
| 10685 | nlmsg_free(msg); |
| 10686 | return; |
| 10687 | } |
| 10688 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10689 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 10690 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 10691 | goto nla_put_failure; |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 10692 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10693 | genlmsg_end(msg, hdr); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 10694 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10695 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10696 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 10697 | return; |
| 10698 | |
| 10699 | nla_put_failure: |
| 10700 | genlmsg_cancel(msg, hdr); |
| 10701 | nlmsg_free(msg); |
| 10702 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10703 | EXPORT_SYMBOL(cfg80211_del_sta); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 10704 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10705 | void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr, |
| 10706 | enum nl80211_connect_failed_reason reason, |
| 10707 | gfp_t gfp) |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 10708 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10709 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
| 10710 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 10711 | struct sk_buff *msg; |
| 10712 | void *hdr; |
| 10713 | |
| 10714 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 10715 | if (!msg) |
| 10716 | return; |
| 10717 | |
| 10718 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED); |
| 10719 | if (!hdr) { |
| 10720 | nlmsg_free(msg); |
| 10721 | return; |
| 10722 | } |
| 10723 | |
| 10724 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 10725 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 10726 | nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason)) |
| 10727 | goto nla_put_failure; |
| 10728 | |
| 10729 | genlmsg_end(msg, hdr); |
| 10730 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10731 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10732 | NL80211_MCGRP_MLME, gfp); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 10733 | return; |
| 10734 | |
| 10735 | nla_put_failure: |
| 10736 | genlmsg_cancel(msg, hdr); |
| 10737 | nlmsg_free(msg); |
| 10738 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10739 | EXPORT_SYMBOL(cfg80211_conn_failed); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 10740 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 10741 | static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, |
| 10742 | const u8 *addr, gfp_t gfp) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10743 | { |
| 10744 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10745 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 10746 | struct sk_buff *msg; |
| 10747 | void *hdr; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10748 | u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10749 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10750 | if (!nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10751 | return false; |
| 10752 | |
| 10753 | msg = nlmsg_new(100, gfp); |
| 10754 | if (!msg) |
| 10755 | return true; |
| 10756 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 10757 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10758 | if (!hdr) { |
| 10759 | nlmsg_free(msg); |
| 10760 | return true; |
| 10761 | } |
| 10762 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10763 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10764 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 10765 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 10766 | goto nla_put_failure; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10767 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 10768 | genlmsg_end(msg, hdr); |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10769 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10770 | return true; |
| 10771 | |
| 10772 | nla_put_failure: |
| 10773 | genlmsg_cancel(msg, hdr); |
| 10774 | nlmsg_free(msg); |
| 10775 | return true; |
| 10776 | } |
| 10777 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10778 | bool cfg80211_rx_spurious_frame(struct net_device *dev, |
| 10779 | const u8 *addr, gfp_t gfp) |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 10780 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10781 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10782 | bool ret; |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 10783 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10784 | trace_cfg80211_rx_spurious_frame(dev, addr); |
| 10785 | |
| 10786 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 10787 | wdev->iftype != NL80211_IFTYPE_P2P_GO)) { |
| 10788 | trace_cfg80211_return_bool(false); |
| 10789 | return false; |
| 10790 | } |
| 10791 | ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, |
| 10792 | addr, gfp); |
| 10793 | trace_cfg80211_return_bool(ret); |
| 10794 | return ret; |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 10795 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10796 | EXPORT_SYMBOL(cfg80211_rx_spurious_frame); |
| 10797 | |
| 10798 | bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev, |
| 10799 | const u8 *addr, gfp_t gfp) |
| 10800 | { |
| 10801 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10802 | bool ret; |
| 10803 | |
| 10804 | trace_cfg80211_rx_unexpected_4addr_frame(dev, addr); |
| 10805 | |
| 10806 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 10807 | wdev->iftype != NL80211_IFTYPE_P2P_GO && |
| 10808 | wdev->iftype != NL80211_IFTYPE_AP_VLAN)) { |
| 10809 | trace_cfg80211_return_bool(false); |
| 10810 | return false; |
| 10811 | } |
| 10812 | ret = __nl80211_unexpected_frame(dev, |
| 10813 | NL80211_CMD_UNEXPECTED_4ADDR_FRAME, |
| 10814 | addr, gfp); |
| 10815 | trace_cfg80211_return_bool(ret); |
| 10816 | return ret; |
| 10817 | } |
| 10818 | EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame); |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 10819 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 10820 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10821 | struct wireless_dev *wdev, u32 nlportid, |
Johannes Berg | 804483e | 2012-03-05 22:18:41 +0100 | [diff] [blame] | 10822 | int freq, int sig_dbm, |
Vladimir Kondratiev | 19504cf | 2013-08-15 14:51:28 +0300 | [diff] [blame] | 10823 | const u8 *buf, size_t len, u32 flags, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10824 | { |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10825 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10826 | struct sk_buff *msg; |
| 10827 | void *hdr; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10828 | |
| 10829 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 10830 | if (!msg) |
| 10831 | return -ENOMEM; |
| 10832 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 10833 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10834 | if (!hdr) { |
| 10835 | nlmsg_free(msg); |
| 10836 | return -ENOMEM; |
| 10837 | } |
| 10838 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10839 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10840 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 10841 | netdev->ifindex)) || |
Ilan Peer | a838490 | 2013-05-08 16:35:55 +0300 | [diff] [blame] | 10842 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10843 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
| 10844 | (sig_dbm && |
| 10845 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
Vladimir Kondratiev | 19504cf | 2013-08-15 14:51:28 +0300 | [diff] [blame] | 10846 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
| 10847 | (flags && |
| 10848 | nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10849 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10850 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10851 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10852 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10853 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10854 | |
| 10855 | nla_put_failure: |
| 10856 | genlmsg_cancel(msg, hdr); |
| 10857 | nlmsg_free(msg); |
| 10858 | return -ENOBUFS; |
| 10859 | } |
| 10860 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10861 | void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie, |
| 10862 | const u8 *buf, size_t len, bool ack, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10863 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10864 | struct wiphy *wiphy = wdev->wiphy; |
| 10865 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10866 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10867 | struct sk_buff *msg; |
| 10868 | void *hdr; |
| 10869 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10870 | trace_cfg80211_mgmt_tx_status(wdev, cookie, ack); |
| 10871 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10872 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 10873 | if (!msg) |
| 10874 | return; |
| 10875 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 10876 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10877 | if (!hdr) { |
| 10878 | nlmsg_free(msg); |
| 10879 | return; |
| 10880 | } |
| 10881 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10882 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10883 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 10884 | netdev->ifindex)) || |
Ilan Peer | a838490 | 2013-05-08 16:35:55 +0300 | [diff] [blame] | 10885 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10886 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
| 10887 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || |
| 10888 | (ack && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 10889 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10890 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10891 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10892 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10893 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10894 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10895 | return; |
| 10896 | |
| 10897 | nla_put_failure: |
| 10898 | genlmsg_cancel(msg, hdr); |
| 10899 | nlmsg_free(msg); |
| 10900 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10901 | EXPORT_SYMBOL(cfg80211_mgmt_tx_status); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10902 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10903 | void cfg80211_cqm_rssi_notify(struct net_device *dev, |
| 10904 | enum nl80211_cqm_rssi_threshold_event rssi_event, |
| 10905 | gfp_t gfp) |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10906 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10907 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10908 | struct wiphy *wiphy = wdev->wiphy; |
| 10909 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10910 | struct sk_buff *msg; |
| 10911 | struct nlattr *pinfoattr; |
| 10912 | void *hdr; |
| 10913 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10914 | trace_cfg80211_cqm_rssi_notify(dev, rssi_event); |
| 10915 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10916 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10917 | if (!msg) |
| 10918 | return; |
| 10919 | |
| 10920 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 10921 | if (!hdr) { |
| 10922 | nlmsg_free(msg); |
| 10923 | return; |
| 10924 | } |
| 10925 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10926 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10927 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10928 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10929 | |
| 10930 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 10931 | if (!pinfoattr) |
| 10932 | goto nla_put_failure; |
| 10933 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10934 | if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, |
| 10935 | rssi_event)) |
| 10936 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10937 | |
| 10938 | nla_nest_end(msg, pinfoattr); |
| 10939 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10940 | genlmsg_end(msg, hdr); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10941 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10942 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10943 | NL80211_MCGRP_MLME, gfp); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10944 | return; |
| 10945 | |
| 10946 | nla_put_failure: |
| 10947 | genlmsg_cancel(msg, hdr); |
| 10948 | nlmsg_free(msg); |
| 10949 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10950 | EXPORT_SYMBOL(cfg80211_cqm_rssi_notify); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10951 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10952 | static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
| 10953 | struct net_device *netdev, const u8 *bssid, |
| 10954 | const u8 *replay_ctr, gfp_t gfp) |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10955 | { |
| 10956 | struct sk_buff *msg; |
| 10957 | struct nlattr *rekey_attr; |
| 10958 | void *hdr; |
| 10959 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10960 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10961 | if (!msg) |
| 10962 | return; |
| 10963 | |
| 10964 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); |
| 10965 | if (!hdr) { |
| 10966 | nlmsg_free(msg); |
| 10967 | return; |
| 10968 | } |
| 10969 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10970 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10971 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10972 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 10973 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10974 | |
| 10975 | rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); |
| 10976 | if (!rekey_attr) |
| 10977 | goto nla_put_failure; |
| 10978 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10979 | if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
| 10980 | NL80211_REPLAY_CTR_LEN, replay_ctr)) |
| 10981 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10982 | |
| 10983 | nla_nest_end(msg, rekey_attr); |
| 10984 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10985 | genlmsg_end(msg, hdr); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10986 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10987 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10988 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10989 | return; |
| 10990 | |
| 10991 | nla_put_failure: |
| 10992 | genlmsg_cancel(msg, hdr); |
| 10993 | nlmsg_free(msg); |
| 10994 | } |
| 10995 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10996 | void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid, |
| 10997 | const u8 *replay_ctr, gfp_t gfp) |
| 10998 | { |
| 10999 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11000 | struct wiphy *wiphy = wdev->wiphy; |
| 11001 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 11002 | |
| 11003 | trace_cfg80211_gtk_rekey_notify(dev, bssid); |
| 11004 | nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp); |
| 11005 | } |
| 11006 | EXPORT_SYMBOL(cfg80211_gtk_rekey_notify); |
| 11007 | |
| 11008 | static void |
| 11009 | nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, |
| 11010 | struct net_device *netdev, int index, |
| 11011 | const u8 *bssid, bool preauth, gfp_t gfp) |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 11012 | { |
| 11013 | struct sk_buff *msg; |
| 11014 | struct nlattr *attr; |
| 11015 | void *hdr; |
| 11016 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11017 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 11018 | if (!msg) |
| 11019 | return; |
| 11020 | |
| 11021 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); |
| 11022 | if (!hdr) { |
| 11023 | nlmsg_free(msg); |
| 11024 | return; |
| 11025 | } |
| 11026 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11027 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11028 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 11029 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 11030 | |
| 11031 | attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE); |
| 11032 | if (!attr) |
| 11033 | goto nla_put_failure; |
| 11034 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11035 | if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) || |
| 11036 | nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) || |
| 11037 | (preauth && |
| 11038 | nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH))) |
| 11039 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 11040 | |
| 11041 | nla_nest_end(msg, attr); |
| 11042 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11043 | genlmsg_end(msg, hdr); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 11044 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11045 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11046 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 11047 | return; |
| 11048 | |
| 11049 | nla_put_failure: |
| 11050 | genlmsg_cancel(msg, hdr); |
| 11051 | nlmsg_free(msg); |
| 11052 | } |
| 11053 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11054 | void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index, |
| 11055 | const u8 *bssid, bool preauth, gfp_t gfp) |
| 11056 | { |
| 11057 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11058 | struct wiphy *wiphy = wdev->wiphy; |
| 11059 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 11060 | |
| 11061 | trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth); |
| 11062 | nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp); |
| 11063 | } |
| 11064 | EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify); |
| 11065 | |
| 11066 | static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev, |
| 11067 | struct net_device *netdev, |
| 11068 | struct cfg80211_chan_def *chandef, |
| 11069 | gfp_t gfp) |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 11070 | { |
| 11071 | struct sk_buff *msg; |
| 11072 | void *hdr; |
| 11073 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11074 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 11075 | if (!msg) |
| 11076 | return; |
| 11077 | |
| 11078 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY); |
| 11079 | if (!hdr) { |
| 11080 | nlmsg_free(msg); |
| 11081 | return; |
| 11082 | } |
| 11083 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 11084 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 11085 | goto nla_put_failure; |
| 11086 | |
| 11087 | if (nl80211_send_chandef(msg, chandef)) |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 11088 | goto nla_put_failure; |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 11089 | |
| 11090 | genlmsg_end(msg, hdr); |
| 11091 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11092 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11093 | NL80211_MCGRP_MLME, gfp); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 11094 | return; |
| 11095 | |
| 11096 | nla_put_failure: |
| 11097 | genlmsg_cancel(msg, hdr); |
| 11098 | nlmsg_free(msg); |
| 11099 | } |
| 11100 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11101 | void cfg80211_ch_switch_notify(struct net_device *dev, |
| 11102 | struct cfg80211_chan_def *chandef) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 11103 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11104 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11105 | struct wiphy *wiphy = wdev->wiphy; |
| 11106 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 11107 | |
Simon Wunderlich | e487eae | 2013-11-21 18:19:51 +0100 | [diff] [blame] | 11108 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11109 | |
Simon Wunderlich | e487eae | 2013-11-21 18:19:51 +0100 | [diff] [blame] | 11110 | trace_cfg80211_ch_switch_notify(dev, chandef); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11111 | |
| 11112 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 11113 | wdev->iftype != NL80211_IFTYPE_P2P_GO && |
Chun-Yeow Yeoh | b8456a1 | 2013-10-17 15:55:02 -0700 | [diff] [blame] | 11114 | wdev->iftype != NL80211_IFTYPE_ADHOC && |
| 11115 | wdev->iftype != NL80211_IFTYPE_MESH_POINT)) |
Simon Wunderlich | e487eae | 2013-11-21 18:19:51 +0100 | [diff] [blame] | 11116 | return; |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11117 | |
| 11118 | wdev->channel = chandef->chan; |
| 11119 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11120 | } |
| 11121 | EXPORT_SYMBOL(cfg80211_ch_switch_notify); |
| 11122 | |
| 11123 | void cfg80211_cqm_txe_notify(struct net_device *dev, |
| 11124 | const u8 *peer, u32 num_packets, |
| 11125 | u32 rate, u32 intvl, gfp_t gfp) |
| 11126 | { |
| 11127 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11128 | struct wiphy *wiphy = wdev->wiphy; |
| 11129 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 11130 | struct sk_buff *msg; |
| 11131 | struct nlattr *pinfoattr; |
| 11132 | void *hdr; |
| 11133 | |
| 11134 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 11135 | if (!msg) |
| 11136 | return; |
| 11137 | |
| 11138 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 11139 | if (!hdr) { |
| 11140 | nlmsg_free(msg); |
| 11141 | return; |
| 11142 | } |
| 11143 | |
| 11144 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11145 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 11146 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
| 11147 | goto nla_put_failure; |
| 11148 | |
| 11149 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 11150 | if (!pinfoattr) |
| 11151 | goto nla_put_failure; |
| 11152 | |
| 11153 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets)) |
| 11154 | goto nla_put_failure; |
| 11155 | |
| 11156 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate)) |
| 11157 | goto nla_put_failure; |
| 11158 | |
| 11159 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl)) |
| 11160 | goto nla_put_failure; |
| 11161 | |
| 11162 | nla_nest_end(msg, pinfoattr); |
| 11163 | |
| 11164 | genlmsg_end(msg, hdr); |
| 11165 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11166 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11167 | NL80211_MCGRP_MLME, gfp); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 11168 | return; |
| 11169 | |
| 11170 | nla_put_failure: |
| 11171 | genlmsg_cancel(msg, hdr); |
| 11172 | nlmsg_free(msg); |
| 11173 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11174 | EXPORT_SYMBOL(cfg80211_cqm_txe_notify); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 11175 | |
| 11176 | void |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 11177 | nl80211_radar_notify(struct cfg80211_registered_device *rdev, |
Janusz Dziedzic | d2859df | 2013-11-06 13:55:51 +0100 | [diff] [blame] | 11178 | const struct cfg80211_chan_def *chandef, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 11179 | enum nl80211_radar_event event, |
| 11180 | struct net_device *netdev, gfp_t gfp) |
| 11181 | { |
| 11182 | struct sk_buff *msg; |
| 11183 | void *hdr; |
| 11184 | |
| 11185 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 11186 | if (!msg) |
| 11187 | return; |
| 11188 | |
| 11189 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT); |
| 11190 | if (!hdr) { |
| 11191 | nlmsg_free(msg); |
| 11192 | return; |
| 11193 | } |
| 11194 | |
| 11195 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 11196 | goto nla_put_failure; |
| 11197 | |
| 11198 | /* NOP and radar events don't need a netdev parameter */ |
| 11199 | if (netdev) { |
| 11200 | struct wireless_dev *wdev = netdev->ieee80211_ptr; |
| 11201 | |
| 11202 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 11203 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 11204 | goto nla_put_failure; |
| 11205 | } |
| 11206 | |
| 11207 | if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event)) |
| 11208 | goto nla_put_failure; |
| 11209 | |
| 11210 | if (nl80211_send_chandef(msg, chandef)) |
| 11211 | goto nla_put_failure; |
| 11212 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 11213 | genlmsg_end(msg, hdr); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 11214 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11215 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11216 | NL80211_MCGRP_MLME, gfp); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 11217 | return; |
| 11218 | |
| 11219 | nla_put_failure: |
| 11220 | genlmsg_cancel(msg, hdr); |
| 11221 | nlmsg_free(msg); |
| 11222 | } |
| 11223 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11224 | void cfg80211_cqm_pktloss_notify(struct net_device *dev, |
| 11225 | const u8 *peer, u32 num_packets, gfp_t gfp) |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 11226 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11227 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11228 | struct wiphy *wiphy = wdev->wiphy; |
| 11229 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 11230 | struct sk_buff *msg; |
| 11231 | struct nlattr *pinfoattr; |
| 11232 | void *hdr; |
| 11233 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11234 | trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets); |
| 11235 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11236 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 11237 | if (!msg) |
| 11238 | return; |
| 11239 | |
| 11240 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 11241 | if (!hdr) { |
| 11242 | nlmsg_free(msg); |
| 11243 | return; |
| 11244 | } |
| 11245 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11246 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11247 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11248 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
| 11249 | goto nla_put_failure; |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 11250 | |
| 11251 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 11252 | if (!pinfoattr) |
| 11253 | goto nla_put_failure; |
| 11254 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11255 | if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets)) |
| 11256 | goto nla_put_failure; |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 11257 | |
| 11258 | nla_nest_end(msg, pinfoattr); |
| 11259 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11260 | genlmsg_end(msg, hdr); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 11261 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11262 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11263 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 11264 | return; |
| 11265 | |
| 11266 | nla_put_failure: |
| 11267 | genlmsg_cancel(msg, hdr); |
| 11268 | nlmsg_free(msg); |
| 11269 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11270 | EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 11271 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11272 | void cfg80211_probe_status(struct net_device *dev, const u8 *addr, |
| 11273 | u64 cookie, bool acked, gfp_t gfp) |
| 11274 | { |
| 11275 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11276 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 11277 | struct sk_buff *msg; |
| 11278 | void *hdr; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11279 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 11280 | trace_cfg80211_probe_status(dev, addr, cookie, acked); |
| 11281 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11282 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 11283 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11284 | if (!msg) |
| 11285 | return; |
| 11286 | |
| 11287 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); |
| 11288 | if (!hdr) { |
| 11289 | nlmsg_free(msg); |
| 11290 | return; |
| 11291 | } |
| 11292 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11293 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11294 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 11295 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 11296 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || |
| 11297 | (acked && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 11298 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11299 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 11300 | genlmsg_end(msg, hdr); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11301 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11302 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11303 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11304 | return; |
| 11305 | |
| 11306 | nla_put_failure: |
| 11307 | genlmsg_cancel(msg, hdr); |
| 11308 | nlmsg_free(msg); |
| 11309 | } |
| 11310 | EXPORT_SYMBOL(cfg80211_probe_status); |
| 11311 | |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11312 | void cfg80211_report_obss_beacon(struct wiphy *wiphy, |
| 11313 | const u8 *frame, size_t len, |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11314 | int freq, int sig_dbm) |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11315 | { |
| 11316 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 11317 | struct sk_buff *msg; |
| 11318 | void *hdr; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11319 | struct cfg80211_beacon_registration *reg; |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11320 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 11321 | trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm); |
| 11322 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11323 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 11324 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 11325 | msg = nlmsg_new(len + 100, GFP_ATOMIC); |
| 11326 | if (!msg) { |
| 11327 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 11328 | return; |
| 11329 | } |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11330 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11331 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
| 11332 | if (!hdr) |
| 11333 | goto nla_put_failure; |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11334 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11335 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11336 | (freq && |
| 11337 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || |
| 11338 | (sig_dbm && |
| 11339 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
| 11340 | nla_put(msg, NL80211_ATTR_FRAME, len, frame)) |
| 11341 | goto nla_put_failure; |
| 11342 | |
| 11343 | genlmsg_end(msg, hdr); |
| 11344 | |
| 11345 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid); |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11346 | } |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11347 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11348 | return; |
| 11349 | |
| 11350 | nla_put_failure: |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11351 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 11352 | if (hdr) |
| 11353 | genlmsg_cancel(msg, hdr); |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11354 | nlmsg_free(msg); |
| 11355 | } |
| 11356 | EXPORT_SYMBOL(cfg80211_report_obss_beacon); |
| 11357 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 11358 | #ifdef CONFIG_PM |
| 11359 | void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev, |
| 11360 | struct cfg80211_wowlan_wakeup *wakeup, |
| 11361 | gfp_t gfp) |
| 11362 | { |
| 11363 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 11364 | struct sk_buff *msg; |
| 11365 | void *hdr; |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 11366 | int size = 200; |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 11367 | |
| 11368 | trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup); |
| 11369 | |
| 11370 | if (wakeup) |
| 11371 | size += wakeup->packet_present_len; |
| 11372 | |
| 11373 | msg = nlmsg_new(size, gfp); |
| 11374 | if (!msg) |
| 11375 | return; |
| 11376 | |
| 11377 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN); |
| 11378 | if (!hdr) |
| 11379 | goto free_msg; |
| 11380 | |
| 11381 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11382 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 11383 | goto free_msg; |
| 11384 | |
| 11385 | if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 11386 | wdev->netdev->ifindex)) |
| 11387 | goto free_msg; |
| 11388 | |
| 11389 | if (wakeup) { |
| 11390 | struct nlattr *reasons; |
| 11391 | |
| 11392 | reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
Johannes Berg | 7fa322c | 2013-10-25 11:16:58 +0200 | [diff] [blame] | 11393 | if (!reasons) |
| 11394 | goto free_msg; |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 11395 | |
| 11396 | if (wakeup->disconnect && |
| 11397 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) |
| 11398 | goto free_msg; |
| 11399 | if (wakeup->magic_pkt && |
| 11400 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) |
| 11401 | goto free_msg; |
| 11402 | if (wakeup->gtk_rekey_failure && |
| 11403 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) |
| 11404 | goto free_msg; |
| 11405 | if (wakeup->eap_identity_req && |
| 11406 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) |
| 11407 | goto free_msg; |
| 11408 | if (wakeup->four_way_handshake && |
| 11409 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) |
| 11410 | goto free_msg; |
| 11411 | if (wakeup->rfkill_release && |
| 11412 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)) |
| 11413 | goto free_msg; |
| 11414 | |
| 11415 | if (wakeup->pattern_idx >= 0 && |
| 11416 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 11417 | wakeup->pattern_idx)) |
| 11418 | goto free_msg; |
| 11419 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 11420 | if (wakeup->tcp_match && |
| 11421 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH)) |
| 11422 | goto free_msg; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11423 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 11424 | if (wakeup->tcp_connlost && |
| 11425 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST)) |
| 11426 | goto free_msg; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11427 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 11428 | if (wakeup->tcp_nomoretokens && |
| 11429 | nla_put_flag(msg, |
| 11430 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS)) |
| 11431 | goto free_msg; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11432 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 11433 | if (wakeup->packet) { |
| 11434 | u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211; |
| 11435 | u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN; |
| 11436 | |
| 11437 | if (!wakeup->packet_80211) { |
| 11438 | pkt_attr = |
| 11439 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023; |
| 11440 | len_attr = |
| 11441 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN; |
| 11442 | } |
| 11443 | |
| 11444 | if (wakeup->packet_len && |
| 11445 | nla_put_u32(msg, len_attr, wakeup->packet_len)) |
| 11446 | goto free_msg; |
| 11447 | |
| 11448 | if (nla_put(msg, pkt_attr, wakeup->packet_present_len, |
| 11449 | wakeup->packet)) |
| 11450 | goto free_msg; |
| 11451 | } |
| 11452 | |
| 11453 | nla_nest_end(msg, reasons); |
| 11454 | } |
| 11455 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 11456 | genlmsg_end(msg, hdr); |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 11457 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11458 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11459 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 11460 | return; |
| 11461 | |
| 11462 | free_msg: |
| 11463 | nlmsg_free(msg); |
| 11464 | } |
| 11465 | EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup); |
| 11466 | #endif |
| 11467 | |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 11468 | void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer, |
| 11469 | enum nl80211_tdls_operation oper, |
| 11470 | u16 reason_code, gfp_t gfp) |
| 11471 | { |
| 11472 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11473 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 11474 | struct sk_buff *msg; |
| 11475 | void *hdr; |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 11476 | |
| 11477 | trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper, |
| 11478 | reason_code); |
| 11479 | |
| 11480 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 11481 | if (!msg) |
| 11482 | return; |
| 11483 | |
| 11484 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER); |
| 11485 | if (!hdr) { |
| 11486 | nlmsg_free(msg); |
| 11487 | return; |
| 11488 | } |
| 11489 | |
| 11490 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11491 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 11492 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) || |
| 11493 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) || |
| 11494 | (reason_code > 0 && |
| 11495 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) |
| 11496 | goto nla_put_failure; |
| 11497 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 11498 | genlmsg_end(msg, hdr); |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 11499 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11500 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11501 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 11502 | return; |
| 11503 | |
| 11504 | nla_put_failure: |
| 11505 | genlmsg_cancel(msg, hdr); |
| 11506 | nlmsg_free(msg); |
| 11507 | } |
| 11508 | EXPORT_SYMBOL(cfg80211_tdls_oper_request); |
| 11509 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11510 | static int nl80211_netlink_notify(struct notifier_block * nb, |
| 11511 | unsigned long state, |
| 11512 | void *_notify) |
| 11513 | { |
| 11514 | struct netlink_notify *notify = _notify; |
| 11515 | struct cfg80211_registered_device *rdev; |
| 11516 | struct wireless_dev *wdev; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11517 | struct cfg80211_beacon_registration *reg, *tmp; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11518 | |
| 11519 | if (state != NETLINK_URELEASE) |
| 11520 | return NOTIFY_DONE; |
| 11521 | |
| 11522 | rcu_read_lock(); |
| 11523 | |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11524 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 11525 | list_for_each_entry_rcu(wdev, &rdev->wdev_list, list) |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11526 | cfg80211_mlme_unregister_socket(wdev, notify->portid); |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11527 | |
| 11528 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 11529 | list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations, |
| 11530 | list) { |
| 11531 | if (reg->nlportid == notify->portid) { |
| 11532 | list_del(®->list); |
| 11533 | kfree(reg); |
| 11534 | break; |
| 11535 | } |
| 11536 | } |
| 11537 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11538 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11539 | |
| 11540 | rcu_read_unlock(); |
| 11541 | |
| 11542 | return NOTIFY_DONE; |
| 11543 | } |
| 11544 | |
| 11545 | static struct notifier_block nl80211_netlink_notifier = { |
| 11546 | .notifier_call = nl80211_netlink_notify, |
| 11547 | }; |
| 11548 | |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 11549 | void cfg80211_ft_event(struct net_device *netdev, |
| 11550 | struct cfg80211_ft_event_params *ft_event) |
| 11551 | { |
| 11552 | struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy; |
| 11553 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 11554 | struct sk_buff *msg; |
| 11555 | void *hdr; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 11556 | |
| 11557 | trace_cfg80211_ft_event(wiphy, netdev, ft_event); |
| 11558 | |
| 11559 | if (!ft_event->target_ap) |
| 11560 | return; |
| 11561 | |
| 11562 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 11563 | if (!msg) |
| 11564 | return; |
| 11565 | |
| 11566 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT); |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 11567 | if (!hdr) |
| 11568 | goto out; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 11569 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 11570 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11571 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 11572 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap)) |
| 11573 | goto out; |
| 11574 | |
| 11575 | if (ft_event->ies && |
| 11576 | nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies)) |
| 11577 | goto out; |
| 11578 | if (ft_event->ric_ies && |
| 11579 | nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len, |
| 11580 | ft_event->ric_ies)) |
| 11581 | goto out; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 11582 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 11583 | genlmsg_end(msg, hdr); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 11584 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11585 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11586 | NL80211_MCGRP_MLME, GFP_KERNEL); |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 11587 | return; |
| 11588 | out: |
| 11589 | nlmsg_free(msg); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 11590 | } |
| 11591 | EXPORT_SYMBOL(cfg80211_ft_event); |
| 11592 | |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 11593 | void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp) |
| 11594 | { |
| 11595 | struct cfg80211_registered_device *rdev; |
| 11596 | struct sk_buff *msg; |
| 11597 | void *hdr; |
| 11598 | u32 nlportid; |
| 11599 | |
| 11600 | rdev = wiphy_to_dev(wdev->wiphy); |
| 11601 | if (!rdev->crit_proto_nlportid) |
| 11602 | return; |
| 11603 | |
| 11604 | nlportid = rdev->crit_proto_nlportid; |
| 11605 | rdev->crit_proto_nlportid = 0; |
| 11606 | |
| 11607 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 11608 | if (!msg) |
| 11609 | return; |
| 11610 | |
| 11611 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP); |
| 11612 | if (!hdr) |
| 11613 | goto nla_put_failure; |
| 11614 | |
| 11615 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11616 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 11617 | goto nla_put_failure; |
| 11618 | |
| 11619 | genlmsg_end(msg, hdr); |
| 11620 | |
| 11621 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
| 11622 | return; |
| 11623 | |
| 11624 | nla_put_failure: |
| 11625 | if (hdr) |
| 11626 | genlmsg_cancel(msg, hdr); |
| 11627 | nlmsg_free(msg); |
| 11628 | |
| 11629 | } |
| 11630 | EXPORT_SYMBOL(cfg80211_crit_proto_stopped); |
| 11631 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11632 | /* initialisation/exit functions */ |
| 11633 | |
| 11634 | int nl80211_init(void) |
| 11635 | { |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 11636 | int err; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11637 | |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11638 | err = genl_register_family_with_ops_groups(&nl80211_fam, nl80211_ops, |
| 11639 | nl80211_mcgrps); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11640 | if (err) |
| 11641 | return err; |
| 11642 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11643 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
| 11644 | if (err) |
| 11645 | goto err_out; |
| 11646 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11647 | return 0; |
| 11648 | err_out: |
| 11649 | genl_unregister_family(&nl80211_fam); |
| 11650 | return err; |
| 11651 | } |
| 11652 | |
| 11653 | void nl80211_exit(void) |
| 11654 | { |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11655 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11656 | genl_unregister_family(&nl80211_fam); |
| 11657 | } |